5959#
6060# REQUIRES
6161# FoBiS.py : https://github.com/szaghi/FoBiS [version 1.2.5 or later required]
62- # FORD : https://github.com/cmacmackin/ford [version 3 .0.2 is the one tested ]
62+ # FORD : https://github.com/cmacmackin/ford [version 4 .0.0 or later ]
6363#
6464# AUTHOR
6565# Jacob Williams : 12/27/2014
6666#
6767
68- set -e
68+ set -o errexit
6969
7070FORDMD=' json-fortran.md' # FORD options file for building documentation
7171DOCDIR=' ./doc/' # build directory for documentation
@@ -97,7 +97,7 @@ FCOMPILER='gnu' #Set default compiler to gfortran
9797# e.g., "./build.sh --compiler intel --coverage no --compiler gnu --coverage" will
9898# perform the build with the GFORTRAN compiler, and coverage analysis
9999
100- script_name=" $( basename $0 ) "
100+ script_name=" $( basename " $0 " ) "
101101
102102# usage message
103103print_usage () {
@@ -213,7 +213,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
213213 shift
214214 ;;
215215 no|No|NO)
216- JF_SKIP_DOCSS =" no"
216+ JF_SKIP_DOCS =" no"
217217 shift
218218 ;;
219219 * )
@@ -226,7 +226,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
226226 exit 0
227227 ;;
228228 --clean)
229- rm -r src{,/tests}/* .o $DOCDIR * $LIBDIR * $BINDIR * * .gcov*
229+ rm -r -- src{,/tests}/* .o $DOCDIR * $LIBDIR * $BINDIR * * .gcov*
230230 ;;
231231 * )
232232 echo " Unknown flag, \" $1 \" , passed to ${script_name} !" 2>&1
254254
255255if [[ $FCOMPILER == custom ]]; then
256256 echo " Trying to compile with custom compiler, $FC "
257- CUSTOM=" -fc $FC "
257+ CUSTOM=( " -fc" " $FC " )
258258fi
259259
260260if [[ $TRY_UNICODE == [yY]* ]]; then
261261 echo " Trying to compile library with Unicode/UCS4 support"
262- FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags " ${FCOMPILERFLAGS} " -dbld " ${BINDIR} " -s " ${INTROSPECDIR} " -dmod ./ -dobj ./ -t ${UCS4TESTCODE} -o ${UCS4TESTCODE% .f90} -colors
262+ FoBiS.py build -ch -compiler " ${FCOMPILER} " " ${CUSTOM[@]} " -cflags " ${FCOMPILERFLAGS} " -dbld " ${BINDIR} " -s " ${INTROSPECDIR} " -dmod ./ -dobj ./ -t " ${UCS4TESTCODE} " -o " ${UCS4TESTCODE% .f90} " -colors
263263 if " ${BINDIR} /${UCS4TESTCODE% .f90} " ; then
264264 DEFINES=" -DUSE_UCS4 -Wunused-function"
265265 fi
269269echo " "
270270echo " Building library..."
271271
272- FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags " ${FCOMPILERFLAGS} ${DEFINES} " ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
272+ FoBiS.py build -ch -compiler ${FCOMPILER} " ${CUSTOM[@]} " -cflags " ${FCOMPILERFLAGS} ${DEFINES} " ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
273273
274274# build the unit tests (uses the above library):
275275if [[ $JF_SKIP_TESTS != [yY]* ]]; then
@@ -282,7 +282,7 @@ if [[ $JF_SKIP_TESTS != [yY]* ]]; then
282282 for TEST in " ${TESTDIR%/ } " /jf_test_* .[fF]90; do
283283 THIS_TEST=${TEST##*/ }
284284 echo " Build ${THIS_TEST% .[fF]90} "
285- FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags " ${FCOMPILERFLAGS} ${DEFINES} " ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR} /${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST% .[fF]90} -colors
285+ FoBiS.py build -ch -compiler ${FCOMPILER} " ${CUSTOM[@]} " -cflags " ${FCOMPILERFLAGS} ${DEFINES} " ${COVERAGE} ${PROFILING} -dbld " ${BINDIR} " -s " ${TESTDIR} " -i " ${LIBDIR} " -libs " ${LIBDIR} /${LIBOUT} " -dmod ./ -dobj ./ -t " ${THIS_TEST} " -o " ${THIS_TEST% .[fF]90} " -colors
286286 done
287287else
288288 echo " Skip building the unit tests since \$ JF_SKIP_TESTS has been set to 'true'."
292292echo " "
293293if [[ $JF_SKIP_TESTS != [yY]* ]] ; then
294294 echo " Running tests..."
295- cd " $BINDIR "
296295 OLD_IGNORES=" $GLOBIGNORE "
296+ # run next commands in subshell to avoid `cd -`
297+ (cd " $BINDIR "
297298 GLOBIGNORE=' *.*'
298299 #
299300 for TEST in jf_test_* ; do
300301 # It would be nice to run json output printed to stdout through jsonlint, however,
301302 # some tests output more than one json structure and these need to be split
302303 echo " Running ${TEST} "
303- ./${TEST}
304- done
305- cd -
304+ " ./${TEST} "
305+ done)
306306 GLOBIGNORE=" $OLD_IGNORES "
307307 if [[ $CODE_COVERAGE = [yY]* ]] ; then
308308 for SRCFILE in json_string_utilities.F90 json_value_module.F90 json_file_module.F90 ; do
0 commit comments