Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpicc/smpirun no longer require special envirnment variables. also they're now
[simgrid.git] / src / smpi / smpicc
1 #!/bin/sh
2 #FIXME: .. paths...
3 prefix="/home/marklee/progs/pkgs/simgrid-nifty"
4 exec_prefix="${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.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 HEADER
29   # very simplistic transform, will probably want full parser for next version
30   grep -v "mpi.h" < ${SOURCE} | perl -pe 's/main/smpi_simulated_main/;' >> ${TMPSOURCE}
31   grep -q "smpi_simulated_main" ${TMPSOURCE}
32   if [ $? -eq 0 ]; then
33     cat >> ${TMPSOURCE} <<FOOTER
34 int main(int argc, char **argv) {
35     return smpi_run_simulation(&argc, argv);
36 }
37 FOOTER
38   fi
39 }
40
41 INCLUDEARGS=""
42 LINKARGS="-L${exec_prefix}/lib -lsimgrid -lsmpi "
43
44 CMDLINE=""
45 while [ -n "$1" ]; do
46   ARG="$1"
47   shift
48   if [ "${ARG}" = "-c" ]; then
49       LINKARGS=""
50       CMDLINE="${CMDLINE} -c "
51   elif [ "${ARG%.c}" != "${ARG}" ]; then
52     INCLUDEARGS="-I . -I .. -I ../include -I ${prefix}/include "
53     SRCFILE="$(realpath ${ARG})"
54     modsource ${SRCFILE}
55     CMDLINE="${CMDLINE} ${TMPDIR}${SRCFILE} "
56   else
57     CMDLINE="${CMDLINE} ${ARG} "
58   fi
59 done
60
61 CMDLINE="${CC} ${INCLUDEARGS} ${CMDLINE} ${LINKARGS}"
62
63 #echo "${CMDLINE}"
64 ${CMDLINE}
65 rm -rf ${TMPDIR}