Logo AND Algorithmique Numérique Distribuée

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