88APP_NAME=$( basename $0 )
99_PARENT=" $( dirname $BASH_SOURCE ) /.."
1010ROOTDIR=$( perl -e " use Cwd 'abs_path'; print abs_path('$_PARENT ')" )
11- MAKE_OPTIONS=" NMODL_BINARY OUTPUT INCFLAGS LINKFLAGS MODS_PATH VERBOSE"
11+ MAKE_OPTIONS=" MECH_NAME NMODL_BINARY DESTDIR INCFLAGS LINKFLAGS MODS_PATH VERBOSE"
1212PARALLELISM=4
13+ SAVE_FILE=" @CMAKE_HOST_SYSTEM_PROCESSOR@/nrnivmodl_options.txt"
1314
14- while getopts " n:v:o :i:l:p:hV" OPT; do
15+ while getopts " n:m:v:d :i:l:p:hV" OPT; do
1516 case " $OPT " in
1617 n)
18+ params_MECH_NAME=" $OPTARG " ;;
19+ m)
1720 params_NMODL_BINARY=" $OPTARG " ;;
18- o )
19- params_OUTPUT =" $OPTARG " ;;
21+ d )
22+ params_DESTDIR =" $OPTARG " ;;
2023 i)
2124 params_INCFLAGS=" $OPTARG " ;;
2225 l)
@@ -28,10 +31,12 @@ while getopts "n:v:o:i:l:p:hV" OPT; do
2831 h)
2932 echo " $APP_NAME [options, ...] [mods_path]"
3033 echo " Options:"
31- echo " -n <binary > NMODL code generation compiler path "
32- echo " -o <output_dir> Set the output dir (default: <arch>-core) "
34+ echo " -n <name > The model name, used as a suffix in the shared library "
35+ echo " -m <mod2c_bin> NMODL code generation compiler path "
3336 echo " -i <incl_flags> Definitions passed to the compiler, typically '-I dir..'"
3437 echo " -l <link_flags> Definitions passed to the linker, typically '-Lx -lylib..'"
38+ echo " -d <dest_dir> Install to dest_dir. Default: off - Only build in {ARCH}" \
39+ " Consider using this option on a second call. Params are preserved."
3540 echo " -V Verbose: show commands executed by make"
3641 echo " -p <n_procs> Make parallelism. Default: 4"
3742 exit 0;;
@@ -47,33 +52,39 @@ if [ $# -gt 1 ]; then
4752 exit 1
4853fi
4954
55+ # To support build + install later we save/restore options
56+ # Attempt to load previous definitions
57+ if [ -f " $SAVE_FILE " ]; then
58+ while read line; do
59+ echo " $line "
60+ eval " $line "
61+ done < " $SAVE_FILE "
62+ fi
63+
5064# If defined mods dir be in $1
5165# Note: due to bug #712 makefile wont handle mod dir with spaces, so we let it fail here
5266params_MODS_PATH=$1
5367
68+ mkdir -p " $( dirname " $SAVE_FILE " ) "
69+ echo " # nrnivmodl-core options. Mods location: $params_MODS_PATH " > $SAVE_FILE
70+
5471make_params=(" ROOT=${ROOTDIR} " )
5572
5673for param in $MAKE_OPTIONS ; do
5774 var=" params_${param} "
58- [ " ${! var+x} " ] && make_params+=(" $param =${! var} " )
59- done
75+ if [ " ${! var+x} " ]; then
76+ make_params+=(" $param =${! var} " )
77+ echo " $var =\" ${! var} \" "
78+ fi
79+ done >> " $SAVE_FILE "
80+
81+ # If -I (install) provided, call "make install"
82+ if [ " $params_DESTDIR " ]; then
83+ make_params+=(" install" )
84+ fi
6085
6186# warn if no mod files provided
62- ls " ${params_MODS_PATH:- .} " /* .mod || echo " Warning : No mods found!"
87+ ls " ${params_MODS_PATH:- .} " /* .mod || echo " WARNING : No mods found!"
6388make -j$PARALLELISM -f " ${ROOTDIR} /share/coreneuron/nrnivmodl_core_makefile" " ${make_params[@]} "
6489
65- # Create a little script to call make install (relinks w right RPATH)
66- # This should allow splitting the build of special-core into two phases:
67- # 1. build the binary from the libcoreneuron.so library and the compiled models
68- # 2. install into the final destination directory and relinking as necessary
69- # TODO: instead of outputting a script we could output an options file which would be read by
70- # this script when installing to ensure the same arguments are being used.
71- echo " #!/bin/bash
72- set -e
73- [ \$ # -eq 1 ] || { echo 'Required install destination. Syntax: ' \$ (basename \$ 0) '<directory>'; false; }
74- set -x
75- make -f '${ROOTDIR} /share/coreneuron/nrnivmodl_core_makefile' " $( printf " '%s' " " ${make_params[@]} " ) " DESTDIR=\$ 1 install
76- " > nrnivmech_install.sh
77- chmod 755 nrnivmech_install.sh
78-
79- echo " mods built successfully. Install script written to nrnivmech_install.sh"
90+ echo " mods built successfully."
0 commit comments