Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finished = inactive
[simgrid.git] / src / smpi / smpiff.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2012-2020. 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    if [ "x${SMPI_NO_UNDEFINED_CHECK}" = "x" ]; then
23      if [ "x@APPLE@" != "x1" ]; then
24        list_add LINKARGS "-Wl,-z,defs"
25      else
26        list_add LINKARGS "-Wl,-undefined,error"
27      fi
28    fi
29 else
30    echo "Warning: smpiff pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
31 fi
32 list_set TMPFILES
33 main_name=main
34
35 cleanup () {
36     eval $(list_get TMPFILES)
37     rm -f "$@"
38 }
39 trap 'cleanup' EXIT
40
41 filter_and_compile_f77() {
42     list_add TMPFILES "${TMPFILE}"
43     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
44       #replace "program main_name by subroutine user_main (and the end clause as well)"
45       if [ $TRACE_CALL_LOCATION -gt 0 ]; then
46         echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
47         echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
48       fi
49       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}"
50       SRCFILE="${TMPFILE}"
51     else
52       SRCFILE="${ARG}"
53     fi
54     list_add CMDLINE "${SRCFILE}"
55 }
56 filter_and_compile_f90() {
57     list_add TMPFILES "${TMPFILE}"
58     #replace "program main_name by subroutine user_main (and the end clause as well)"
59     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
60       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
61       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
62     fi
63     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}"
64     SRCFILE="${TMPFILE}"
65     list_add CMDLINE "${SRCFILE}"
66 }
67 TRACE_CALL_LOCATION=0
68 NEEDS_OUTPUT=1
69
70 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
71 list_add_not_empty CMDLINE "${FFLAGS}"
72 while [ $# -gt 0 ]; do
73     ARG="$1"
74     shift
75     case "${ARG}" in
76         -c)
77             CMAKE_LINKARGS=""
78             LINKARGS=""
79             list_add CMDLINE "-c"
80             ;;
81         *.f)
82             FILENAME=`basename ${ARG}`
83             TMPFILE=$(mymktemp "${ARG}" ".f")
84             ORIGFILE="${FILENAME%.f}"
85             filter_and_compile_f77
86             ;;
87         *.F)$
88             FILENAME=`basename ${ARG}`
89             TMPFILE=$(mymktemp "${ARG}" ".F")
90             ORIGFILE="${FILENAME%.F}"
91             filter_and_compile_f77
92             ;;
93         *.f90)
94             FILENAME=`basename ${ARG}`
95             TMPFILE=$(mymktemp "${ARG}" ".f90")
96             ORIGFILE="${FILENAME%.f90}"
97             filter_and_compile_f90
98             ;;
99         *.F90)$
100             FILENAME=`basename ${ARG}`
101             TMPFILE=$(mymktemp "${ARG}" ".F90")
102             ORIGFILE="${FILENAME%.F90}"
103             filter_and_compile_f90
104             ;;
105         '-version' | '--version')
106             printf '%b\n' "$SIMGRID_VERSION"
107             exit 0
108             ;;
109         "-git-version" | "--git-version")
110             printf '%b\n' "$SIMGRID_GITHASH"
111             exit 0
112             ;;
113         '-compiler-version' | '--compiler-version')
114             ${REAL_FORTRAN_COMPILER} --version
115             ;;
116         '-trace-call-location')
117             TRACE_CALL_LOCATION=1
118             # This should be list_add FFLAGS but it's not possible
119             # anymore: FFLAGS was already moved into CMDLINE above.
120             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
121             ;;
122         -o)
123             list_add CMDLINE "-o$1"
124             NEEDS_OUTPUT=0
125             shift
126             ;;
127         '-show'|'-compile-info'|'-link-info')
128             # Dry run displaying commands instead of executing them. Useful to cmake
129             show=1
130             ;;
131         *)
132             list_add CMDLINE "${ARG}"
133             ;;
134     esac
135 done
136
137 if [ $NEEDS_OUTPUT -ne 0 ]; then
138    list_add CMDLINE "-o${ORIGFILE}.o"
139 fi
140
141 list_add_not_empty CMDLINE ${INCLUDEARGS}
142 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
143 list_add_not_empty CMDLINE "${LINKARGS}"
144
145 eval $(list_get CMDLINE)
146 if [ "x$VERBOSE" = x1 -o "x$show" = x1 ] ; then
147   echo "$@"
148   [ "x$show" = x1 ] && exit 0
149 fi
150 "$@"