Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5361c3bb95ecff1e18e7d1d00c1d95aac2da7266
[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 list_set LINKARGS "-shared" "-lsimgrid" @SMPI_Fortran_LIBS@ "-lm"
20 list_set TMPFILES
21 main_name=main
22
23 cleanup () {
24     eval $(list_get TMPFILES)
25     rm -f "$@"
26 }
27 trap 'cleanup' EXIT
28
29 filter_and_compile_f77() {
30     list_add TMPFILES "${TMPFILE}"
31     #replace "program main_name by subroutine user\_main (and the end clause as well)"
32     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
33       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
34       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
35     fi
36     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}"
37     SRCFILE="${TMPFILE}"
38     list_add CMDLINE "${SRCFILE}"
39 }
40 filter_and_compile_f90() {
41     list_add TMPFILES "${TMPFILE}"
42     #replace "program main_name by subroutine user\_main (and the end clause as well)"
43     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
44       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
45       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
46     fi
47     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}"
48     SRCFILE="${TMPFILE}"
49     list_add CMDLINE "${SRCFILE}"
50 }
51 TRACE_CALL_LOCATION=0
52 NEEDS_OUTPUT=1
53
54 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
55 list_add_not_empty CMDLINE "${FFLAGS}"
56 while [ $# -gt 0 ]; do
57     ARG="$1"
58     shift
59     case "${ARG}" in
60         -c)
61             CMAKE_LINKARGS=""
62             LINKARGS=""
63             list_add CMDLINE "-c"
64             ;;
65         *.f)
66             FILENAME=`basename ${ARG}`
67             TMPFILE=$(mymktemp "${ARG}" ".f")
68             ORIGFILE="${FILENAME%.f}"
69             filter_and_compile_f77
70             ;;
71         *.F)$
72             FILENAME=`basename ${ARG}`
73             TMPFILE=$(mymktemp "${ARG}" ".F")
74             ORIGFILE="${FILENAME%.F}"
75             filter_and_compile_f77
76             ;;
77         *.f90)
78             FILENAME=`basename ${ARG}`
79             TMPFILE=$(mymktemp "${ARG}" ".f90")
80             ORIGFILE="${FILENAME%.f90}"
81             filter_and_compile_f90
82             ;;
83         *.F90)$
84             FILENAME=`basename ${ARG}`
85             TMPFILE=$(mymktemp "${ARG}" ".F90")
86             ORIGFILE="${FILENAME%.F90}"
87             filter_and_compile_f90
88             ;;
89         '-version' | '--version')
90             printf '%b\n' "$SIMGRID_VERSION"
91             exit 0
92             ;;
93         "-git-version" | "--git-version")
94             printf '%b\n' "$SIMGRID_GITHASH"
95             exit 0
96             ;;
97         '-compiler-version' | '--compiler-version')
98             ${REAL_FORTRAN_COMPILER} --version
99             ;;
100         '-trace-call-location')
101             TRACE_CALL_LOCATION=1
102             # This should be list_add FFLAGS but it's not possible
103             # anymore: FFLAGS was already moved into CMDLINE above.
104             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
105             ;;
106         -o)
107             list_add CMDLINE "-o$1"
108             NEEDS_OUTPUT=0
109             shift
110             ;;
111         *)
112             list_add CMDLINE "${ARG}"
113             ;;
114     esac
115 done
116
117 if [ $NEEDS_OUTPUT -ne 0 ]; then
118    list_add CMDLINE "-o${ORIGFILE}.o"
119 fi
120
121 list_add_not_empty CMDLINE ${INCLUDEARGS}
122 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
123 list_add_not_empty CMDLINE "${LINKARGS}"
124
125 eval $(list_get CMDLINE)
126 "$@"