Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add version notes to smpiXXX scripts
[simgrid.git] / src / smpi / smpiff.in
1 #! /bin/sh
2
3 # Copyright (c) 2010-2014. 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
11 prefix="@exec_prefix@"
12 smpicc="$prefix/bin/smpicc"
13 smpif2c="$prefix/bin/smpif2c"
14
15 @SMPITOOLS_SH@
16
17 list_set ARGS "-DMAIN__=user_main" "-Diargc_=smpi_process_argc" "-Dgetarg_=smpi_process_getarg"
18 list_set LINKARGS "-L@F2C_LIBRARY_PATH@" "-lf2c" "-lm"
19 list_set SRCFILES
20
21 while [ $# -gt 0 ]; do
22     ARG="$1"
23     shift
24     case "${ARG}" in
25         *.f)
26             SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
27             if [ -z "$SRCFILE" ] ; then
28                 SRCFILE="$ARG"
29             fi
30             list_add SRCFILES "${SRCFILE}"
31             ;;
32         '-version' | '--version' | '-v')
33             # -e is not recognised by MS-DOS...
34             echo -e $SIMGRID_VERSION
35             exit 0
36             ;;           
37         *)
38             if [ "${ARG}" = "-c" ]; then
39                 LINKARGS=""
40             fi
41             list_add ARGS "${ARG}"
42             ;;
43     esac
44 done
45 list_add_not_empty ARGS "${LINKARGS}"
46
47 build () {
48     local SRCFILE
49     SRCFILE="$1"
50     TMPFILE=$(mymktemp "${SRCFILE}" ".f")
51     CFILE="${TMPFILE%.f}.c"
52
53     eval $(list_get ARGS)
54
55     cp "${SRCFILE}" "${TMPFILE}" \
56         && "$smpif2c" "${TMPFILE}" \
57         && "$smpicc" "$@" "${CFILE}" \
58         && rm -f "${CFILE}" \
59         && rm -f "${TMPFILE}" \
60         || exit $?
61
62     # When the file is compiled with "-c" and no output file is specified with
63     # "-o", rename the output.  FIXME: do it properly.
64     if [ -f "${CFILE%.c}.o" ]; then
65         mv "${CFILE%.c}.o" "${SRCFILE%.f}.o"
66     fi
67 }
68
69 if [ -n "${SRCFILES}" ]; then
70     eval $(list_get SRCFILES)
71     for SRCFILE in "$@"; do
72         build "$SRCFILE"
73     done
74 else
75     eval $(list_get ARGS)
76     "$smpicc" "$@"
77 fi