-
Notifications
You must be signed in to change notification settings - Fork 128
/
cc.in
151 lines (133 loc) · 4.7 KB
/
cc.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
#
# Copyright (c) 2015 Martin Lucina. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# cc.in/c++.in: rumprun backend C/C++ compiler wrapper script
#
die()
{
exit 1
}
PROGNAME=${0##*/}
# Determine if we're being run as C or C++.
case ${PROGNAME} in
*-gcc|*-clang)
CC="!LIBEXEC_CC!"
CFLAGS="!CFLAGS!"
EXTRALIBS=
;;
*-g++|*-clang++)
CC="!LIBEXEC_CXX!"
CFLAGS="!CXXFLAGS!"
EXTRALIBS="-lc++ -lunwind"
;;
*)
echo "${PROGNAME}: internal error, unknown invocation"
exit 1
;;
esac
PRMETA="$(dirname ${CC})/brprintmetainfo"
# Figure out what we're supposed to be doing. Assume we're fermenting
# and switch to compilation if -c / -S / -E was passed.
MODE=ferment
WANTARG=
# OUTFILE gets set to whatever is specified with -o (the real output file).
OUTFILE=a.out
for arg in "$@"; do
[ "${arg}" = "-c" ] && MODE=compile
[ "${arg}" = "-S" ] && MODE=compile
[ "${arg}" = "-E" ] && MODE=compile
[ "${arg}" = "-o" ] && WANTARG=yes && continue
[ -n "${WANTARG}" ] && OUTFILE=${arg} && WANTARG=
# If either of these is present on the command line, the
# behaviour of gcc seems to be that they silently override
# all other flags
[ "${arg}" = "-dumpmachine" ] && { MODE=dumpmachine; break; }
[ "${arg}" = "-dumpspecs" ] && { MODE=dumpspecs; break; }
# even if the backing compiler supports multiarch, we do not
[ "${arg}" = "-print-multiarch" ] && \
{ echo "${PROGNAME}: unrecognized option '-print-multiarch'" 2>&1;
exit 1; }
done
case ${MODE} in
compile)
exec ${CC} ${CFLAGS} -no-integrated-cpp \
--sysroot !DESTDIR!/rumprun-!MACHINE_GNU_ARCH! \
-specs=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-compile_or_ferment \
"$@" ${EXTRALIBS}
;;
ferment)
meta1="$(${PRMETA} "${OUTFILE}" 2>/dev/null)"
# Link the real (from user's PoV) output file as a relocatable object,
# with no rump components. '-u main' is necessary to pull in main if the
# user is linking it in from a library.
${CC} ${CFLAGS} -no-integrated-cpp \
--sysroot !DESTDIR!/rumprun-!MACHINE_GNU_ARCH! \
-specs=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-compile_or_ferment \
!EXTRACCFLAGS! -Wl,-r -Wl,-u,main \
"$@" !DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/share/!TOOLTUPLE!-recipe.s ${EXTRALIBS} || die
# If the presumed output file did not change, and the compiler
# did not flag an error, assume this is a command which does not
# generate output (e.g. cc -dumpspecs) and exit gracefully
meta2="$(${PRMETA} "${OUTFILE}" 2>/dev/null)"
[ "${meta1}" != "${meta2}" ] || exit 0
if [ "${RUMPRUN_STUBLINK}" = succeed ]; then
exec 3>&1 2>&1
echo '!!!'
echo '!!! WARNING: $RUMPRUN_STUBLINK may be desupported without'
echo '!!! warning in the future. Do not rely on it'
echo '!!! continuing to be available.'
echo '!!!'
exec 1>&3 3>&-
fi
# Try a stub link with minimal rump components. If that fails then stop.
${CC} ${CFLAGS} -no-integrated-cpp \
--sysroot !DESTDIR!/rumprun-!MACHINE_GNU_ARCH! \
-specs=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-stub \
${OUTFILE} -o /dev/null
if [ $? -ne 0 ]; then
if [ "${RUMPRUN_STUBLINK}" = "succeed" ]; then
echo "${PROGNAME}: warning: stub link failed" 1>&2
else
[ -f "${OUTFILE}" ] && rm -f ${OUTFILE}
die
fi
fi
# Some build systems insist that the output looks like an executable.
chmod +x ${OUTFILE}
;;
dumpmachine)
echo !TOOLTUPLE!
;;
dumpspecs)
${CC} -dumpspecs
cat !DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-compile_or_ferment
;;
*)
echo "${PROGNAME}: internal error, unknown mode"
exit 1
;;
esac
exit 0