| #!/bin/bash |
| # This uses the zircon prebuild C++ toolchain |
| |
| if [ -z "${ZIRCON}" ]; then |
| echo "gccwrap.sh: missing ZIRCON env variable" >&2 |
| exit 1 |
| fi |
| |
| zirconsysroot="${ZIRCON_SYSROOT}" |
| if [ -z "${zirconsysroot}" ]; then |
| echo "gccwrap.sh: missing ZIRCON_SYSROOT env variable" >&2 |
| exit 1 |
| fi |
| |
| if [ -z "${FUCHSIA_ROOT_OUT_DIR}" ]; then |
| echo "gccwrap.sh: missing FUCHSIA_ROOT_OUT_DIR env variable" >&2 |
| exit 1 |
| fi |
| |
| if [ "$GOARCH" == "amd64" ]; then |
| libdir="x64-shared" |
| gccbin="$ZIRCON/prebuilt/downloads/gcc/bin/x86_64-elf-gcc" |
| elif [ "$GOARCH" == "arm64" ]; then |
| libdir="arm64-shared" |
| gccbin="$ZIRCON/prebuilt/downloads/gcc/bin/aarch64-elf-gcc" |
| else |
| echo "gccwrap.sh: unsupported GOARCH: $GOARCH" >&2 |
| exit 1 |
| fi |
| |
| compiler=false |
| extra_args="" |
| |
| for var in "$@" |
| do |
| if [[ "$var" == "-r" || "$var" == "-c" ]]; then |
| compiler=true |
| fi |
| done |
| |
| if ! $compiler; then |
| extra_args="-lc $zirconsysroot/lib/Scrt1.o $zirconsysroot/lib/libzircon.so -lfdio" |
| fi |
| |
| exec $gccbin \ |
| --sysroot=$zirconsysroot \ |
| -I$zirconsysroot/include \ |
| -I${ZIRCON}/system/ulib/fdio/include \ |
| -L$zirconsysroot/lib \ |
| -L${FUCHSIA_ROOT_OUT_DIR}/${libdir} \ |
| -nostdlib \ |
| -fuse-ld=gold \ |
| -fno-use-linker-plugin \ |
| -Wl,-nostdlib \ |
| -Wl,--build-id \ |
| -Wl,-z,max-page-size=4096 \ |
| -Wl,-z,combreloc \ |
| -Wl,-z,relro \ |
| -Wl,-z,now \ |
| -Wl,-z,text \ |
| -Wl,-z,noexecstack \ |
| -Wl,--hash-style=gnu \ |
| -Wl,--eh-frame-hdr \ |
| -Wl,-dynamic-linker=ld.so.1 \ |
| $extra_args \ |
| "$@" |