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
@@ -78,7 +78,7 @@ BINDIR='./bin/' # build directory for unit tests
7878LIBDIR=' ./lib/' # build directory for library
7979MODCODE=' json_module.F90' # json module file name
8080LIBOUT=' libjsonfortran.a' # name of json library
81-
81+ FPP= " gfortran -E " # default to gfortran -E pre-processing
8282
8383# The following warning might be triggered by ifort unless explicitly silenced:
8484# warning #7601: F2008 standard does not allow an internal procedure to be an actual argument procedure name. (R1214.4).
@@ -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 () {
@@ -122,18 +122,21 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
122122 intel|Intel|INTEL|ifort)
123123 FCOMPILER=' Intel'
124124 FCOMPILERFLAGS=" $INTELCOMPILERFLAGS "
125+ FPP=" fpp"
125126 shift
126127 ;;
127128 gnu|Gnu|GNU|gfortran|Gfortran|GFortran|GFORTRAN)
128129 FCOMPILER=' gnu'
129130 FCOMPILERFLAGS=" $GNUCOMPILERFLAGS "
131+ FPP=" gfortran -E"
130132 shift
131133 ;;
132134 * )
133135 FCOMPILER=" custom"
134136 echo " Warning: Trying to build with unsupported compiler, $2 ." 1>&2
135137 echo " Please ensure you set appropriate --cflags and (single) quote them" 1>&2
136138 FC=" $2 "
139+ FPP=" gfortran -E" # try gfortran to preprocess as a default
137140 shift
138141 ;;
139142 esac
@@ -213,7 +216,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
213216 shift
214217 ;;
215218 no|No|NO)
216- JF_SKIP_DOCSS =" no"
219+ JF_SKIP_DOCS =" no"
217220 shift
218221 ;;
219222 * )
@@ -226,7 +229,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
226229 exit 0
227230 ;;
228231 --clean)
229- rm -r src{,/tests}/* .o $DOCDIR * $LIBDIR * $BINDIR * * .gcov*
232+ rm -r -- src{,/tests}/* .o $DOCDIR * $LIBDIR * $BINDIR * * .gcov*
230233 ;;
231234 * )
232235 echo " Unknown flag, \" $1 \" , passed to ${script_name} !" 2>&1
254257
255258if [[ $FCOMPILER == custom ]]; then
256259 echo " Trying to compile with custom compiler, $FC "
257- CUSTOM=" -fc $FC "
260+ CUSTOM=( " -fc" " $FC " )
258261fi
259262
260263if [[ $TRY_UNICODE == [yY]* ]]; then
261264 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
265+ FoBiS.py build -ch -compiler " ${FCOMPILER} " " ${CUSTOM[@]} " -cflags " ${FCOMPILERFLAGS} " -dbld " ${BINDIR} " -s " ${INTROSPECDIR} " -dmod ./ -dobj ./ -t " ${UCS4TESTCODE} " -o " ${UCS4TESTCODE% .f90} " -colors
263266 if " ${BINDIR} /${UCS4TESTCODE% .f90} " ; then
264267 DEFINES=" -DUSE_UCS4 -Wunused-function"
265268 fi
269272echo " "
270273echo " Building library..."
271274
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
275+ 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
273276
274277# build the unit tests (uses the above library):
275278if [[ $JF_SKIP_TESTS != [yY]* ]]; then
@@ -282,7 +285,7 @@ if [[ $JF_SKIP_TESTS != [yY]* ]]; then
282285 for TEST in " ${TESTDIR%/ } " /jf_test_* .[fF]90; do
283286 THIS_TEST=${TEST##*/ }
284287 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
288+ 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
286289 done
287290else
288291 echo " Skip building the unit tests since \$ JF_SKIP_TESTS has been set to 'true'."
292295echo " "
293296if [[ $JF_SKIP_TESTS != [yY]* ]] ; then
294297 echo " Running tests..."
295- cd " $BINDIR "
296298 OLD_IGNORES=" $GLOBIGNORE "
299+ # run next commands in subshell to avoid `cd -`
300+ (cd " $BINDIR "
297301 GLOBIGNORE=' *.*'
298302 #
299303 for TEST in jf_test_* ; do
300304 # It would be nice to run json output printed to stdout through jsonlint, however,
301305 # some tests output more than one json structure and these need to be split
302306 echo " Running ${TEST} "
303- ./${TEST}
304- done
305- cd -
307+ " ./${TEST} "
308+ done)
306309 GLOBIGNORE=" $OLD_IGNORES "
307310 if [[ $CODE_COVERAGE = [yY]* ]] ; then
308311 for SRCFILE in json_string_utilities.F90 json_value_module.F90 json_file_module.F90 ; do
@@ -343,8 +346,9 @@ echo ""
343346if [[ $JF_SKIP_DOCS != [yY]* ]]; then
344347 if hash ford 2> /dev/null; then
345348 echo " Building documentation..."
346- [[ $TRY_UNICODE = [yY]* ]] && MACRO_FLAG=" -m USE_UCS4"
347- ford $MACRO_FLAG -p $PAGESDIR $FORDMD
349+ [[ $TRY_UNICODE = [yY]* ]] && MACRO_FLAG=(" -m" " USE_UCS4" )
350+ echo " $FPP " > preprocessor-def.md # Override via include in project file, until FORD gets CLI for this
351+ ford --debug " ${MACRO_FLAG[@]} " -p " $PAGESDIR " " $FORDMD "
348352 else
349353 echo " FORD not found! Install using: sudo pip install ford"
350354 fi
0 commit comments