Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8b63bee120e22cae06588fbed59697031fc55488
[simgrid.git] / src / smpi / smpiff.in
1 #! /bin/sh
2
3 # Copyright (c) 2012-2015. 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=@GFORTRAN_EXE@
13
14 INCLUDEARGS="@includeflag@"
15 CMAKE_LINKARGS="-L@libdir@"
16
17 @SMPITOOLS_SH@
18
19 list_set FFLAGS "-ff2c" "-fno-second-underscore" "-ffixed-line-length-none" "-cpp"
20 list_set LINKARGS "-lsimgrid" "-lm" "-lgfortran"
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     echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
34     echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
35     sed 's/[[:space:]]\{6\}[[:space:]]*\(end \)\{0,1\}program[[:space:]]*\([a-zA-Z0-9\-\_]*\)/      \1subroutine user_main /gI;s/[[:space:]]*use[[:space:]]*mpi/\include \"mpif\.h\" /gI' "${ARG}" >> "${TMPFILE}"
36     SRCFILE="${TMPFILE}"
37     list_add CMDLINE "${SRCFILE}"
38 }
39 NEEDS_OUTPUT=1
40
41 list_set CMDLINE "${F77}"
42 list_add_not_empty CMDLINE "${FFLAGS}"
43 while [ $# -gt 0 ]; do
44     ARG="$1"
45     shift
46     case "${ARG}" in
47         -c)
48             CMAKE_LINKARGS=""
49             LINKARGS=""
50             list_add CMDLINE "-c"
51             ;;
52         *.f)
53             TMPFILE=$(mymktemp "${ARG}" ".f")
54             ORIGFILE="${ARG%.f}"
55             filter_and_compile
56             ;;
57         *.F)
58             TMPFILE=$(mymktemp "${ARG}" ".F")
59             ORIGFILE="${ARG%.F}"
60             filter_and_compile
61             ;;
62         '-version' | '--version')
63             printf '%b\n' "$SIMGRID_VERSION"
64             exit 0
65             ;;
66         "-git-version" | "--git-version")
67             printf '%b\n' "$SIMGRID_GITHASH"
68             exit 0
69             ;;
70         '-compiler-version' | '--compiler-version')
71             ${F77} --version
72             ;;
73         -o)
74             NEEDS_OUTPUT=0
75             list_add CMDLINE "-o"   
76             ;;        
77         *)
78             list_add CMDLINE "${ARG}"
79             ;;
80     esac
81 done
82
83 if [ $NEEDS_OUTPUT -ne 0 ]; then
84    list_add CMDLINE "-o${ORIGFILE}.o"     
85 fi
86
87 list_add_not_empty CMDLINE ${INCLUDEARGS}
88 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
89 list_add_not_empty CMDLINE "${LINKARGS}"
90
91 eval $(list_get CMDLINE)
92 "$@"