Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
obey our coding standards and cosmetics
[simgrid.git] / src / smpi / smpicc.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2007-2018. 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 CC=@CMAKE_C_COMPILER@
13
14 INCLUDEARGS="@includeflag@"
15 CMAKE_LINKARGS="-L@libdir@"
16
17 @SMPITOOLS_SH@
18
19 list_set CFLAGS
20 list_set LINKARGS "-lm"
21 if [ "x@WIN32@" = "x1" ]; then
22     list_add CFLAGS "-include" "@includedir@/smpi/smpi_main.h"
23     list_add LINKARGS "@libdir@\libsimgrid.dll"
24 elif [ "x@APPLE@" = "x1" ]; then
25     list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
26     list_add CFLAGS "-fpic"
27     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
28        list_add LINKARGS "-shared"
29     else
30        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
31     fi
32     list_add LINKARGS "-lsimgrid" "-Wl,-undefined,error"
33 else
34     list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
35     list_add CFLAGS "-fpic"
36     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
37        list_add LINKARGS "-shared"
38     else
39        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
40     fi
41     list_add LINKARGS "-lsimgrid" "-Wl,-z,defs"
42 fi
43
44
45 list_set CMDARGS
46 while [ $# -gt 0 ]; do
47     ARG="$1"
48     shift
49     case "${ARG}" in
50         -c)
51             CMAKE_LINKARGS=""
52             LINKARGS=""
53             list_add CMDARGS "-c"
54             ;;
55         *.c)
56             SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
57             if [ -z "$SRCFILE" ] ; then
58                 SRCFILE="$ARG"
59             fi
60             list_add CMDARGS "${SRCFILE}"
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         '-trace-call-location')
71             list_add_not_empty CMDARGS "-DTRACE_CALL_LOCATION"
72             ;;
73         '-compiler-version' | '--compiler-version')
74             ${CC} --version
75             ;;
76         *)
77             list_add CMDARGS "${ARG}"
78             ;;
79     esac
80 done
81
82 list_set CMDLINE "${CC}"
83 list_add_not_empty CMDLINE "${CFLAGS}"
84 list_add_not_empty CMDLINE ${INCLUDEARGS}
85 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
86 list_add_not_empty CMDLINE "${CMDARGS}"
87 list_add_not_empty CMDLINE "${LINKARGS}"
88
89 eval $(list_get CMDLINE)
90 "$@"