Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Apply the default settings of 'smpi/buffering' too
[simgrid.git] / src / smpi / smpiff.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2012-2019. 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][^a-zA-Z0-9]*\([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:]]*\)\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/\1\2subroutine 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 # By default, we execute the commands instead of only showing them to cmake
60 Show=
61
62 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
63 list_add_not_empty CMDLINE "${FFLAGS}"
64 while [ $# -gt 0 ]; do
65     ARG="$1"
66     shift
67     case "${ARG}" in
68         -c)
69             CMAKE_LINKARGS=""
70             LINKARGS=""
71             list_add CMDLINE "-c"
72             ;;
73         *.f)
74             FILENAME=`basename ${ARG}`
75             TMPFILE=$(mymktemp "${ARG}" ".f")
76             ORIGFILE="${FILENAME%.f}"
77             filter_and_compile_f77
78             ;;
79         *.F)$
80             FILENAME=`basename ${ARG}`
81             TMPFILE=$(mymktemp "${ARG}" ".F")
82             ORIGFILE="${FILENAME%.F}"
83             filter_and_compile_f77
84             ;;
85         *.f90)
86             FILENAME=`basename ${ARG}`
87             TMPFILE=$(mymktemp "${ARG}" ".f90")
88             ORIGFILE="${FILENAME%.f90}"
89             filter_and_compile_f90
90             ;;
91         *.F90)$
92             FILENAME=`basename ${ARG}`
93             TMPFILE=$(mymktemp "${ARG}" ".F90")
94             ORIGFILE="${FILENAME%.F90}"
95             filter_and_compile_f90
96             ;;
97         '-version' | '--version')
98             printf '%b\n' "$SIMGRID_VERSION"
99             exit 0
100             ;;
101         "-git-version" | "--git-version")
102             printf '%b\n' "$SIMGRID_GITHASH"
103             exit 0
104             ;;
105         '-compiler-version' | '--compiler-version')
106             ${REAL_FORTRAN_COMPILER} --version
107             ;;
108         '-trace-call-location')
109             TRACE_CALL_LOCATION=1
110             # This should be list_add FFLAGS but it's not possible
111             # anymore: FFLAGS was already moved into CMDLINE above.
112             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
113             ;;
114         -o)
115             list_add CMDLINE "-o$1"
116             NEEDS_OUTPUT=0
117             shift
118             ;;
119         '-show'|'-compile-info'|'-link-info')
120             # Dry run displaying commands instead of executing them. Useful to cmake
121             Show=echo
122             ;;
123         *)
124             list_add CMDLINE "${ARG}"
125             ;;
126     esac
127 done
128
129 if [ $NEEDS_OUTPUT -ne 0 ]; then
130    list_add CMDLINE "-o${ORIGFILE}.o"
131 fi
132
133 list_add_not_empty CMDLINE ${INCLUDEARGS}
134 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
135 list_add_not_empty CMDLINE "${LINKARGS}"
136
137 eval $(list_get CMDLINE)
138 $Show "$@"