Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deal with empty args.
[simgrid.git] / src / smpi / smpif90.in
1 #! /bin/sh
2
3 F90=@GFORTRAN_EXE@
4
5 INCLUDEARGS="@includeflag@"
6 CMAKE_LINKARGS="-L@libdir@"
7
8 @SMPITOOLS_SH@
9
10 list_set FFLAGS "-ff2c" "-fno-second-underscore"
11 list_set LINKARGS "-lsimgrid" "-lm" "-lgfortran"
12 list_set TMPFILES
13 main_name=main
14
15 cleanup () {
16     eval $(list_get TMPFILES)
17     rm -f "$@"
18 }
19 trap 'cleanup' EXIT
20
21 list_set CMDLINE "${F90}"
22 list_add_not_empty CMDLINE "${FFLAGS}"
23 while [ $# -gt 0 ]; do
24     ARG="$1"
25     shift
26     case "${ARG}" in
27         -c)
28             CMAKE_LINKARGS=""
29             LINKARGS=""
30             list_add CMDLINE "-c"
31             ;;
32         *.f90|*.F90)
33             TMPFILE=$(mymktemp "${ARG}" ".f90")
34             list_add TMPFILES "${TMPFILE}"
35       #replace "program main_name by subroutine user\_main (and the end clause as well)"
36             sed 's/[[:space:]]*program[[:space:]]*\([a-zA-Z0-9\-\_]*\)/subroutine user\_main /gI;s/[[:space:]]*use[[:space:]]*mpi/\include \"mpif\.h\" /gI' "${ARG}" > "${TMPFILE}"
37             SRCFILE="${TMPFILE}"
38             list_add CMDLINE "${SRCFILE}"
39             ;;
40         *)
41             list_add CMDLINE "${ARG}"
42             ;;
43     esac
44 done
45
46 list_add_not_empty CMDLINE ${INCLUDEARGS}
47 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
48 list_add_not_empty CMDLINE "${LINKARGS}"
49
50 eval $(list_get CMDLINE)
51 "$@"