Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpicxx: obey the VERBOSE environment variable and display what we do
[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 @SMPI_C_FLAGS@
27 list_add LINKARGS
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 # By default, we execute the commands instead of only showing them to cmake
52 Show=
53
54 list_set CMDARGS
55 while [ $# -gt 0 ]; do
56     ARG="$1"
57     shift
58     case "${ARG}" in
59         -c)
60             CMAKE_LINKARGS=""
61             LINKARGS=""
62             list_add CMDARGS "-c"
63             ;;
64         *.c)
65             SRCFILE="$(readlink -f ${ARG} 2>/dev/null)"
66             if [ -z "$SRCFILE" ] ; then
67                 SRCFILE="$ARG"
68             fi
69             list_add CMDARGS "${SRCFILE}"
70             ;;
71         '-version' | '--version')
72             printf '%b\n' "$SIMGRID_VERSION"
73             exit 0
74             ;;
75         "-git-version" | "--git-version")
76             printf '%b\n' "$SIMGRID_GITHASH"
77             exit 0
78             ;;
79         '-trace-call-location')
80             list_add_not_empty CMDARGS "-DTRACE_CALL_LOCATION"
81             ;;
82         '-compiler-version' | '--compiler-version')
83             ${CC} --version
84             ;;
85         '-show'|'-compile-info'|'-link-info')
86             # Dry run displaying commands instead of executing them. Useful to cmake
87             Show=echo
88             ;;
89          *)
90             list_add CMDARGS "${ARG}"
91             ;;
92     esac
93 done
94
95 list_set CMDLINE "${CC}"
96 list_add_not_empty CMDLINE "${CFLAGS}"
97 list_add_not_empty CMDLINE ${INCLUDEARGS}
98 list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
99 list_add_not_empty CMDLINE "${CMDARGS}"
100 list_add_not_empty CMDLINE "${LINKARGS}"
101
102 eval $(list_get CMDLINE)
103 $Show "$@"