fix zig-cc script with different PKG_ROOT_PATH (and filter out some gcc-only warning options)

This commit is contained in:
henderkes
2026-05-07 10:58:46 +07:00
parent edeb5b9f0d
commit ff9a84967f

View File

@@ -1,9 +1,14 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../../buildroot/include" 2>/dev/null || true)"
BUILDROOT_INC="${BUILD_INCLUDE_PATH:-$SCRIPT_DIR/../../../buildroot/include}"
BUILDROOT_ABS="$(realpath "$BUILDROOT_INC" 2>/dev/null || true)"
PARSED_ARGS=()
is_buildroot_inc() {
[[ -n "$BUILDROOT_ABS" && "$1" == "$BUILDROOT_ABS" ]]
}
while [[ $# -gt 0 ]]; do
case "$1" in
-isystem)
@@ -11,13 +16,13 @@ while [[ $# -gt 0 ]]; do
ARG="$1"
shift
ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)"
[[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem" "$ARG")
is_buildroot_inc "$ARG_ABS" && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem" "$ARG")
;;
-isystem*)
ARG="${1#-isystem}"
shift
ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)"
[[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG")
is_buildroot_inc "$ARG_ABS" && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG")
;;
-march=*|-mcpu=*)
OPT_NAME="${1%%=*}"
@@ -32,6 +37,10 @@ while [[ $# -gt 0 ]]; do
PARSED_ARGS+=("${OPT_NAME}=${OPT_VALUE}")
shift
;;
-Wlogical-op|-Wduplicated-cond|-Wduplicated-branches|-Wno-clobbered|-Wjump-misses-init|-Wformat-truncation|-Warray-bounds=*|-Wimplicit-fallthrough=*)
# GCC-only warning flags that clang/zig doesn't recognize; drop to silence -Wunknown-warning-option noise
shift
;;
*)
PARSED_ARGS+=("$1")
shift