Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branches 'master' and 'master' of github.com:simgrid/simgrid
[simgrid.git] / src / smpi / smpif90.in
1 #! /bin/sh
2
3 # Copyright (c) 2012-2017. The SimGrid Team.
4 # All rights reserved.
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
8
9 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
10 SIMGRID_GITHASH="@SIMGRID_GITHASH@"
11
12 F90=@SMPI_Fortran_COMPILER@
13
14 INCLUDEARGS="@includeflag@"
15 CMAKE_LINKARGS="-L@libdir@"
16
17 @SMPITOOLS_SH@
18
19 list_set FFLAGS @SMPI_Fortran_FLAGS@
20 list_set LINKARGS "-shared" "-lsimgrid" @SMPI_Fortran_LIBS@ "-lm"
21 list_set TMPFILES
22 main_name=main
23
24 cleanup () {
25     eval $(list_get TMPFILES)
26     rm -f "$@"
27 }
28 trap 'cleanup' EXIT
29
30 filter_and_compile() {
31     list_add TMPFILES "${TMPFILE}"
32 #replace "program main_name by subroutine user\_main (and the end clause as well)"
33     sed 's/[[:space:]]*[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/ subroutine user\_main /g;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" > "${TMPFILE}"
34     SRCFILE="${TMPFILE}"
35     list_add CMDLINE "${SRCFILE}"
36 }
37
38 list_set CMDLINE "${F90}"
39 list_add_not_empty CMDLINE "${FFLAGS}"
40 while [ $# -gt 0 ]; do
41     ARG="$1"
42     shift
43     case "${ARG}" in
44         -c)
45             CMAKE_LINKARGS=""
46             LINKARGS=""
47             list_add CMDLINE "-c"
48             ;;
49         *.f90)
50             TMPFILE=$(mymktemp "${ARG}" ".f90")
51             filter_and_compile
52             ;;
53         *.F90)
54             TMPFILE=$(mymktemp "${ARG}" ".F90")
55             filter_and_compile
56             ;;
57         '-version' | '--version')
58             printf '%b\n' "$SIMGRID_VERSION"
59             exit 0
60             ;;
61         "-git-version" | "--git-version")
62             printf '%b\n' "$SIMGRID_GITHASH"
63             exit 0
64             ;;
65         '-compiler-version' | '--compiler-version')
66             ${F90} --version
67             ;;
68         -o)
69             list_add CMDLINE "-o$1"
70             shift
71             ;;
72         *)
73             list_add CMDLINE "${ARG}"
74             ;;
75     esac
76 done
77
78 list_add_not_empty CMDLINE ${INCLUDEARGS}
79 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
80 list_add_not_empty CMDLINE "${LINKARGS}"
81
82 eval $(list_get CMDLINE)
83 "$@"