OverviewFilesCommitsIssuesDocsReleasesPeers

dc-terrain / tools / zig-cc

22 lines · text ref:
#!/bin/sh
export HOME="${HOME:-/home/fleeky}"
# zig cc wrapper: cross-compile to an OLD glibc (2.28) so the .so loads on older
# hosts (e.g. ashatron, glibc 2.35), with OpenMP via LLVM's libomp (clang's ABI;
# modern clang dropped libgomp). The target needs libomp.so.5 at runtime
# (apt install libomp5); the build records only the SONAME, not host glibc.
args=""; openmp=0; compile=0
for arg in "$@"; do
    case "$arg" in
        -march=x86-64|-m64|-fno-gnu-unique) ;;   # filtered: zig rejects these
        -fopenmp) args="$args -fopenmp"; openmp=1 ;;  # enable OpenMP (libomp/__kmpc ABI)
        -c) args="$args -c"; compile=1 ;;
        *) args="$args $arg" ;;
    esac
done
# On LINK steps with OpenMP, link libomp by FULL PATH so lld records DT_NEEDED
# libomp.so.5 (clang's auto -lomp doesn't fire under zig's lld for -shared).
omp=""
[ "$openmp" = 1 ] && [ "$compile" = 0 ] && omp="/usr/lib/llvm-18/lib/libomp.so.5"
# -isystem: host headers + clang's omp.h. -L: host libs + llvm-18 lib dir.
exec zig cc -target x86_64-linux-gnu.2.28 -isystem /usr/include -isystem /usr/lib/llvm-18/lib/clang/18/include -L/usr/lib/x86_64-linux-gnu -L/usr/lib/llvm-18/lib $args $omp