>From 608e11a25a6c44bffe018b4d7a6281fffc32554d Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Tue, 16 Jul 2019 22:41:59 +0300 Subject: [PATCH 1/4] pkg.in: factored out bin/archdep-* These were just asking to be unified as a (hasty) internal fork between implementations has actually occured to date (which is a total shame); the overall number of fork()s should go down a bit, too. The archdep-filter is now able to handle both a file specified on the command line and stdin (don't you do inplace substitution on the same file in a pipe though, it's a race condition that occured to be overly subtle to me this evening). Thanks: Dmitry Levin --- bin/archdep-filter | 36 ++++++++++++++++++++++++++++++++++++ bin/archdep-grep | 9 +++++++++ pkg.in/lists/Makefile | 10 +--------- pkg.in/profiles/Makefile | 10 +--------- 4 files changed, 47 insertions(+), 18 deletions(-) create mode 100755 bin/archdep-filter create mode 100755 bin/archdep-grep diff --git a/bin/archdep-filter b/bin/archdep-filter new file mode 100755 index 0000000..3a81b2d --- /dev/null +++ b/bin/archdep-filter @@ -0,0 +1,36 @@ +#!/bin/sh +# transform texts including lines like entity@arch + +[ -n "$ARCH" ] || { + echo "** error: ARCH not set" >&2 + exit 1 +} + +# -n is definitely not a typo +process() { + sed -r -e 's/\<([^@ ]*)@X86\>/\1@i586 \1@x86_64/g' \ + -e 's/\<([^@ ]*)@IA32\>/\1@i586 i586-\1@x86_64/g' \ + -e 's/\<([^@ ]*)@E2K\>/\1@e2k \1@e2kv4/g' | + sed -r -n 's/\<([^@ ]*)\>|\<([^@ ]*)@'"$ARCH"'\>/\1\2/pg' | + sed -r -e 's/\<([^@ ]*)@[^@ ]+\> *//g' \ + -e 's/^ +//;s/ +$//' +} + +exit_handler() +{ + local rc=$1 + rm -f -- "$tmpfile" + exit $rc +} + +tmpfile="$(mktemp)" +trap 'exit_handler $?' EXIT HUP PIPE INT QUIT TERM + +# arguments can be a single file or none +# (in which case stdout gets processed) +if [ -f "$1" ]; then + process < "$1" > "$tmpfile" && + cat "$tmpfile" > "$1" +else + process +fi diff --git a/bin/archdep-grep b/bin/archdep-grep new file mode 100755 index 0000000..a3c3b9d --- /dev/null +++ b/bin/archdep-grep @@ -0,0 +1,9 @@ +#!/bin/sh +# used twice at least + +[ -d "$1" ] || { + echo "** error: missing directory argument" >&2 + exit 1 +} + +find "$1" -type f | xargs -rL1 -I '__' archdep-filter __ diff --git a/pkg.in/lists/Makefile b/pkg.in/lists/Makefile index 1be3792..afc5035 100644 --- a/pkg.in/lists/Makefile +++ b/pkg.in/lists/Makefile @@ -35,16 +35,8 @@ copy-groups: @echo $(call groups2lists) \ | xargs -r -- cp --parents -at $(TARGET) -- -grep-archdep: a = $(ARCH) grep-archdep: - @# xargs -L 1024 -n 1024 ? -- breaks -I - @find $(TARGET) -type f \ - | xargs -I '__' sh -c '\ - sed -ri "s/\\<([^@ ]*)@X86\\>/\\1@i586 \\1@x86_64/g" __; \ - sed -ri "s/\\<([^@ ]*)@IA32\\>/\\1@i586 i586-\\1@x86_64/g" __;\ - sed -rni "s/\\<([^@ ]*)\\>|\\<([^@ ]*)@$a\\>/\\1\\2/pg" __; \ - sed -ri "s/\\<([^@ ]*)@[^@ ]+\\> *//g" __; \ - sed -ri "s/^ +//;s/ +$$//" __' + @archdep-grep $(TARGET) # do beforehand as foreach gets expanded before recipe execution $(TARGET): diff --git a/pkg.in/profiles/Makefile b/pkg.in/profiles/Makefile index 5251436..056a754 100644 --- a/pkg.in/profiles/Makefile +++ b/pkg.in/profiles/Makefile @@ -18,16 +18,8 @@ copy-profiles: $(addsuffix .directory,$(THE_PROFILES)); \ fi -### exact copy of a snippet from ../lists/Makefile -grep-archdep: a = $(ARCH) grep-archdep: - @# xargs -L 1024 -n 1024 ? -- breaks -I - @find $(TARGET) -type f \ - | xargs -I '__' sh -c '\ - sed -ri "s/\\<([^@ ]*)@X86\\>/\\1@i586 \\1@x86_64/g" __; \ - sed -ri "s/\\<([^@ ]*)@IA32\\>/\\1@i586 i586-\\1@x86_64/g" __;\ - sed -rni "s/\\<([^@ ]*)\\>|\\<([^@ ]*)@$a\\>/\\1\\2/pg" __; \ - sed -ri "s/\\<([^@ ]*)@[^@ ]+\\> *//g" __' + @archdep-grep $(TARGET) $(TARGET): @mkdir -p $(TARGET) -- 2.10.4