Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
disable on osx as -z is not supported there
[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 [ "@APPLE@" != "1" ]; then
23        list_add LINKARGS "-Wl,-z,defs"
24    fi 
25 else
26    echo "Warning: smpiff pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
27 fi
28 list_set TMPFILES
29 main_name=main
30
31 cleanup () {
32     eval $(list_get TMPFILES)
33     rm -f "$@"
34 }
35 trap 'cleanup' EXIT
36
37 filter_and_compile_f77() {
38     list_add TMPFILES "${TMPFILE}"
39     #replace "program main_name by subroutine user_main (and the end clause as well)"
40     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
41       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
42       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
43     fi
44     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}"
45     SRCFILE="${TMPFILE}"
46     list_add CMDLINE "${SRCFILE}"
47 }
48 filter_and_compile_f90() {
49     list_add TMPFILES "${TMPFILE}"
50     #replace "program main_name by subroutine user_main (and the end clause as well)"
51     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
52       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
53       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
54     fi
55     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}"
56     SRCFILE="${TMPFILE}"
57     list_add CMDLINE "${SRCFILE}"
58 }
59 TRACE_CALL_LOCATION=0
60 NEEDS_OUTPUT=1
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=1
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 if [ "x$VERBOSE" = x1 -o "x$show" = x1 ] ; then
139   echo "$@"
140   [ "x$show" = x1 ] && exit 0
141 fi
142 "$@"