1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#!/usr/bin/env bash
set -e
ARCH=@host_cpu@
MODSUBDIR=@modsubdir@
USER_PWD="$PWD"
if [ -z "$NRNHOME" ] ; then
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
else
prefix="$NRNHOME"
exec_prefix="${prefix}/${ARCH}"
bindir="${prefix}/bin"
libdir="${prefix}/lib"
fi
if [ -z ${CORENRNHOME+x} ] ; then
# CORENRNHOME wasn't set, use the install prefix
cnrn_prefix=@cnrn_prefix@
else
cnrn_prefix="${CORENRNHOME}"
fi
if [ "${NRNHOME_EXEC}" ] ; then
exec_prefix="${NRNHOME_EXEC}"
bindir="${exec_prefix}/bin"
libdir="${exec_prefix}/lib"
fi
export prefix
export bindir
export libdir
if command -v xcrun; then
@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
fi
fi
LinkCoreNEURON=false
UserINCFLAGS=""
UserLDFLAGS=""
UserCOREFLAGS=()
# - options come first but can be in any order.
while [ "$1" ] ; do
case "$1" in
-coreneuron)
# also run nrnivmodl-core
LinkCoreNEURON=true
shift;;
-incflags)
# extra include flags and paths (NEURON only)
UserINCFLAGS="$2"
# extra include flags and paths for CoreNEURON
UserCOREFLAGS+=(-i "${2}")
shift
shift;;
-loadflags)
# extra link flags, paths, libraries (NEURON only)
UserLDFLAGS="$2"
# extra lin flags, paths. libraries (CoreNEURON)
UserCOREFLAGS+=(-l "${2}")
shift
shift;;
-*)
echo "$1 unrecognized"
exit 1;;
*)
break;;
esac
done
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
# path is used, sometimes the spaces must be escaped (eg. a Makefile
# dependency pattern, and sometimes it is more useful for readability to
# enclose the path in "". To work around this issue, when creating a list
# of paths, translate the spaces for each item to +++ and after retrieval
# of an item, retranslate back to either a space or an escaped space.
# Only do this for cmake
shopt -s nullglob
# files is the complete list of mod files to process
files=()
if [ $# -gt 0 ] ; then
for i in "$@" ; do
if [ -d "$i" ] ; then
files+=( "$i"/*.mod )
elif [ -e "$i" ] || [ -e "$i.mod" ] ; then
files+=( "$i" )
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 ""
exit 1
fi
done
else
files=( *.mod )
fi
base_names=()
for i in "${files[@]}" ; do
base_names+=( "$(basename "$i" .mod)" )
done
echo -n "Mod files:"
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."
echo
mkdir "$MODSUBDIR"
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
> "$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 \"$dir_name\"; @NRN_NOCMODL_SANITIZER_ENVIRONMENT_STRING@ MODLUNIT=\$(NRNUNITS) \$(NOCMODL) \"$base_name.mod\" -o \"$mdir\")
./${base_name// /\\ }.o: ./${base_name// /\\ }.c
@printf \" -> \$(C_GREEN)Compiling\$(C_RESET) \$<\\\n\"
\$(COMPILE) -I\"$dir_name\" \$(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c \$< -o \$@
" >> "$MODMAKE"
done
MODOBJS=
{
echo '#include <stdio.h>
#include "hocdec.h"
extern int nrnmpi_myid;
extern int nrn_nobanner_;
#if defined(__cplusplus)
extern "C" {
#endif
'
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
# call nrnivmodl-core if CoreNEURON is enabled and requested via CLI
UsingCoreNEURON=false
@CORENEURON_ENABLED_TRUE@UsingCoreNEURON=true
if [ "$LinkCoreNEURON" = true ] ; then
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 "${bindir}/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" "LinkCoreNEURON=$LinkCoreNEURON" special &&
echo "Successfully created $MODSUBDIR/special"
|