diff --git a/bin/archdep-filter b/bin/archdep-filter new file mode 100755 index 00000000..9e289441 --- /dev/null +++ b/bin/archdep-filter @@ -0,0 +1,47 @@ +#!/bin/sh +# filter stdin or file for words related to +# the specified target architecture +# +# args: -a arch [-i file] + +if [ "$1" = "-a" -a -n "$2" ]; then + a="$2" + shift 2 +else + cat + exit +fi + +if [ "$1" = "-i" -a -w "$2" ]; then + f="$2" + t="`mktemp`" +fi + +# map meta-arches for prefiltering +# NB: biarch gets special expansion later +case "$a" in +i586) + A="(IA32|X86)";; +x86_64) + A="X86";; +e2k*) + A="E2K";; +*) + A=;; +esac + +# NB: pipe runs in parallel => faster than -e -e +cat ${f:+"$f"} | +sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$A\>/\1\2/pg" | +sed -rn "s/\<([^@ ]*)\>|\<[^@ ]*@\!$A\> */\1/pg" | +sed -r "s/\<([^@ ]*)@IA32\>/\1@i586 i586-\1@x86_64/g" | +sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$a\>/\1\2/pg" | +sed -rn "s/\<([^@ ]*)\>|\<[^@ ]*@\!$a\> */\1/pg" | +sed -r "s/\<([^@ ]*)@\![^@ ]+\>/\1/g" | +sed -r "s/\<([^@ ]*)@[^@ ]+\> *//g" | +sed -r "s/^ +//;s/ +$//" | +if [ -n "$f" ]; then + cat > "$t" && mv "$t" "$f" +else + cat +fi