Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deal with empty args.
[simgrid.git] / src / smpi / smpiff.in
1 #! /bin/sh
2
3 prefix="@exec_prefix@"
4 smpicc="$prefix/bin/smpicc"
5 smpif2c="$prefix/bin/smpif2c"
6
7 @SMPITOOLS_SH@
8
9 list_set ARGS "-DMAIN__=user_main" "-Diargc_=smpi_process_argc" "-Dgetarg_=smpi_process_getarg"
10 list_set LINKARGS "-L@F2C_LIBRARY_PATH@" "-lf2c" "-lm"
11 list_set SRCFILES
12
13 while [ $# -gt 0 ]; do
14     ARG="$1"
15     shift
16     case "${ARG}" in
17         *.f)
18             SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
19             if [ -z "$SRCFILE" ] ; then
20                 SRCFILE="$ARG"
21             fi
22             list_add SRCFILES "${SRCFILE}"
23             ;;
24         *)
25             if [ "${ARG}" = "-c" ]; then
26                 LINKARGS=""
27             fi
28             list_add ARGS "${ARG}"
29             ;;
30     esac
31 done
32 list_add_not_empty ARGS "${LINKARGS}"
33
34 build () {
35     local SRCFILE
36     SCFILE="$1"
37     TMPFILE=$(mymktemp "${SRCFILE}" ".f")
38     CFILE="${TMPFILE%.f}.c"
39
40     eval $(list_get ARGS)
41
42     cp "${SRCFILE}" "${TMPFILE}" \
43         && "$smpif2c" "${TMPFILE}" \
44         && "$smpicc" "$@" "${CFILE}" \
45         && rm -f "${CFILE}" \
46         && rm -f "${TMPFILE}" \
47         || exit $?
48
49     # When the file is compiled with "-c" and no output file is specified with
50     # "-o", rename the output.  FIXME: do it properly.
51     if [ -f "${CFILE%.c}.o" ]; then
52         mv "${CFILE%.c}.o" "${SRCFILE%.f}.o"
53     fi
54 }
55
56 if [ -n "${SRCFILES}" ]; then
57     eval $(list_get SRCFILES)
58     for SRCFILE in "$@"; do
59         build "$SRCFILE"
60     done
61 else
62     eval $(list_get ARGS)
63     "$smpicc" "$@"
64 fi