You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
941 B
50 lines
941 B
3 years ago
|
#!/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";;
|
||
|
aarch64|arm*)
|
||
|
A="ARM";;
|
||
|
*)
|
||
|
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
|