Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Actor: make the refcount observable, and improve debug messages
[simgrid.git] / src / smpi / smpif90.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: smpif90 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() {
35     list_add TMPFILES "${TMPFILE}"
36     #replace "program main_name by subroutine user_main (and the end clause as well)"
37     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}"
38     SRCFILE="${TMPFILE}"
39     list_add CMDLINE "${SRCFILE}"
40 }
41
42 NEEDS_OUTPUT=1
43
44 # By default, we execute the commands instead of only showing them to cmake
45 Show=
46
47 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
48 list_add_not_empty CMDLINE "${FFLAGS}"
49 while [ $# -gt 0 ]; do
50     ARG="$1"
51     shift
52     case "${ARG}" in
53         -c)
54             CMAKE_LINKARGS=""
55             LINKARGS=""
56             list_add CMDLINE "-c"
57             ;;
58         *.f90)
59             FILENAME=`basename ${ARG}`
60             TMPFILE=$(mymktemp "${ARG}" ".f90")
61             ORIGFILE="${FILENAME%.f90}"
62             filter_and_compile
63             ;;
64         *.F90)
65             FILENAME=`basename ${ARG}`
66             TMPFILE=$(mymktemp "${ARG}" ".F90")
67             ORIGFILE="${FILENAME%.F90}"
68             filter_and_compile
69             ;;
70         '-version' | '--version')
71             printf '%b\n' "$SIMGRID_VERSION"
72             exit 0
73             ;;
74         "-git-version" | "--git-version")
75             printf '%b\n' "$SIMGRID_GITHASH"
76             exit 0
77             ;;
78         '-compiler-version' | '--compiler-version')
79             ${REAL_FORTRAN_COMPILER} --version
80             ;;
81         -o)
82             list_add CMDLINE "-o$1"
83             NEEDS_OUTPUT=0
84             shift
85             ;;
86         '-show'|'-compile-info'|'-link-info')
87             # Dry run displaying commands instead of executing them. Useful to cmake
88             Show=echo
89             ;;
90         *)
91             list_add CMDLINE "${ARG}"
92             ;;
93     esac
94 done
95
96 if [ $NEEDS_OUTPUT -ne 0 ]; then
97    list_add CMDLINE "-o${ORIGFILE}.o"
98 fi
99
100 list_add_not_empty CMDLINE ${INCLUDEARGS}
101 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
102 list_add_not_empty CMDLINE "${LINKARGS}"
103
104 eval $(list_get CMDLINE)
105 $Show "$@"