Logo AND Algorithmique Numérique Distribuée

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