#!/bin/bash

declare -a finalargs
finalargs=()

for o in "$@"; do
    if [ "$o" = "-Wl,--no-undefined-version" ]; then
        continue
    fi

    if [[ "$o" == "--target="* ]]; then
        continue
    fi

    if [[ "$o" == "-march="* ]]; then
        continue
    fi

    if [[ "$o" == "--march="* ]]; then
        continue
    fi

    if [[ "$o" == "-mtune="* ]]; then
        continue
    fi

    if [[ "$o" == "--mtune="* ]]; then
        continue
    fi

    finalargs+=("$o")
done

if [ "$(arch)" = "x86_64" ]; then
    MARCH="-march=x86_64"
elif [ "$(arch)" = "aarch64" ]; then
    # MARCH="-march=armv8-a"
    MARCH=""
else 
    MARCH=""
fi

exec /app/zig/zig cc $MARCH "${finalargs[@]}"

