Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Added doc block for smpi_backup_global_memory_segment()
[simgrid.git] / src / smpi / smpiff.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 F77=@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     if [ $TRACE_CALL_LOCATION -gt 0 ]; then
34       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
35     echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
36     fi
37     sed 's/[[:space:]]\{6\}[[:space:]]*\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/      \1subroutine user_main /g;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" >> "${TMPFILE}"
38     SRCFILE="${TMPFILE}"
39     list_add CMDLINE "${SRCFILE}"
40 }
41 TRACE_CALL_LOCATION=0
42 NEEDS_OUTPUT=1
43
44 list_set CMDLINE "${F77}"
45 list_add_not_empty CMDLINE "${FFLAGS}"
46 while [ $# -gt 0 ]; do
47     ARG="$1"
48     shift
49     case "${ARG}" in
50         -c)
51             CMAKE_LINKARGS=""
52             LINKARGS=""
53             list_add CMDLINE "-c"
54             ;;
55         *.f)
56             TMPFILE=$(mymktemp "${ARG}" ".f")
57             ORIGFILE="${ARG%.f}"
58             filter_and_compile
59             ;;
60         *.F)
61             TMPFILE=$(mymktemp "${ARG}" ".F")
62             ORIGFILE="${ARG%.F}"
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             ${F77} --version
75             ;;
76         '-trace-call-location')
77             TRACE_CALL_LOCATION=1
78             # This should be list_add FFLAGS but it's not possible
79             # anymore: FFLAGS was already moved into CMDLINE above.
80             list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
81             ;;
82         -o)
83             NEEDS_OUTPUT=0
84             list_add CMDLINE "-o$1"
85             shift
86             ;;        
87         *)
88             list_add CMDLINE "${ARG}"
89             ;;
90     esac
91 done
92
93 if [ $NEEDS_OUTPUT -ne 0 ]; then
94    list_add CMDLINE "-o${ORIGFILE}.o"     
95 fi
96
97 list_add_not_empty CMDLINE ${INCLUDEARGS}
98 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
99 list_add_not_empty CMDLINE "${LINKARGS}"
100
101 eval $(list_get CMDLINE)
102 "$@"