Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the undue differences between smpiff and smpif90
[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() {
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;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" >> "${TMPFILE}"
37     SRCFILE="${TMPFILE}"
38     list_add CMDLINE "${SRCFILE}"
39 }
40 TRACE_CALL_LOCATION=0
41 NEEDS_OUTPUT=1
42
43 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
44 list_add_not_empty CMDLINE "${FFLAGS}"
45 while [ $# -gt 0 ]; do
46     ARG="$1"
47     shift
48     case "${ARG}" in
49         -c)
50             CMAKE_LINKARGS=""
51             LINKARGS=""
52             list_add CMDLINE "-c"
53             ;;
54         *.f)
55             FILENAME=`basename ${ARG}`
56             TMPFILE=$(mymktemp "${ARG}" ".f")
57             ORIGFILE="${FILENAME%.f}"
58             filter_and_compile
59             ;;
60         *.F)$
61             FILENAME=`basename ${ARG}`
62             TMPFILE=$(mymktemp "${ARG}" ".F")
63             ORIGFILE="${FILENAME%.F}"
64             filter_and_compile
65             ;;
66         '-version' | '--version')
67             printf '%b\n' "$SIMGRID_VERSION"
68             exit 0
69             ;;
70         "-git-version" | "--git-version")
71             printf '%b\n' "$SIMGRID_GITHASH"
72             exit 0
73             ;;
74         '-compiler-version' | '--compiler-version')
75             ${REAL_FORTRAN_COMPILER} --version
76             ;;
77         '-trace-call-location')
78             TRACE_CALL_LOCATION=1
79             # This should be list_add FFLAGS but it's not possible
80             # anymore: FFLAGS was already moved into CMDLINE above.
81             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
82             ;;
83         -o)
84             list_add CMDLINE "-o$1"
85             NEEDS_OUTPUT=0
86             shift
87             ;;
88         *)
89             list_add CMDLINE "${ARG}"
90             ;;
91     esac
92 done
93
94 if [ $NEEDS_OUTPUT -ne 0 ]; then
95    list_add CMDLINE "-o${ORIGFILE}.o"
96 fi
97
98 list_add_not_empty CMDLINE ${INCLUDEARGS}
99 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
100 list_add_not_empty CMDLINE "${LINKARGS}"
101
102 eval $(list_get CMDLINE)
103 "$@"