Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0ab2d2877acd1c7aab56f16bdd37a17c29d4583f
[simgrid.git] / src / smpi / smpiff.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2012-2017. The SimGrid Team.
4 # All rights reserved.
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
8
9 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
10 SIMGRID_GITHASH="@SIMGRID_GITHASH@"
11
12 F77=@SMPI_Fortran_COMPILER@
13
14 INCLUDEARGS="@includeflag@"
15 CMAKE_LINKARGS="-L@libdir@"
16
17 @SMPITOOLS_SH@
18
19 list_set FFLAGS @SMPI_Fortran_FLAGS@
20 list_set LINKARGS "-shared" "-lsimgrid" @SMPI_Fortran_LIBS@ "-lm"
21 list_set TMPFILES
22 main_name=main
23
24 cleanup () {
25     eval $(list_get TMPFILES)
26     rm -f "$@"
27 }
28 trap 'cleanup' EXIT
29
30 filter_and_compile() {
31     list_add TMPFILES "${TMPFILE}"
32     #replace "program main_name by subroutine user\_main (and the end clause as well)"
33     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
34       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
35     echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
36     fi
37     sed 's/[[:space:]]\{6\}[[:space:]]*\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/      \1subroutine user_main /g;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" >> "${TMPFILE}"
38     SRCFILE="${TMPFILE}"
39     list_add CMDLINE "${SRCFILE}"
40 }
41 TRACE_CALL_LOCATION=0
42 NEEDS_OUTPUT=1
43
44 list_set CMDLINE "${F77}"
45 list_add_not_empty CMDLINE "${FFLAGS}"
46 while [ $# -gt 0 ]; do
47     ARG="$1"
48     shift
49     case "${ARG}" in
50         -c)
51             CMAKE_LINKARGS=""
52             LINKARGS=""
53             list_add CMDLINE "-c"
54             ;;
55         *.f)
56             FILENAME=`basename ${ARG}`
57             TMPFILE=$(mymktemp "${ARG}" ".f")
58             ORIGFILE="${FILENAME%.f}"
59             filter_and_compile
60             ;;
61         *.F)$
62             FILENAME=`basename ${ARG}`
63             TMPFILE=$(mymktemp "${ARG}" ".F")
64             ORIGFILE="${FILENAME%.F}"
65             filter_and_compile
66             ;;
67         '-version' | '--version')
68             printf '%b\n' "$SIMGRID_VERSION"
69             exit 0
70             ;;
71         "-git-version" | "--git-version")
72             printf '%b\n' "$SIMGRID_GITHASH"
73             exit 0
74             ;;
75         '-compiler-version' | '--compiler-version')
76             ${F77} --version
77             ;;
78         '-trace-call-location')
79             TRACE_CALL_LOCATION=1
80             # This should be list_add FFLAGS but it's not possible
81             # anymore: FFLAGS was already moved into CMDLINE above.
82             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
83             ;;
84         -o)
85             NEEDS_OUTPUT=0
86             list_add CMDLINE "-o$1"
87             shift
88             ;;        
89         *)
90             list_add CMDLINE "${ARG}"
91             ;;
92     esac
93 done
94
95 if [ $NEEDS_OUTPUT -ne 0 ]; then
96    list_add CMDLINE "-o${ORIGFILE}.o"     
97 fi
98
99 list_add_not_empty CMDLINE ${INCLUDEARGS}
100 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
101 list_add_not_empty CMDLINE "${LINKARGS}"
102
103 eval $(list_get CMDLINE)
104 "$@"