Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3cc7a6a44e0925eeaeeb0b063e6a632b5d6c064a
[simgrid.git] / src / smpi / smpicc.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2007-2019. 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 # Don't use -Wl,-z-defs with Clang and address sanitizer
20 if [ "@CMAKE_C_COMPILER_ID@" = "Clang" -a "@HAVE_SANITIZER_ADDRESS@" = "TRUE" ]; then
21     LINKER_UNDEFINED_ERROR=""
22 else
23     LINKER_UNDEFINED_ERROR="1"
24 fi
25
26 list_set CFLAGS
27 list_set LINKARGS "-lm"
28 if [ "x@WIN32@" = "x1" ]; then
29     list_add CFLAGS "-include" "@includedir@/smpi/smpi_main.h"
30     list_add LINKARGS "@libdir@\libsimgrid.dll"
31 elif [ "x@APPLE@" = "x1" ]; then
32     list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
33     list_add CFLAGS "-fpic"
34     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
35        list_add LINKARGS "-shared"
36     else
37        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
38     fi
39     list_add LINKARGS "-lsimgrid" ${LINKER_UNDEFINED_ERROR:+"-Wl,-undefined,error"}
40 else
41     list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
42     list_add CFLAGS "-fpic"
43     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
44        list_add LINKARGS "-shared"
45     else
46        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
47     fi
48     list_add LINKARGS "-lsimgrid" ${LINKER_UNDEFINED_ERROR:+"-Wl,-z,defs"}
49 fi
50
51
52 list_set CMDARGS
53 while [ $# -gt 0 ]; do
54     ARG="$1"
55     shift
56     case "${ARG}" in
57         -c)
58             CMAKE_LINKARGS=""
59             LINKARGS=""
60             list_add CMDARGS "-c"
61             ;;
62         *.c)
63             SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
64             if [ -z "$SRCFILE" ] ; then
65                 SRCFILE="$ARG"
66             fi
67             list_add CMDARGS "${SRCFILE}"
68             ;;
69         '-version' | '--version')
70             printf '%b\n' "$SIMGRID_VERSION"
71             exit 0
72             ;;
73         "-git-version" | "--git-version")
74             printf '%b\n' "$SIMGRID_GITHASH"
75             exit 0
76             ;;
77         '-trace-call-location')
78             list_add_not_empty CMDARGS "-DTRACE_CALL_LOCATION"
79             ;;
80         '-compiler-version' | '--compiler-version')
81             ${CC} --version
82             ;;
83         *)
84             list_add CMDARGS "${ARG}"
85             ;;
86     esac
87 done
88
89 list_set CMDLINE "${CC}"
90 list_add_not_empty CMDLINE "${CFLAGS}"
91 list_add_not_empty CMDLINE ${INCLUDEARGS}
92 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
93 list_add_not_empty CMDLINE "${CMDARGS}"
94 list_add_not_empty CMDLINE "${LINKARGS}"
95
96 eval $(list_get CMDLINE)
97 "$@"