Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / smpicc.in
1 #!/usr/bin/env sh
2
3 # Copyright (c) 2007-2023. 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="@GIT_VERSION@"
11
12 CC=@CMAKE_C_COMPILER@
13
14 @SMPITOOLS_SH@
15
16 list_set INCLUDEARGS @includeflag@
17 list_set CMAKE_LINKARGS "-L@libdir@"
18
19 # Don't use -Wl,-z-defs with Clang and address sanitizer
20 if [ "@CMAKE_C_COMPILER_ID@" = "Clang" ] && [ "@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@APPLE@" = "x1" ]; then
29     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
30        list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
31        list_add LINKARGS "-shared"
32     else
33        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
34     fi
35     if [ "x${SMPI_NO_UNDEFINED_CHECK}" = "x" ]; then
36       list_add LINKARGS "-lsimgrid" "-lm" ${LINKER_UNDEFINED_ERROR:+"-Wl,-undefined,error"}
37     fi
38 else
39     if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
40        list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h"
41        list_add LINKARGS "-shared"
42     else
43        echo "Warning: smpicc pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
44     fi
45     if [ "x${SMPI_NO_UNDEFINED_CHECK}" = "x" ]; then
46       list_add LINKARGS "-lsimgrid" "-lm" ${LINKER_UNDEFINED_ERROR:+"-Wl,-z,defs"}
47     fi
48 fi
49
50 list_set CMDARGS
51 while [ $# -gt 0 ]; do
52     ARG="$1"
53     shift
54     case "${ARG}" in
55         -c)
56             CMAKE_LINKARGS=""
57             LINKARGS=""
58             list_add CMDARGS "-c"
59             ;;
60         *.c)
61             SRCFILE="$(readlink -f "${ARG}" 2>/dev/null)"
62             if [ -z "$SRCFILE" ] ; then
63                 SRCFILE="$ARG"
64             fi
65             list_add CMDARGS "${SRCFILE}"
66             ;;
67         '-version' | '--version')
68             printf '%b\n' "$SIMGRID_VERSION"
69             exit 0
70             ;;
71         "-git-version" | "--git-version")
72             printf '%b\n' "$SIMGRID_GITHASH"
73             exit 0
74             ;;
75         '-trace-call-location')
76             list_add CMDARGS "-DTRACE_CALL_LOCATION"
77             ;;
78         '-compiler-version' | '--compiler-version')
79             ${CC} --version
80             ;;
81         '-show'|'-compile-info'|'-link-info')
82             # Dry run displaying commands instead of executing them. Useful to cmake
83             show=1
84             ;;
85          *)
86             list_add CMDARGS "${ARG}"
87             ;;
88     esac
89 done
90
91 list_add CMDARGS "-fPIC"
92
93 list_set CMDLINE "${CC}"
94 list_add_not_empty CMDLINE "${CFLAGS}"
95 list_add_not_empty CMDLINE "${INCLUDEARGS}"
96 list_add_not_empty CMDLINE "${CMAKE_LINKARGS}"
97 list_add_not_empty CMDLINE "${CMDARGS}"
98 list_add_not_empty CMDLINE "${LINKARGS}"
99
100 eval "$(list_get CMDLINE)"
101 if [ "x$VERBOSE" = x1 ] || [ "x$show" = x1 ] ; then
102   echo "$@"
103   [ "x$show" = x1 ] && exit 0
104 fi
105 "$@"