Skip to content

Commit

Permalink
added configure script
Browse files Browse the repository at this point in the history
  • Loading branch information
James Osborn committed Mar 7, 2017
1 parent 22523d8 commit 361a755
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 James C. Osborn
Copyright (c) 2017 James C. Osborn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
95 changes: 95 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
NIM = @@NIM
QEXDIR = @@QEXDIR
QMPDIR = @@QMPDIR
QIODIR = @@QIODIR
CC = @@CC
LD = @@LD
CC_TYPE = @@CC_TYPE
CFLAGS_ALWAYS = @@CFLAGS_ALWAYS
CFLAGS_DEBUG = @@CFLAGS_DEBUG
CFLAGS_SPEED = @@CFLAGS_SPEED
VERBOSITY = @@VERBOSITY
SIMD = @@SIMD
VLEN = @@VLEN

#### edit above

ifneq ($(origin QEXDIR), undefined)
ENVS += QEXDIR=$(QEXDIR)
endif
ifneq ($(origin QMPDIR), undefined)
ENVS += QMPDIR=$(QMPDIR)
endif
ifneq ($(origin QIODIR), undefined)
ENVS += QIODIR=$(QIODIR)
endif
ifneq ($(origin CC_TYPE), undefined)
ENVS += CC_TYPE=$(CC_TYPE)
endif
ifneq ($(origin CC), undefined)
ENVS += CC=$(CC)
endif
ifneq ($(origin LD), undefined)
ENVS += LD=$(LD)
endif
ifneq ($(origin CFLAGS_ALWAYS), undefined)
ENVS += CFLAGS_ALWAYS="$(CFLAGS_ALWAYS)"
endif
ifneq ($(origin CFLAGS_DEBUG), undefined)
ENVS += CFLAGS_DEBUG="$(CFLAGS_DEBUG)"
endif
ifneq ($(origin CFLAGS_SPEED), undefined)
ENVS += CFLAGS_SPEED="$(CFLAGS_SPEED)"
endif
ifneq ($(origin VERBOSITY), undefined)
ENVS += VERBOSITY=$(VERBOSITY)
endif
ifneq ($(origin SIMD), undefined)
ENVS += SIMD=$(SIMD)
endif
ifneq ($(origin VLEN), undefined)
ENVS += VLEN=$(VLEN)
endif

DBG = "-d:release"
ifeq ($(debug),1)
DBG = "-d:debug"
endif
ifeq ($(run),1)
DBG += "-r"
endif
ifeq ($(c),1)
DBG += "-c"
endif
DBG += "--warning[SmallLshouldNotBeUsed]:off"
DBG += "--hint[XDeclaredButNotUsed]:off"
DBG += "--implicitStatic:on"
#DBG += "--verbosity:2"
#DBG += "--listCmd"
#DBG += "--parallelBuild:4"
#DBG += "--embedsrc"
#DBG += "--genMapping"
#DBG += "--gc:refc"
#DBG += "--gc:markAndSweep"
#refc|v2|markAndSweep|boehm|go|none

TARGETS = $(MAKECMDGOALS)

ifeq ($(TARGETS),clean)
TARGETS = dummy
endif
clean:
\rm -rf nimcache
ifeq ($(TARGETS),all)
T1 = $(wildcard $(QEXDIR)/src/*.nim)
T2 = $(notdir $(T1))
T3 = $(basename $(T2))
T4 = $(filter-out simdQpx,$(T3))
TARGETS = $(T4)
endif
all: $(TARGETS)

$(TARGETS): _force
$(ENVS) $(NIM) c $(DBG) --nimcache:`pwd`/nimcache -o:`pwd`/$(@F) $(QEXDIR)/src/$@

.PHONY: _force
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ constructs which may change.

### Installation:

First you need Nim. I recommend installing it from the instructions
given in "Installation from github" at the bottom of this page:
First you need `Nim<https://nim-lang.org>`_.

You can install it either by using the script "installNim"
in this repo, or from the instructions given here:
http://nim-lang.org/download.html

(optional) Copy "Makefile.template" to a separate build directory.
Create a separate build directory (optional but recommended).

Copy "Makefile.template" to "Makefile" and edit it
to point to the QEX source, set compiler, etc.
(the first section is for BG/Q, the second for x86)
From the build directory run the "configure" script found with the source.
This will create a "Makefile" in the build directory.
Check the resulting Makefile and edit if necessary.

The variables you'll likely need to change are:
The variables you may need to change are:

```
QEXDIR: root directory containing QEX code (where this README.md is)
Expand Down
16 changes: 16 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

dir=`dirname $0`
nim=`$dir/findNim`
if [ "X`$nim`" = "X" ]; then
#echo "Error: can't find Nim compiler 'nim'"
#exit 1
#echo "Installing Nim compiler 'nim'" 1>&2
#dir=`dirname $0`
$dir/installNim
nim=`$dir/findNim`
fi

echo "Using Nim compiler: $nim"

$nim $dir/configure.nims
78 changes: 78 additions & 0 deletions configure.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import osPaths
import strUtils

var params = newSeq[string](0)
template set(key,val: string) =
params.insert val
params.insert key
template `~`(key,val: untyped) =
set(astToStr(key), val)

let nim = paramStr(0)
NIM ~ nim

let script = paramStr(1)
#let qexdir = thisDir()
let (qexdir, _, _) = splitFile(script)
echo "Using QEXDIR ", qexdir
set "QEXDIR", qexdir

let home = getHomeDir()

var qmpdir = home / "lqcd/install/qmp"
echo "Using QMPDIR ", qmpdir
set "QMPDIR", qmpdir

var qiodir = home / "lqcd/install/qio"
echo "Using QIODIR ", qiodir
set "QIODIR", qiodir

var machine = ""
CC ~ "mpicc"
LD ~ "$(CC)"
CC_TYPE ~ "gcc"
CFLAGS_ALWAYS ~ "-Wall -std=gnu99 -march=native -ldl"
CFLAGS_DEBUG ~ "-g3 -O0"
CFLAGS_SPEED ~ "-g -O3"
VERBOSITY ~ "1"
SIMD ~ ""
VLEN ~ "1"

if dirExists "/bgsys":
machine = "Blue Gene/Q"
CC ~ qexdir / "mpixlc2"
CFLAGS_ALWAYS ~ ""
CFLAGS_DEBUG ~ "-g3 -O0"
CFLAGS_SPEED ~ "-O3"
VERBOSITY ~ "3"
SIMD ~ "QPX"

let uname = staticExec "uname"

if machine=="" and uname=="Darwin":
machine = "macOS"
SIMD ~ "SSE,AVX"
VLEN ~ "8"

if machine=="" and fileExists "/proc/cpuinfo":
# assume compute nodes are same as build nodes
machine = "linux"
SIMD ~ "SSE,AVX"
VLEN ~ "8"

# cray/modules
# KNL
# linux (/proc/cpuinfo)
# check on linux/mac/vesta/cooley/theta
# gcc/icc opt level

var f = readFile(qexdir / "Makefile.in")
f = replace(f, "$", "!DOLLAR!")
f = replace(f, "#", "!HASH!")
f = replace(f, "@@", "$")
f = f % params
f = replace(f, "!HASH!", "#")
f = replace(f, "!DOLLAR!", "$")

#echo f
writeFile("Makefile", f)
37 changes: 37 additions & 0 deletions findNim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

whichNim() {
nim=`which nim`
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/bin/nim 2>/dev/null |tail -n1`
fi
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/bin/nim-[0-9]* 2>/dev/null |tail -n1`
fi
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/bin/nim-* 2>/dev/null |tail -n1`
fi
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/nim/Nim/bin/nim 2>/dev/null |tail -n1`
fi
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/nim/Nim-[0-9]*/bin/nim 2>/dev/null |tail -n1`
fi
if [ "X`$nim`" = "X" ]; then
nim=`ls -1 $HOME/nim/Nim-*/bin/nim 2>/dev/null |tail -n1`
fi
echo $nim
}

nim=`whichNim`

#if [ "X`$nim`" = "X" ]; then
#echo "Error: can't find Nim compiler 'nim'"
#exit 1
#echo "Installing Nim compiler 'nim'" 1>&2
#dir=`dirname $0`
#$dir/installNim
#nim=`whichNim`
#fi

echo $nim
Loading

0 comments on commit 361a755

Please sign in to comment.