Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
when SMPI_PRETEND_CC is set, don't replace program xx by subroutine xx, we want to...
[simgrid.git] / src / smpi / smpif90.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: smpif90 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() {
42     list_add TMPFILES "${TMPFILE}"
43     #replace "program main_name by subroutine user_main (and the end clause as well)"
44     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
45       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}"
46       SRCFILE="${TMPFILE}"
47     else
48       SRCFILE="${ARG}"
49     fi
50     SRCFILE="${TMPFILE}"
51     list_add CMDLINE "${SRCFILE}"
52 }
53
54 NEEDS_OUTPUT=1
55
56 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
57 list_add_not_empty CMDLINE "${FFLAGS}"
58 while [ $# -gt 0 ]; do
59     ARG="$1"
60     shift
61     case "${ARG}" in
62         -c)
63             CMAKE_LINKARGS=""
64             LINKARGS=""
65             list_add CMDLINE "-c"
66             ;;
67         *.f90)
68             FILENAME=`basename ${ARG}`
69             TMPFILE=$(mymktemp "${ARG}" ".f90")
70             ORIGFILE="${FILENAME%.f90}"
71             filter_and_compile
72             ;;
73         *.F90)
74             FILENAME=`basename ${ARG}`
75             TMPFILE=$(mymktemp "${ARG}" ".F90")
76             ORIGFILE="${FILENAME%.F90}"
77             filter_and_compile
78             ;;
79         '-version' | '--version')
80             printf '%b\n' "$SIMGRID_VERSION"
81             exit 0
82             ;;
83         "-git-version" | "--git-version")
84             printf '%b\n' "$SIMGRID_GITHASH"
85             exit 0
86             ;;
87         '-compiler-version' | '--compiler-version')
88             ${REAL_FORTRAN_COMPILER} --version
89             ;;
90         -o)
91             list_add CMDLINE "-o$1"
92             NEEDS_OUTPUT=0
93             shift
94             ;;
95         '-show'|'-compile-info'|'-link-info')
96             # Dry run displaying commands instead of executing them. Useful to cmake
97             show=1
98             ;;
99         *)
100             list_add CMDLINE "${ARG}"
101             ;;
102     esac
103 done
104
105 if [ $NEEDS_OUTPUT -ne 0 ]; then
106    list_add CMDLINE "-o${ORIGFILE}.o"
107 fi
108
109 list_add_not_empty CMDLINE ${INCLUDEARGS}
110 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
111 list_add_not_empty CMDLINE "${LINKARGS}"
112
113 eval $(list_get CMDLINE)
114 if [ "x$VERBOSE" = x1 -o "x$show" = x1 ] ; then
115   echo "$@"
116   [ "x$show" = x1 ] && exit 0
117 fi
118 "$@"