#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# "ld -r" for Mach-O, which ld64.lld does not do: the "relocatable object"
# is a thin archive of the inputs (nested ones flattened). xnu-cc force-loads it.
LLVM=${LLVM:-/opt/homebrew/opt/llvm/bin}
reloc=0; out=; ins=
while [ $# -gt 0 ]; do
	case "$1" in
	-r) reloc=1 ;;
	-o) out=$2; shift ;;
	-m|-T|-Map) shift ;;
	-*) ;;
	*) ins="$ins $1" ;;
	esac
	shift
done
if [ $reloc = 1 ]; then
	rm -f "$out"
	exec "$LLVM/llvm-ar" rcsT "$out" $ins
fi
echo "xnu-ld: only -r is supported (link with xnu-cc)" >&2
exit 1
