Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2100adb272eab97e5899cb0aaf5edc1a78c01a80
[simgrid.git] / src / smpi / smpif90.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2012-2018. 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     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
20        list_add LINKARGS "-shared"
21     fi
22 list_set LINKARGS "-lsimgrid" @SMPI_Fortran_LIBS@ "-lm"
23 list_set TMPFILES
24 main_name=main
25
26 cleanup () {
27     eval $(list_get TMPFILES)
28     rm -f "$@"
29 }
30 trap 'cleanup' EXIT
31
32 filter_and_compile() {
33     list_add TMPFILES "${TMPFILE}"
34     #replace "program main_name by subroutine user\_main (and the end clause as well)"
35     sed 's/[[:space:]]*[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/ subroutine user\_main /g' "${ARG}" > "${TMPFILE}"
36     SRCFILE="${TMPFILE}"
37     list_add CMDLINE "${SRCFILE}"
38 }
39
40 NEEDS_OUTPUT=1
41
42 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
43 list_add_not_empty CMDLINE "${FFLAGS}"
44 while [ $# -gt 0 ]; do
45     ARG="$1"
46     shift
47     case "${ARG}" in
48         -c)
49             CMAKE_LINKARGS=""
50             LINKARGS=""
51             list_add CMDLINE "-c"
52             ;;
53         *.f90)
54             FILENAME=`basename ${ARG}`
55             TMPFILE=$(mymktemp "${ARG}" ".f90")
56             ORIGFILE="${FILENAME%.f90}"
57             filter_and_compile
58             ;;
59         *.F90)
60             FILENAME=`basename ${ARG}`
61             TMPFILE=$(mymktemp "${ARG}" ".F90")
62             ORIGFILE="${FILENAME%.F90}"
63             filter_and_compile
64             ;;
65         '-version' | '--version')
66             printf '%b\n' "$SIMGRID_VERSION"
67             exit 0
68             ;;
69         "-git-version" | "--git-version")
70             printf '%b\n' "$SIMGRID_GITHASH"
71             exit 0
72             ;;
73         '-compiler-version' | '--compiler-version')
74             ${REAL_FORTRAN_COMPILER} --version
75             ;;
76         -o)
77             list_add CMDLINE "-o$1"
78             NEEDS_OUTPUT=0
79             shift
80             ;;
81         *)
82             list_add CMDLINE "${ARG}"
83             ;;
84     esac
85 done
86
87 if [ $NEEDS_OUTPUT -ne 0 ]; then
88    list_add CMDLINE "-o${ORIGFILE}.o"
89 fi
90
91 list_add_not_empty CMDLINE ${INCLUDEARGS}
92 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
93 list_add_not_empty CMDLINE "${LINKARGS}"
94
95 eval $(list_get CMDLINE)
96 "$@"