@@ -75,10 +75,12 @@ elif [ ! -d "$TMPDIR" ]; then
75
75
fi
76
76
fi
77
77
78
+ X=
78
79
OPT=
79
80
ARGS=
80
81
FLAGS=
81
82
OUTPUT=
83
+ NEED_X=
82
84
MDFLAG=0
83
85
MCOSMO=0
84
86
INTENT=ld
@@ -94,8 +96,7 @@ NEED_DEPENDENCY_OUTPUT=
94
96
for x; do
95
97
if [ x" $x " != x" ${x#* } " ]; then
96
98
fatal_error " arguments containing spaces unsupported: $x "
97
- fi
98
- if [ -n " $NEED_OUTPUT " ]; then
99
+ elif [ -n " $NEED_OUTPUT " ]; then
99
100
NEED_OUTPUT=
100
101
OUTPUT=$x
101
102
continue
@@ -109,6 +110,10 @@ for x; do
109
110
elif [ -n " $NEED_EQUAL " ]; then
110
111
x=" ${NEED_EQUAL} =${x} "
111
112
NEED_EQUAL=
113
+ elif [ -n " $NEED_X " ]; then
114
+ NEED_X=
115
+ X=$x
116
+ x=" -x${x} "
112
117
elif [ x" $x " = x" -" ] || # is alias for stdin
113
118
[ x" $x " = x" ${x# -* } " ]; then # !startswith(x, "-")
114
119
if [ x" $x " != x" ${x% .s} " ] ||
@@ -142,6 +147,7 @@ for x; do
142
147
if [ x" $INTENT " != x" cpp" ]; then
143
148
INTENT=cc
144
149
fi
150
+ continue
145
151
elif [ x" $x " = x" -E" ] ||
146
152
[ x" $x " = x" -M" ] ||
147
153
[ x" $x " = x" -MM" ]; then
@@ -214,8 +220,12 @@ for x; do
214
220
elif [ x" $x " = x" -dumpversion" ]; then
215
221
echo $GCC_VERSION
216
222
Exit 0
217
- elif [ x" $x " = x" -x" ] ||
218
- [ x" $x " = x" -e" ] ||
223
+ elif [ x" $x " = x" -x" ]; then
224
+ NEED_X=1
225
+ continue
226
+ elif [ x" $x " != x" ${x# -x} " ]; then
227
+ X=${x# -x}
228
+ elif [ x" $x " = x" -e" ] ||
219
229
[ x" $x " = x" -z" ] ||
220
230
[ x" $x " = x" -T" ] ||
221
231
[ x" $x " = x" -L" ] ||
@@ -240,12 +250,37 @@ for x; do
240
250
ARGS=" $ARGS $x "
241
251
done
242
252
253
+ # precompiled header mode
254
+ if [ $INTENT != cpp ]; then
255
+ if [ -z " $X " ]; then
256
+ ONLY_HEADER_INPUTS=1
257
+ for x in $ARGS ; do
258
+ if [ x" $x " = x" ${x# -* } " ] && # !startswith(x, "-")
259
+ [ x" $x " = x" ${x% .h} " ] && # !endswith(x, ".h")
260
+ [ x" $x " = x" ${x% .hpp} " ]; then # !endswith(x, ".hpp")
261
+ ONLY_HEADER_INPUTS=0
262
+ break
263
+ fi
264
+ done
265
+ if [ $ONLY_HEADER_INPUTS -eq 1 ]; then
266
+ INTENT=gch
267
+ fi
268
+ elif [ x" $X " = x" c-header" ] ||
269
+ [ x" $X " = x" c++-header" ]; then
270
+ INTENT=gch
271
+ fi
272
+ fi
273
+ if [ $INTENT = gch ]; then
274
+ fatal_error " precompiled headers only supported with ARCH-unknown-cosmo-cc compilers"
275
+ fi
276
+
277
+ # check for incorrect usage
243
278
if [ $INPUT_FILE_COUNT -eq 0 ]; then
244
279
fatal_error " no input files"
245
- elif [ -z " $INPUT " ] &&
246
- [ $INTENT != ld ] &&
247
- [ $INPUT_FILE_COUNT -gt 1 ] ; then
248
- fatal_error " cannot specify '-o' with '-c', or '-E' with multiple files "
280
+ elif [ -n " $OUTPUT " ] && [ $INPUT_FILE_COUNT -gt 1 ] ; then
281
+ if [ $INTENT = cc ] || [ $INTENT = cpp ] ; then
282
+ fatal_error " cannot specify '-o' with '-c' or '-E' with multiple files "
283
+ fi
249
284
fi
250
285
251
286
PLATFORM=" -D__COSMOPOLITAN__ -D__COSMOCC__ -D__FATCOSMOCC__"
@@ -263,12 +298,22 @@ if [ x"$OPT" != x"-O3" ] && [ x"$MODE" != x"optlinux" ]; then
263
298
CFLAGS=" $CFLAGS -fno-schedule-insns2"
264
299
fi
265
300
301
+ if [ x" $X " = x" c" ] || [ x" $X " = x" c-header" ]; then
302
+ CPLUSPLUS=0
303
+ elif [ x" $X " = x" c++" ] || [ x" $X " = x" c++-header" ]; then
304
+ CPLUSPLUS=1
305
+ elif [ x" $PROG " != x" ${PROG% ++} " ]; then
306
+ CPLUSPLUS=1
307
+ else
308
+ CPLUSPLUS=0
309
+ fi
310
+
266
311
CC_X86_64=" $BIN /x86_64-linux-cosmo-gcc"
267
312
CC_AARCH64=" $BIN /aarch64-linux-cosmo-gcc"
268
- if [ x " $PROG " != x " ${PROG % ++} " ]; then
313
+ if [ $CPLUSPLUS -eq 1 ]; then
269
314
CC_X86_64=" $BIN /x86_64-linux-cosmo-g++"
270
315
CC_AARCH64=" $BIN /aarch64-linux-cosmo-g++"
271
- if [ x " $INTENT " != x " cpp" ]; then
316
+ if [ $INTENT != cpp ]; then
272
317
CFLAGS=" $CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
273
318
fi
274
319
CPPFLAGS=" -isystem $BIN /../include/third_party/libcxx $CPPFLAGS "
@@ -313,7 +358,7 @@ if [ x"$OPT" != x"-Os" ] && [ x"$MODE" != x"tiny" ] && [ x"$MODE" != x"optlinux"
313
358
CFLAGS_AARCH64=" ${CFLAGS_AARCH64} -fpatchable-function-entry=7,6 -fno-inline-functions-called-once -DFTRACE -DSYSDEBUG"
314
359
fi
315
360
316
- if [ x " $PROG " != x " ${PROG % ++} " ]; then
361
+ if [ $CPLUSPLUS -eq 1 ]; then
317
362
LDLIBS_X86_64=" -lcxx ${LDLIBS_X86_64} "
318
363
LDLIBS_AARCH64=" -lcxx ${LDLIBS_AARCH64} "
319
364
fi
0 commit comments