#!/usr/bin/env bash # brintcc — the C compiler driver for wasm32-hwjs-linux. # # The front door. It resolves configuration (libexec/config.sh), decides which # libc this line is for, and execs the implementation in libexec/. It is an # exec, not a call: this toolchain compiles entire distributions, and a second # process per translation unit is a cost paid a million times. # # LIBC SELECTION. Default musl; `-mlibc=glibc` or a target triple naming a gnu # environment selects the glibc implementation. The selector is STRIPPED before # the exec — clang has no -mlibc flag and refuses the line if it sees one. # Autotools does not ask for a libc by flag; it looks for a program named after # the target triple, which is what the wasm32-hwjs-linux-*-gcc symlinks beside # this file are for. Invoked through one of those, the name decides the default. set -euo pipefail # PATH PROBES # # dirname and basename in the shell. path_dirname_v and path_basename_v answer # in $PATH_DIRNAME and $PATH_BASENAME what "$(dirname -- "$1")" and # "$(basename -- "$1")" hold, the trailing newlines the substitution strips # included, and start no process. The same block is in bin/brintcc, # libexec/config.sh, libexec/brintcc-glibc and libexec/brintld. path_dirname_v() { local _pd="$1" _pd="${_pd%"${_pd##*[!/]}"}" if [[ -z "$_pd" ]]; then if [[ -n "$1" ]]; then PATH_DIRNAME=/; else PATH_DIRNAME=.; fi elif [[ "$_pd" != */* ]]; then PATH_DIRNAME=. else _pd="${_pd%/*}" _pd="${_pd%"${_pd##*[!/]}"}" PATH_DIRNAME="${_pd:-/}" fi PATH_DIRNAME="${PATH_DIRNAME%"${PATH_DIRNAME##*[!$'\n']}"}" } path_basename_v() { local _pb="$1" _pb="${_pb%"${_pb##*[!/]}"}" if [[ -n "$_pb" ]]; then PATH_BASENAME="${_pb##*/}" elif [[ -n "$1" ]]; then PATH_BASENAME=/ else PATH_BASENAME= fi PATH_BASENAME="${PATH_BASENAME%"${PATH_BASENAME##*[!$'\n']}"}" } # End of the path probes. # readlink -f, not dirname alone: these front doors are meant to be symlinked # into a prefix on PATH, and a symlink's dirname is the prefix, not this repo. path_dirname_v "$(readlink -f "${BASH_SOURCE[0]}")" source "$PATH_DIRNAME/../libexec/config.sh" brintium_require llvm sysroot brintium_select_libc "$@" case "$BRINTIUM_LIBC" in glibc) # The glibc arm compiles against the kernel UAPI headers unconditionally # (-isystem, on every line), so an absent pointer is a refusal here rather # than an -isystem of a directory that does not exist and a header error # a thousand lines into a build. brintium_require kernel-headers exec "$BRINTIUM/libexec/brintcc-glibc" "${BRINTIUM_ARGV[@]}" ;; musl) exec "$BRINTIUM/libexec/brintcc-musl" "${BRINTIUM_ARGV[@]}" ;; esac