X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9e68ca10e951fb61e944c99c7774b1e415ae9f6d..7655578ae329f484a219af5eef138eb7ad10b997:/src/smpi/smpiff.in diff --git a/src/smpi/smpiff.in b/src/smpi/smpiff.in index b86184bd96..feb45630ed 100644 --- a/src/smpi/smpiff.in +++ b/src/smpi/smpiff.in @@ -1,17 +1,33 @@ -#! /bin/bash +#! /bin/sh prefix="@exec_prefix@" ARGS="-DMAIN__=user_main -Diargc_=smpi_process_argc -Dgetarg_=smpi_process_getarg" -LINKARGS="-lf2c" -SRCFILES="" +LINKARGS="-L@F2C_LIBRARY_PATH@ -lf2c -lm" +# $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}" +} +SRCFILES="" while [ -n "$1" ]; do ARG="$1" shift case "${ARG}" in *.f) SRCFILE="$(readlink -f ${ARG} 2>/dev/null)" - if [ -z $SRCFILE ] ; then + if [ -z "$SRCFILE" ] ; then SRCFILE="$ARG" fi SRCFILES="${SRCFILES} ${SRCFILE}" @@ -28,11 +44,18 @@ ARGS="${ARGS} ${LINKARGS}" if [ -n "${SRCFILES}" ] then - for SRCFILE in "${SRCFILES}" + for SRCFILE in ${SRCFILES} do - CFILE="${SRCFILE%.f}.c" - #echo "$prefix/bin/smpif2c ${SRCFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE}" - $prefix/bin/smpif2c ${SRCFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} + TMPFILE=$(mymktemp "${SRCFILE}" ".f") + cp ${SRCFILE} ${TMPFILE} + CFILE="${TMPFILE%.f}.c" + #echo "$prefix/bin/smpif2c ${TMPFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} && rm ${TMPFILE}" + $prefix/bin/smpif2c ${TMPFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} && rm ${TMPFILE} || exit $? + # When the file is compiled with "-c" and no output file is specified with + # "-o", rename the output. FIXME: do it properly. + if [ -f ${CFILE%.c}.o ]; then + mv ${CFILE%.c}.o ${SRCFILE%.f}.o + fi done else #echo "$prefix/bin/smpicc ${ARGS}"