archdep-filter 941 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/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";;
29 30
aarch64|arm*)
	A="ARM";;
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
*)
	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