Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b5c10f0e5579cfcf9c360d822722cfd485abf2a4
[simgrid.git] / src / smpi / smpiff.in
1 #! /usr/bin/env bash
2 prefix="@exec_prefix@"
3
4 ARGS="-DMAIN__=user_main -Diargc_=smpi_process_argc -Dgetarg_=smpi_process_getarg"
5 LINKARGS="-lf2c -lm"
6 declare -a SRCFILES
7
8 # $1: prefix, $2: suffix
9 mymktemp () {
10     tmp=$(mktemp --suffix="$2" "$1_XXXXXXXXXX" 2> /dev/null)
11     if [ -z "$tmp" ]; then
12         # mktemp failed (unsupported --suffix ?), try unsafe mode
13         tmp=$(mktemp -u "$1_XXXXXXXXXX" 2> /dev/null)
14         if [ -z "$tmp" ]; then
15             # mktemp failed again (doesn't exist ?), try very unsafe mode
16             tmp="$1_$$x$RANDOM"
17         fi
18         tmp="${tmp}$2"
19         # create temp file, and exit if it existed before
20         sh -C -c "true > \"${tmp}\"" || exit 1
21     fi
22     echo "${tmp}"
23 }
24
25 while [ -n "$1" ]; do
26   ARG="$1"
27   shift
28   case "${ARG}" in
29     *.f)
30       SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
31        if [ -z "$SRCFILE" ] ; then
32          SRCFILE="$ARG"
33        fi
34        SRCFILES+="${SRCFILE}"
35        ;;
36     *)
37       if [ "${ARG}" = "-c" ]; then
38           LINKARGS=""
39       fi
40       ARGS="${ARGS} ${ARG}"
41       ;;
42   esac
43 done
44 ARGS="${ARGS} ${LINKARGS}"
45
46 if [ -n "${SRCFILES}" ]
47 then
48    for SRCFILE in "${SRCFILES[@]}"
49    do
50       TMPFILE=$(mymktemp "${SRCFILE}" ".f")
51       cp ${SRCFILE} ${TMPFILE}
52       CFILE="${TMPFILE%.f}.c"
53       #echo "$prefix/bin/smpif2c ${TMPFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} && rm ${TMPFILE}"
54       $prefix/bin/smpif2c ${TMPFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} && rm ${TMPFILE} || exit $?
55       # When the file is compiled with "-c" and no output file is specified with
56       # "-o", rename the output.  FIXME: do it properly.
57       if [ -f ${CFILE%.c}.o ]; then
58           mv ${CFILE%.c}.o ${SRCFILE%.f}.o
59       fi
60    done
61 else
62    #echo "$prefix/bin/smpicc ${ARGS}"
63    $prefix/bin/smpicc ${ARGS}
64 fi