-#! /bin/bash
+#! /bin/sh
-CC=@CMAKE_REAL_Fortran_Compiler@
+F90=@GFORTRAN_EXE@
INCLUDEARGS="@includeflag@"
CMAKE_LINKARGS="-L@libdir@"
-FFLAGS="-O2 -cpp -Dprogram=subroutine -Dmain=user_main -ff2c "
-LINKARGS="-lsimgrid -lsmpi -lm -lgfortran"
+FFLAGS="-ff2c -fno-second-underscore"
+LINKARGS="-lsimgrid -lm -lgfortran"
+main_name=main
+trap 'rm -f ${TMPFILES}' EXIT
+
+# $1: prefix, $2: suffix
+mymktemp () {
+ tmp=$(mktemp --suffix="$2" "$1_XXXXXXXXXX" 2> /dev/null)
+ if [ -z "$tmp" ]; then
+ # mktemp failed (unsupported --suffix ?), try unsafe mode
+ tmp=$(mktemp -u "$1_XXXXXXXXXX" 2> /dev/null)
+ if [ -z "$tmp" ]; then
+ # mktemp failed again (doesn't exist ?), try very unsafe mode
+ tmp="$1_$$x$RANDOM"
+ fi
+ tmp="${tmp}$2"
+ # create temp file, and exit if it existed before
+ sh -C -c "true > \"${tmp}\"" || exit 1
+ fi
+ echo "${tmp}"
+}
CMDLINE=""
while [ -n "$1" ]; do
CMDLINE="${CMDLINE} -c "
;;
*.f90|*.F90)
- SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
- if [ -z $SRCFILE ] ; then
- SRCFILE="$ARG"
- fi
+ TMPFILE=$(mymktemp "${ARG}" ".f90")
+ TMPFILES="${TMPFILES} ${TMPFILE}"
+ #replace "program main_name by subroutine user\_main (and the end clause as well)"
+ sed 's/[[:space:]]*program[[:space:]]*\([a-zA-Z0-9\-\_]*\)/subroutine user\_main /gI;s/[[:space:]]*use[[:space:]]*mpi/\include \"mpif\.h\" /gI' ${ARG} > ${TMPFILE}
+ SRCFILE="${TMPFILE}"
CMDLINE="${CMDLINE} ${SRCFILE} "
;;
*)
esac
done
-CMDLINE="${CC} ${FFLAGS} ${CMDLINE} ${INCLUDEARGS} ${CMAKE_LINKARGS} ${LINKARGS}"
+CMDLINE="${F90} ${FFLAGS} ${CMDLINE} ${INCLUDEARGS} ${CMAKE_LINKARGS} ${LINKARGS}"
#echo "${CMDLINE}"
${CMDLINE}