Logo AND Algorithmique Numérique Distribuée

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