Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
generate unique names, but easier for debug
[simgrid.git] / src / smpi / smpif90.in
1 #! /bin/bash
2
3 CC=gfortran
4
5 INCLUDEARGS="@includeflag@"
6 CMAKE_LINKARGS="-L@libdir@"
7
8 FFLAGS="-ff2c  -fno-second-underscore"
9 LINKARGS="-lsimgrid -lm -lgfortran"
10 main_name=main
11 TMPFILE=$(mktemp).f90
12 CMDLINE=""
13 while [ -n "$1" ]; do
14   ARG="$1"
15   shift
16   case "${ARG}" in
17    -c)
18       CMAKE_LINKARGS=""
19       LINKARGS=""
20       CMDLINE="${CMDLINE} -c "
21       ;;
22    *.f90|*.F90)
23       SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
24       if [ -z $SRCFILE ] ; then
25          SRCFILE="$ARG"
26       fi
27
28       TMPFILE=${ARG}\_$RANDOM.f90
29       #replace "program main_name by subroutine user\_main (and the end clause as well)"
30       sed 's/[[:space:]]*program[[:space:]]*\([a-zA-Z0-9\-\_]*\)/subroutine user\_main /gI;s/[[:space:]]*use[[:space:]]*mpi/\include \"mpif\.h\" /gI'  ${ARG} > ${TMPFILE}
31       SRCFILE="${TMPFILE}"
32       CMDLINE="${CMDLINE} ${SRCFILE} "
33       ;;
34    *)
35       CMDLINE="${CMDLINE} ${ARG} "
36       ;;
37   esac
38 done
39
40 CMDLINE="${CC} ${FFLAGS} ${CMDLINE} ${INCLUDEARGS} ${CMAKE_LINKARGS} ${LINKARGS}"
41
42 #echo "${CMDLINE}"
43 ${CMDLINE}
44
45 if [ -f ${TMPFILE} ];then
46   rm ${TMPFILE}
47 fi