Logo AND Algorithmique Numérique Distribuée

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