archdep-filter 1.23 KB
Newer Older
1 2 3 4
#!/bin/sh
# filter stdin or file for words related to
# the specified target architecture
#
5
# args: [-a arch] [-i file]
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

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
*)
	A=;;
esac

# NB: pipe runs in parallel => faster than -e -e
cat ${f:+"$f"} |
37
sed -r  ':loop; s/^((([^@]+@!)[^,]+)+),([a-zA-Z0-9_]+)/\1@!\4/; t loop' |
38
sed -r  ':loop; s/^((([^@]+@)[^,]+)+),([a-zA-Z0-9_]+)/\1\n\3\4/; t loop' |
39 40
sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$A\>[^ ]*\>/\1\2/pg" |
sed -rn "s/\<([^@ ]*)\>|\<[^ ]*@\!$A\>[^ ]*\> */\1/pg" |
41
sed -r  "s/\<([^@ ]*)@IA32\>/\1@i586 i586-\1@x86_64/g" |
42 43 44
sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$a\>[^ ]*\>/\1\2/pg" |
sed -rn "s/\<([^@ ]*)\>|\<[^ ]*@\!$a\>[^ ]*\> */\1/pg" |
sed -r  "s/\<([^@ ]*)@\![^ ]+\>/\1/g" |
45
sed -r  "s/\<([^@ ]*)@[^@ ]+\> *//g" |
46
sed -r  "s/^ +//;s/ +$//;/^$/d" |
47 48 49 50 51
if [ -n "$f" ]; then
	cat > "$t" && mv "$t" "$f"
else
	cat
fi
52 53 54 55

# stick this for debugging sed pipeline and run the script
# with >/dev/null to see what flows in a particular place:
#   tee /dev/stderr |