Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ac32b8d0efae6a4cd8c02f6549994775da8ef908
[simgrid.git] / src / smpi / smpicc.in
1 #!/bin/bash
2 #FIXME: .. paths...
3 prefix="@prefix@"
4 exec_prefix="@exec_prefix@"
5
6 CC="gcc"
7
8 SEED="221238"
9
10 TMPDIR="$(mktemp -d tmpXXXXXXX)"
11
12 function modsource {
13   SOURCE="$1"
14   SOURCEFILE="$(basename ${SOURCE})"
15   SOURCEDIR="${SOURCE%${SOURCEFILE}}"
16   if [ -n "${SOURCEDIR}" ]; then
17     mkdir -p ${TMPDIR}${SOURCEDIR}
18   fi
19   TMPSOURCE="${TMPDIR}${SOURCE}"
20   cat > ${TMPSOURCE} <<HEADER
21 #define SEED ${SEED}
22 #include "smpi/smpi.h"
23 #include "xbt/sysdep.h"
24 #include "xbt/log.h"
25 #include "xbt/asserts.h"
26 #define sleep(x) smpi_sleep(x)
27 #define gettimeofday(x, y) smpi_gettimeofday(x, y)
28 int smpi_run_simulation(int *argc, char **argv);
29 HEADER
30   # very simplistic transform, will probably want full parser for next version
31   grep -v "mpi.h" < ${SOURCE} | perl -pe 's/main/smpi_simulated_main/;' >> ${TMPSOURCE}
32   grep -q "smpi_simulated_main" ${TMPSOURCE}
33   if [ $? -eq 0 ]; then
34     cat >> ${TMPSOURCE} <<FOOTER
35 int main(int argc, char **argv) {
36     return smpi_run_simulation(&argc, argv);
37 }
38 FOOTER
39   fi
40 }
41
42 INCLUDEARGS="-I @top_srcdir@/include "
43 LINKARGS="-L@top_builddir@/src/.libs -L@libdir@ -lsimgrid -lsmpi "
44
45 CMDLINE=""
46 while [ -n "$1" ]; do
47   ARG="$1"
48   shift
49   if [ "${ARG}" = "-c" ]; then
50       LINKARGS=""
51       CMDLINE="${CMDLINE} -c "
52   elif [ "${ARG%.c}" != "${ARG}" ]; then
53     INCLUDEARGS="${INCLUDEARGS} -I . -I .. -I ../include -I @includedir@ "
54     SRCFILE="$(realpath ${ARG})"
55     modsource ${SRCFILE}
56     CMDLINE="${CMDLINE} ${TMPDIR}${SRCFILE} "
57   else
58     CMDLINE="${CMDLINE} ${ARG} "
59   fi
60 done
61
62 CMDLINE="${CC} ${INCLUDEARGS} ${CFLAGS} ${CMDLINE} ${LINKARGS}"
63
64 #echo "${CMDLINE}"
65 ${CMDLINE}
66 rm -rf ${TMPDIR}