Logo AND Algorithmique Numérique Distribuée

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