mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Add precompiled header support to cosmocc
This commit is contained in:
parent
f8cfc89eba
commit
6ac3d3b804
2 changed files with 102 additions and 17 deletions
|
@ -75,10 +75,12 @@ elif [ ! -d "$TMPDIR" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
X=
|
||||||
OPT=
|
OPT=
|
||||||
ARGS=
|
ARGS=
|
||||||
FLAGS=
|
FLAGS=
|
||||||
OUTPUT=
|
OUTPUT=
|
||||||
|
NEED_X=
|
||||||
MDFLAG=0
|
MDFLAG=0
|
||||||
MCOSMO=0
|
MCOSMO=0
|
||||||
INTENT=ld
|
INTENT=ld
|
||||||
|
@ -94,8 +96,7 @@ NEED_DEPENDENCY_OUTPUT=
|
||||||
for x; do
|
for x; do
|
||||||
if [ x"$x" != x"${x#* }" ]; then
|
if [ x"$x" != x"${x#* }" ]; then
|
||||||
fatal_error "arguments containing spaces unsupported: $x"
|
fatal_error "arguments containing spaces unsupported: $x"
|
||||||
fi
|
elif [ -n "$NEED_OUTPUT" ]; then
|
||||||
if [ -n "$NEED_OUTPUT" ]; then
|
|
||||||
NEED_OUTPUT=
|
NEED_OUTPUT=
|
||||||
OUTPUT=$x
|
OUTPUT=$x
|
||||||
continue
|
continue
|
||||||
|
@ -109,6 +110,10 @@ for x; do
|
||||||
elif [ -n "$NEED_EQUAL" ]; then
|
elif [ -n "$NEED_EQUAL" ]; then
|
||||||
x="${NEED_EQUAL}=${x}"
|
x="${NEED_EQUAL}=${x}"
|
||||||
NEED_EQUAL=
|
NEED_EQUAL=
|
||||||
|
elif [ -n "$NEED_X" ]; then
|
||||||
|
NEED_X=
|
||||||
|
X=$x
|
||||||
|
x="-x${x}"
|
||||||
elif [ x"$x" = x"-" ] || # is alias for stdin
|
elif [ x"$x" = x"-" ] || # is alias for stdin
|
||||||
[ x"$x" = x"${x#-*}" ]; then # !startswith(x, "-")
|
[ x"$x" = x"${x#-*}" ]; then # !startswith(x, "-")
|
||||||
if [ x"$x" != x"${x%.s}" ] ||
|
if [ x"$x" != x"${x%.s}" ] ||
|
||||||
|
@ -142,6 +147,7 @@ for x; do
|
||||||
if [ x"$INTENT" != x"cpp" ]; then
|
if [ x"$INTENT" != x"cpp" ]; then
|
||||||
INTENT=cc
|
INTENT=cc
|
||||||
fi
|
fi
|
||||||
|
continue
|
||||||
elif [ x"$x" = x"-E" ] ||
|
elif [ x"$x" = x"-E" ] ||
|
||||||
[ x"$x" = x"-M" ] ||
|
[ x"$x" = x"-M" ] ||
|
||||||
[ x"$x" = x"-MM" ]; then
|
[ x"$x" = x"-MM" ]; then
|
||||||
|
@ -214,8 +220,12 @@ for x; do
|
||||||
elif [ x"$x" = x"-dumpversion" ]; then
|
elif [ x"$x" = x"-dumpversion" ]; then
|
||||||
echo $GCC_VERSION
|
echo $GCC_VERSION
|
||||||
Exit 0
|
Exit 0
|
||||||
elif [ x"$x" = x"-x" ] ||
|
elif [ x"$x" = x"-x" ]; then
|
||||||
[ x"$x" = x"-e" ] ||
|
NEED_X=1
|
||||||
|
continue
|
||||||
|
elif [ x"$x" != x"${x#-x}" ]; then
|
||||||
|
X=${x#-x}
|
||||||
|
elif [ x"$x" = x"-e" ] ||
|
||||||
[ x"$x" = x"-z" ] ||
|
[ x"$x" = x"-z" ] ||
|
||||||
[ x"$x" = x"-T" ] ||
|
[ x"$x" = x"-T" ] ||
|
||||||
[ x"$x" = x"-L" ] ||
|
[ x"$x" = x"-L" ] ||
|
||||||
|
@ -240,12 +250,37 @@ for x; do
|
||||||
ARGS="$ARGS $x"
|
ARGS="$ARGS $x"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# precompiled header mode
|
||||||
|
if [ $INTENT != cpp ]; then
|
||||||
|
if [ -z "$X" ]; then
|
||||||
|
ONLY_HEADER_INPUTS=1
|
||||||
|
for x in $ARGS; do
|
||||||
|
if [ x"$x" = x"${x#-*}" ] && # !startswith(x, "-")
|
||||||
|
[ x"$x" = x"${x%.h}" ] && # !endswith(x, ".h")
|
||||||
|
[ x"$x" = x"${x%.hpp}" ]; then # !endswith(x, ".hpp")
|
||||||
|
ONLY_HEADER_INPUTS=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $ONLY_HEADER_INPUTS -eq 1 ]; then
|
||||||
|
INTENT=gch
|
||||||
|
fi
|
||||||
|
elif [ x"$X" = x"c-header" ] ||
|
||||||
|
[ x"$X" = x"c++-header" ]; then
|
||||||
|
INTENT=gch
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ $INTENT = gch ]; then
|
||||||
|
fatal_error "precompiled headers only supported with ARCH-unknown-cosmo-cc compilers"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check for incorrect usage
|
||||||
if [ $INPUT_FILE_COUNT -eq 0 ]; then
|
if [ $INPUT_FILE_COUNT -eq 0 ]; then
|
||||||
fatal_error "no input files"
|
fatal_error "no input files"
|
||||||
elif [ -z "$INPUT" ] &&
|
elif [ -n "$OUTPUT" ] && [ $INPUT_FILE_COUNT -gt 1 ]; then
|
||||||
[ $INTENT != ld ] &&
|
if [ $INTENT = cc ] || [ $INTENT = cpp ]; then
|
||||||
[ $INPUT_FILE_COUNT -gt 1 ]; then
|
fatal_error "cannot specify '-o' with '-c' or '-E' with multiple files"
|
||||||
fatal_error "cannot specify '-o' with '-c', or '-E' with multiple files"
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PLATFORM="-D__COSMOPOLITAN__ -D__COSMOCC__ -D__FATCOSMOCC__"
|
PLATFORM="-D__COSMOPOLITAN__ -D__COSMOCC__ -D__FATCOSMOCC__"
|
||||||
|
@ -263,12 +298,22 @@ if [ x"$OPT" != x"-O3" ] && [ x"$MODE" != x"optlinux" ]; then
|
||||||
CFLAGS="$CFLAGS -fno-schedule-insns2"
|
CFLAGS="$CFLAGS -fno-schedule-insns2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ x"$X" = x"c" ] || [ x"$X" = x"c-header" ]; then
|
||||||
|
CPLUSPLUS=0
|
||||||
|
elif [ x"$X" = x"c++" ] || [ x"$X" = x"c++-header" ]; then
|
||||||
|
CPLUSPLUS=1
|
||||||
|
elif [ x"$PROG" != x"${PROG%++}" ]; then
|
||||||
|
CPLUSPLUS=1
|
||||||
|
else
|
||||||
|
CPLUSPLUS=0
|
||||||
|
fi
|
||||||
|
|
||||||
CC_X86_64="$BIN/x86_64-linux-cosmo-gcc"
|
CC_X86_64="$BIN/x86_64-linux-cosmo-gcc"
|
||||||
CC_AARCH64="$BIN/aarch64-linux-cosmo-gcc"
|
CC_AARCH64="$BIN/aarch64-linux-cosmo-gcc"
|
||||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
if [ $CPLUSPLUS -eq 1 ]; then
|
||||||
CC_X86_64="$BIN/x86_64-linux-cosmo-g++"
|
CC_X86_64="$BIN/x86_64-linux-cosmo-g++"
|
||||||
CC_AARCH64="$BIN/aarch64-linux-cosmo-g++"
|
CC_AARCH64="$BIN/aarch64-linux-cosmo-g++"
|
||||||
if [ x"$INTENT" != x"cpp" ]; then
|
if [ $INTENT != cpp ]; then
|
||||||
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
||||||
fi
|
fi
|
||||||
CPPFLAGS="-isystem $BIN/../include/third_party/libcxx $CPPFLAGS"
|
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"
|
||||||
CFLAGS_AARCH64="${CFLAGS_AARCH64} -fpatchable-function-entry=7,6 -fno-inline-functions-called-once -DFTRACE -DSYSDEBUG"
|
CFLAGS_AARCH64="${CFLAGS_AARCH64} -fpatchable-function-entry=7,6 -fno-inline-functions-called-once -DFTRACE -DSYSDEBUG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
if [ $CPLUSPLUS -eq 1 ]; then
|
||||||
LDLIBS_X86_64="-lcxx ${LDLIBS_X86_64}"
|
LDLIBS_X86_64="-lcxx ${LDLIBS_X86_64}"
|
||||||
LDLIBS_AARCH64="-lcxx ${LDLIBS_AARCH64}"
|
LDLIBS_AARCH64="-lcxx ${LDLIBS_AARCH64}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -59,8 +59,17 @@ if [ x"$ARCH" = x"$PROG" ]; then
|
||||||
fatal_error "cosmocross must be run via cross compiler"
|
fatal_error "cosmocross must be run via cross compiler"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
X=
|
||||||
|
NEED_X=
|
||||||
for x; do
|
for x; do
|
||||||
if [ x"$x" = x"-mtiny" ]; then
|
if [ -n "$NEED_X" ]; then
|
||||||
|
NEED_X=
|
||||||
|
X=$x
|
||||||
|
elif [ x"$x" = x"-x" ]; then
|
||||||
|
NEED_X=1
|
||||||
|
elif [ x"$x" != x"${x#-x}" ]; then
|
||||||
|
X=${x#-x}
|
||||||
|
elif [ x"$x" = x"-mtiny" ]; then
|
||||||
MODE=tiny
|
MODE=tiny
|
||||||
elif [ x"$x" = x"-mdbg" ]; then
|
elif [ x"$x" = x"-mdbg" ]; then
|
||||||
MODE=dbg
|
MODE=dbg
|
||||||
|
@ -79,16 +88,26 @@ else
|
||||||
LIB="$BIN/../$ARCH-linux-cosmo/lib"
|
LIB="$BIN/../$ARCH-linux-cosmo/lib"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ x"$X" = x"c" ] || [ x"$X" = x"c-header" ]; then
|
||||||
|
CPLUSPLUS=0
|
||||||
|
elif [ x"$X" = x"c++" ] || [ x"$X" = x"c++-header" ]; then
|
||||||
|
CPLUSPLUS=1
|
||||||
|
elif [ x"$PROG" != x"${PROG%++}" ]; then
|
||||||
|
CPLUSPLUS=1
|
||||||
|
else
|
||||||
|
CPLUSPLUS=0
|
||||||
|
fi
|
||||||
|
|
||||||
CC="$BIN/$ARCH-linux-cosmo-gcc"
|
CC="$BIN/$ARCH-linux-cosmo-gcc"
|
||||||
CRT="$LIB/crt.o"
|
CRT="$LIB/crt.o"
|
||||||
LDLIBS="-lcosmo"
|
LDLIBS="-lcosmo"
|
||||||
if [ -z "$COSMOS" ]; then
|
if [ -z "$COSMOS" ]; then
|
||||||
LDFLAGS="$LDFLAGS -L$LIB -L$BIN/../$ARCH-linux-cosmo/lib"
|
LDFLAGS="$LDFLAGS -L$LIB -L$BIN/../$ARCH-linux-cosmo/lib"
|
||||||
else
|
else
|
||||||
LDFLAGS="$LDFLAGS -L$COSMOS/lib -L$LIB -L$BIN/../$ARCH-linux-cosmo/lib"
|
LDFLAGS="$LDFLAGS -L$COSMOS/lib -L$LIB -L$BIN/../$ARCH-linux-cosmo/lib"
|
||||||
CPPFLAGS="$CPPFLAGS -I$COSMOS/include"
|
CPPFLAGS="$CPPFLAGS -I$COSMOS/include"
|
||||||
fi
|
fi
|
||||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
if [ $CPLUSPLUS -eq 1 ]; then
|
||||||
CC="$BIN/$ARCH-linux-cosmo-g++"
|
CC="$BIN/$ARCH-linux-cosmo-g++"
|
||||||
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
||||||
CPPFLAGS="-isystem $BIN/../include/third_party/libcxx $CPPFLAGS"
|
CPPFLAGS="-isystem $BIN/../include/third_party/libcxx $CPPFLAGS"
|
||||||
|
@ -219,6 +238,27 @@ if [ $RELOCATABLE -eq 1 ]; then
|
||||||
LDFLAGS="$LDFLAGS -r"
|
LDFLAGS="$LDFLAGS -r"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# precompiled header mode
|
||||||
|
if [ $INTENT != cpp ]; then
|
||||||
|
if [ -z "$X" ]; then
|
||||||
|
ONLY_HEADER_INPUTS=1
|
||||||
|
for x; do
|
||||||
|
if [ x"$x" = x"${x#-*}" ] && # !startswith(x, "-")
|
||||||
|
[ x"$x" = x"${x%.h}" ] && # !endswith(x, ".h")
|
||||||
|
[ x"$x" = x"${x%.hpp}" ]; then # !endswith(x, ".hpp")
|
||||||
|
ONLY_HEADER_INPUTS=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $ONLY_HEADER_INPUTS -eq 1 ]; then
|
||||||
|
INTENT=h
|
||||||
|
fi
|
||||||
|
elif [ x"$X" = x"c-header" ] ||
|
||||||
|
[ x"$X" = x"c++-header" ]; then
|
||||||
|
INTENT=h
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# support --ftrace unless optimizing for size
|
# support --ftrace unless optimizing for size
|
||||||
if [ x"$OPT" != x"-Os" ] && # $OPT != -Os
|
if [ x"$OPT" != x"-Os" ] && # $OPT != -Os
|
||||||
[ x"$MODE" != x"optlinux" ] && # $MODE not optlinux
|
[ x"$MODE" != x"optlinux" ] && # $MODE not optlinux
|
||||||
|
@ -242,7 +282,7 @@ fi
|
||||||
|
|
||||||
if [ $INTENT = cpp ]; then
|
if [ $INTENT = cpp ]; then
|
||||||
set -- "$CC" $PLATFORM $CPPFLAGS "$@"
|
set -- "$CC" $PLATFORM $CPPFLAGS "$@"
|
||||||
elif [ $INTENT = cc ] || [ $INTENT = s ]; then
|
elif [ $INTENT = cc ] || [ $INTENT = s ] || [ $INTENT = h ]; then
|
||||||
set -- "$CC" $PLATFORM $PREDEF $CFLAGS $CPPFLAGS "$@" $PRECIOUS
|
set -- "$CC" $PLATFORM $PREDEF $CFLAGS $CPPFLAGS "$@" $PRECIOUS
|
||||||
else
|
else
|
||||||
set -- "$CC" $PLATFORM $PREDEF $CFLAGS $CPPFLAGS $CRT "$@" $LDFLAGS $LDLIBS $PRECIOUS
|
set -- "$CC" $PLATFORM $PREDEF $CFLAGS $CPPFLAGS $CRT "$@" $LDFLAGS $LDLIBS $PRECIOUS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue