diff --git a/bin/nrnivmodl.in b/bin/nrnivmodl.in index ee1322da57..07682f3f85 100755 --- a/bin/nrnivmodl.in +++ b/bin/nrnivmodl.in @@ -3,9 +3,9 @@ set -e ARCH=@host_cpu@ MODSUBDIR=@modsubdir@ -USER_PWD="`pwd`" +USER_PWD="$PWD" -if test "x${NRNHOME}" = x ; then +if [ -z "$NRNHOME" ] ; then prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ @@ -17,32 +17,25 @@ else libdir="${prefix}/lib" fi -if [ -z ${CORENRNHOME+x} ]; then +if [ -z ${CORENRNHOME+x} ] ; then # CORENRNHOME wasn't set, use the install prefix cnrn_prefix=@cnrn_prefix@ else cnrn_prefix="${CORENRNHOME}" fi -if test "${NRNHOME_EXEC}" != "" ; then +if [ "${NRNHOME_EXEC}" ] ; then exec_prefix="${NRNHOME_EXEC}" bindir="${exec_prefix}/bin" libdir="${exec_prefix}/lib" fi -# Besides NRNHOME, one may set NRNBIN to override the default location of user binaries -if test "x$NRNBIN" = "x"; then - NRNBIN=$bindir -fi - export prefix export bindir export libdir -MAKEFILEDIR="${bindir}" - if command -v xcrun; then - @NRN_OSX_BUILD_TRUE@export SDKROOT=`xcrun --sdk macosx --show-sdk-path` + @NRN_OSX_BUILD_TRUE@export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) @NRN_OSX_BUILD_TRUE@export MACOSX_DEPLOYMENT_TARGET="@CMAKE_OSX_DEPLOYMENT_TARGET@" if [ -z "${MACOSX_DEPLOYMENT_TARGET}" ]; then unset MACOSX_DEPLOYMENT_TARGET @@ -55,9 +48,8 @@ UserLDFLAGS="" UserCOREFLAGS=() # - options come first but can be in any order. -while test -n "$1" ; do - opt="$1" - case "$opt" in +while [ "$1" ] ; do + case "$1" in -coreneuron) # also run nrnivmodl-core LinkCoreNEURON=true @@ -77,14 +69,14 @@ while test -n "$1" ; do shift shift;; -*) - echo "$opt unrecognized" + echo "$1 unrecognized" exit 1;; *) break;; esac done -pwd +echo "$PWD" # Mod file paths may contain spaces which make variable lists of those # hard to manage as space is the item separator. Furthermore, when a @@ -95,214 +87,140 @@ pwd # of an item, retranslate back to either a space or an escaped space. # Only do this for cmake -hide_spaces() { - echo "$1" | sed 's/ /+++/g' -} -unhide_spaces() { - echo "$1" | sed 's/+++/ /g' -} -escape_spaces() { - echo "$1" | sed 's/+++/\\ /g' -} -remove_spaces() { - echo "$1" | sed 's/ //g' -} - +shopt -s nullglob # files is the complete list of mod files to process -files="" -if test $# -gt 0 ; then +files=() +if [ $# -gt 0 ] ; then for i in "$@" ; do - i_hide=`hide_spaces "$i"` - if test -d "$i" ; then - set +e - for j in $(cd "$i"; unset LC_ALL; ls *.mod) ; do - files="$files $i_hide/$j" - done - set -e + if [ -d "$i" ] ; then + files+=( "$i"/*.mod ) + elif [ -e "$i" ] || [ -e "$i.mod" ] ; then + files+=( "$i" ) else - if test -e "$i" -o -e "$i.mod" ; then - files="$files $i_hide" - else - echo "Arg Error: \"$i\" is not a folder or mod file name or prefix" - - echo "" - echo -n " Mod file, folder args:" - for j in "$@" ; do - echo -n " \"$j\"" - done - echo "" + echo "Arg Error: \"$i\" is not a folder or mod file name or prefix" - exit 1 - fi + echo "" + echo -n " Mod file, folder args:" + for j in "$@" ; do + echo -n " \"$j\"" + done + echo "" + + exit 1 fi done else - if ls *.mod 1> /dev/null 2> /dev/null ; then # only if there are mod files - # Unset LC_ALL for consistent mod order - files=$(unset LC_ALL; ls *.mod) - fi + files=( *.mod ) fi -files=`echo "$files" | sed 's/^ *//'` - -base_names="" -for i in $files ; do - base_names="$base_names `basename $i .mod`" +base_names=() +for i in "${files[@]}" ; do + base_names+=( "$(basename "$i" .mod)" ) done echo -n "Mod files:" -for i in $files ; do - base_name=`basename "$i" .mod` - dir_name=`dirname "$i"` - echo -n " \"`unhide_spaces $dir_name`/$base_name.mod\"" +for i in "${files[@]}" ; do + dir_name=$(dirname "$i") + echo -n " \"$dir_name/${i%.mod}.mod\"" done echo "" echo "" -if [ ! -d $MODSUBDIR ] ; then - echo "Creating $MODSUBDIR directory for .o files." +if [ ! -d "$MODSUBDIR" ] ; then + echo "Creating '$MODSUBDIR' directory for .o files." echo - mkdir $MODSUBDIR + mkdir "$MODSUBDIR" fi -files=`echo "$files" | sed 's/\.mod//g'` - -if test "$files" = '*' ; then - files="" -fi +files=( "${files[@]%.mod}" ) cd $MODSUBDIR -mdir="`pwd`" - - # construct file to be included by makefile to specify mod to c rule when - # executed in $MODSUBDIR (child folder of launch location folder) - MODMAKE=makemod2c_inc - echo "" > $MODMAKE - for i in $files ; do - case "$i" in - /*) f=$i;; # absolute, fine as is - *) f=../$i;; # relative - esac - base_name="`basename $f`" - dir_name="`dirname $f`" - # Note: indentation for shell lines in make rules must be a tab - echo "\ -./$base_name.c: `escape_spaces "$f.mod"` +mdir="$PWD" + +# construct file to be included by makefile to specify mod to c rule when +# executed in $MODSUBDIR (child folder of launch location folder) +MODMAKE=makemod2c_inc +> "$MODMAKE" +for i in "${files[@]}" ; do + case "$i" in + /*) f="$i";; # absolute, fine as is + *) f="../$i";; # relative + esac + base_name="$(basename "$f")" + dir_name="$(dirname "$f")" + # Note: indentation for shell lines in make rules must be a tab + echo "\ +./${base_name// /\\ }.c: ${f// /\\ }.mod @printf \" -> \$(C_GREEN)NMODL\$(C_RESET) \$<\\\n\" - (cd \"`unhide_spaces $dir_name`\"; MODLUNIT=\$(NRNUNITS) \$(NOCMODL) $base_name.mod -o \"$mdir\") + (cd \"$dir_name\"; MODLUNIT=\$(NRNUNITS) \$(NOCMODL) \"$base_name.mod\" -o \"$mdir\") -./$base_name.o: ./$base_name.c - @printf \" -> \$(C_GREEN)Compiling\$(C_RESET) \$<\\\n\" - \$(COMPILE) -I\"`unhide_spaces $dir_name`\" \$(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c \$< -o \$@ -" >> $MODMAKE - done - if test "$nrnivmodl_cfiles" != "" ; then - # I find it very difficult to construct shell variables which are - # space separated lists of items containing spaces. So, for a cmake build, - # the nrnivmodl_cfiles variable is required to be a ';' separated list - # of c files which may contain spaces. - # Save the Internal Field Separator and interpret variables as ';' - # separated list of items (which may contain spaces). Restore after - # processing nrnivmodl_cfiles. - ifs="$IFS" - IFS=';' - for i in $nrnivmodl_cfiles ; do - i_hide=`hide_spaces "$i"` - case "$i_hide" in - /*) f=$i_hide;; # absolute, fine as is - *) f=../$i_hide;; # relative - esac - base_name="`basename $f .c`" - dir_name="`dirname $f`" - echo "\ -./$base_name.o: `escape_spaces "$f"` +./${base_name// /\\ }.o: ./${base_name// /\\ }.c @printf \" -> \$(C_GREEN)Compiling\$(C_RESET) \$<\\\n\" - (cd \"`unhide_spaces $dir_name`\"; \$(COMPILE) \$(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c $base_name.c -o \"$mdir/$base_name.o\") -" >> $MODMAKE - done - IFS="$ifs" - fi + \$(COMPILE) -I\"$dir_name\" \$(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c \$< -o \$@ +" >> "$MODMAKE" +done -COBJS= MODOBJS= -if [ `echo "\n"` ] ; then - newline="\n" -else - newline="\\\\n" -fi -echo '#include +{ + echo '#include #include "hocdec.h" extern int nrnmpi_myid; extern int nrn_nobanner_; #if defined(__cplusplus) extern "C" { #endif -' > mod_func.cpp -for i in $base_names ; do - echo 'extern void _'`remove_spaces "$i"`'_reg(void);' -done >> mod_func.cpp -echo ' -void modl_reg(){ - if (!nrn_nobanner_) if (nrnmpi_myid < 1) { - fprintf(stderr, "Additional mechanisms from files'$newline'"); -' >> mod_func.cpp - -for i in $files -do - echo ' fprintf(stderr," \"'`unhide_spaces "$i"`'.mod\"");' -done >>mod_func.cpp - -echo ' fprintf(stderr, "'$newline'"); - }' >>mod_func.cpp - -for i in $base_names; do - echo ' _'`remove_spaces "$i"`'_reg();' - MODOBJS="$MODOBJS ./$i.o" -done >> mod_func.cpp - -echo "}" >> mod_func.cpp - -echo ' +' + + for i in "${base_names[@]}" ; do + echo "extern void _${i// }_reg(void);" + done + + echo "" + echo "void modl_reg() {" + echo " if (!nrn_nobanner_) if (nrnmpi_myid < 1) {" + printf ' fprintf(stderr, "Additional mechanisms from files\\n");\n' + + for i in "${files[@]}" + do + echo ' fprintf(stderr, " \"'"$i"'.mod\"");' + done + + printf ' fprintf(stderr, "\\n");\n' + + echo " }" + + for i in "${base_names[@]}" ; do + echo " _${i// }_reg();" + MODOBJS="$MODOBJS ./${i// /\\ }.o" + done + + echo "}" + + echo ' #if defined(__cplusplus) } -#endif' >> mod_func.cpp - -if test -n "$nrnivmodl_cfiles" ; then - sp="" - COBJS="" - ifs="$IFS" - IFS=';' - for i in $nrnivmodl_cfiles ; do - base_name=`basename "$i" .c` - COBJS="${COBJS}${sp}./${base_name}.o" - sp=" " - done - IFS="$ifs" -fi -echo "COBJS='$COBJS'" +#endif' +} > mod_func.cpp # call nrnivmodl-core if CoreNEURON is enabled and requested via CLI -UsingCoreNEURON="no" -@CORENEURON_ENABLED_TRUE@UsingCoreNEURON="yes" +UsingCoreNEURON=false +@CORENEURON_ENABLED_TRUE@UsingCoreNEURON=true if [ "$LinkCoreNEURON" = true ] ; then - if [ "$UsingCoreNEURON" = "yes" ] ; then - cd $USER_PWD - args="" - # pass the nrnivmodl file args to nrnivmodl-core (with spaces escaped) - for i in "$@"; do - j=`hide_spaces "$i"` - j=`escape_spaces "$j"` - args="$args $j" - done - "${cnrn_prefix}/bin/nrnivmodl-core" "${UserCOREFLAGS[@]}" $args - cd $MODSUBDIR + if [ "$UsingCoreNEURON" = true ] ; then + if [ "$#" -gt 1 ] ; then + printf "ERROR : when called with -coreneuron only 1 mod dir is accepted.\n" + exit 1 + fi + cd "$USER_PWD" + "${cnrn_prefix}/bin/nrnivmodl-core" "${UserCOREFLAGS[@]}" "$@" + cd "$MODSUBDIR" else printf "ERROR : CoreNEURON support is not enabled!\n" exit 1 fi fi -make -j 4 -f "${MAKEFILEDIR}/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" "LinkCoreNEURON=$LinkCoreNEURON" special && +make -j 4 -f "${bindir}/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" "LinkCoreNEURON=$LinkCoreNEURON" special && echo "Successfully created $MODSUBDIR/special" diff --git a/bin/nrnivmodl_makefile_cmake.in b/bin/nrnivmodl_makefile_cmake.in index 70bd53c5b4..632964897c 100644 --- a/bin/nrnivmodl_makefile_cmake.in +++ b/bin/nrnivmodl_makefile_cmake.in @@ -1,12 +1,10 @@ # Arguments: # MODOBJFILES -# COBJFILES # UserLDFLAGS # UserINCFLAGS # LinkCoreNEURON -# Rules to build MODOBJFILES from mod files and COBJFILES from $nrnivmodl_cfiles -# are found in makemod2c_inc +# Rules to build MODOBJFILES from mod files are found in makemod2c_inc # Mechanisms version are by default 0.0, but should be overriden MECH_NAME = @@ -83,7 +81,6 @@ NRNUNITS = $(datadir_lib)/nrnunits.lib MODC_DIR = . OBJS_DIR = . mod_objs = $(MODOBJFILES) -c_objs = $(COBJFILES) mod_func_o = $(OBJS_DIR)/mod_func.o mod_func_cpp = $(MODC_DIR)/mod_func.cpp @@ -130,13 +127,13 @@ special: $(mech_lib) $(mech_lib): $(mech_lib_type) -mech_lib_shared: mod_func.o $(mod_objs) $(c_objs) $(nrn_lib) build_always +mech_lib_shared: mod_func.o $(mod_objs) $(nrn_lib) build_always @printf " => $(C_GREEN)LINKING$(C_RESET) shared library $(mech_lib)\n" $(CXX_LINK_SHARED) -I $(incdir) -o ${mech_lib} ${_SONAME} \ - $(mod_func_o) $(mod_objs) $(c_objs) $(NRNLIB_FLAGS) $(NRNLIB_RPATH_FLAGS) $(LDFLAGS) + $(mod_func_o) $(mod_objs) $(NRNLIB_FLAGS) $(NRNLIB_RPATH_FLAGS) $(LDFLAGS) rm -f $(OBJS_DIR)/.libs/libnrnmech.so ; mkdir -p $(OBJS_DIR)/.libs ; cp $(mech_lib) $(OBJS_DIR)/.libs/libnrnmech.so -mech_lib_static: mod_func.o $(mod_objs) $(c_objs) $(nrn_lib) build_always +mech_lib_static: mod_func.o $(mod_objs) $(nrn_lib) build_always @printf " => $(C_GREEN)LINKING$(C_RESET) static library $(mech_lib)\n" ar cq ${mech_lib} $(mod_func_o) $(mod_objs) $(cobjs); diff --git a/external/coreneuron b/external/coreneuron index 63066908dc..39f8fb792a 160000 --- a/external/coreneuron +++ b/external/coreneuron @@ -1 +1 @@ -Subproject commit 63066908dc4ca12f25b93906910a4aecdb3af12e +Subproject commit 39f8fb792a2b5f35f996276d8f62fe7b4194d275 diff --git a/packaging/python/test_wheels.sh b/packaging/python/test_wheels.sh index 5e6bd24d71..105c481d37 100755 --- a/packaging/python/test_wheels.sh +++ b/packaging/python/test_wheels.sh @@ -90,7 +90,7 @@ run_mpi_test () { # coreneuron execution via neuron if [[ "$has_coreneuron" == "true" ]]; then rm -rf $ARCH_DIR - nrnivmodl -coreneuron test/coreneuron/mod/ + nrnivmodl -coreneuron "test/coreneuron/mod files/" # python as a launcher can be used only with non-gpi build if [[ "$has_gpu_support" == "false" ]]; then @@ -165,7 +165,7 @@ run_serial_test () { $python_exe test/coreneuron/test_psolve.py fi - nrnivmodl -coreneuron test/coreneuron/mod/ + nrnivmodl -coreneuron "test/coreneuron/mod files/" # coreneuron+gpu can be used via python but special only if [[ "$has_gpu_support" == "false" ]]; then diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 62f8221fa6..0e83987bf2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -271,8 +271,8 @@ if(NRN_ENABLE_PYTHON AND PYTEST_FOUND) # This get used in 4 tests so make it the default and override in other tests. SCRIPT_PATTERNS test/coreneuron/test_spikes.py MODFILE_PATTERNS - test/coreneuron/mod/*.mod test/coreneuron/mod/axial.inc test/pynrn/unitstest.mod - test/pynrn/version_macros.mod test/gjtests/natrans.mod) + "test/coreneuron/mod files/*.mod" "test/coreneuron/mod files/axial.inc" + test/pynrn/unitstest.mod test/pynrn/version_macros.mod test/gjtests/natrans.mod) nrn_add_test( GROUP coreneuron_modtests NAME version_macros diff --git a/test/coreneuron/mod/axial.inc b/test/coreneuron/mod files/axial.inc similarity index 100% rename from test/coreneuron/mod/axial.inc rename to test/coreneuron/mod files/axial.inc diff --git a/test/coreneuron/mod/axial.mod b/test/coreneuron/mod files/axial.mod similarity index 100% rename from test/coreneuron/mod/axial.mod rename to test/coreneuron/mod files/axial.mod diff --git a/test/coreneuron/mod/axial_pp.mod b/test/coreneuron/mod files/axial_pp.mod similarity index 100% rename from test/coreneuron/mod/axial_pp.mod rename to test/coreneuron/mod files/axial_pp.mod diff --git a/test/coreneuron/mod/bacur.mod b/test/coreneuron/mod files/bacur.mod similarity index 100% rename from test/coreneuron/mod/bacur.mod rename to test/coreneuron/mod files/bacur.mod diff --git a/test/coreneuron/mod/banocur.mod b/test/coreneuron/mod files/banocur.mod similarity index 100% rename from test/coreneuron/mod/banocur.mod rename to test/coreneuron/mod files/banocur.mod diff --git a/test/coreneuron/mod/fornetcon.mod b/test/coreneuron/mod files/fornetcon.mod similarity index 100% rename from test/coreneuron/mod/fornetcon.mod rename to test/coreneuron/mod files/fornetcon.mod diff --git a/test/coreneuron/mod/invlfire.mod b/test/coreneuron/mod files/invlfire.mod similarity index 100% rename from test/coreneuron/mod/invlfire.mod rename to test/coreneuron/mod files/invlfire.mod diff --git a/test/coreneuron/mod/netmove.mod b/test/coreneuron/mod files/netmove.mod similarity index 100% rename from test/coreneuron/mod/netmove.mod rename to test/coreneuron/mod files/netmove.mod diff --git a/test/coreneuron/mod/sample.mod b/test/coreneuron/mod files/sample.mod similarity index 100% rename from test/coreneuron/mod/sample.mod rename to test/coreneuron/mod files/sample.mod diff --git a/test/coreneuron/mod/watchrange.mod b/test/coreneuron/mod files/watchrange.mod similarity index 100% rename from test/coreneuron/mod/watchrange.mod rename to test/coreneuron/mod files/watchrange.mod