make regen: ~8x faster: use sed script instead of single invocations

Change-Id: Ib9b3f4fc524bf3ae7cc921b0340adec113529d4d
This commit is contained in:
Neels Hofmeyr 2016-07-11 18:36:46 +02:00
parent 156fa393fc
commit c23146e7f1
1 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
# Usage: # Usage:
# ../../move-asn1-headers.sh osmocom/foo/bar File1.h File2.h ... # ../../move-asn1-headers.sh subdir_name File1.h File2.h ...
# All .h and .c files in the current directory are edited to use #include <...>
# style for the .h files given on the cmdline. The given .h files are also
# moved to ../include/<subdir_name>/ so that #include <...> will work.
set -e set -e
@ -13,13 +16,12 @@ include_dir="$base_dir/include/$include_subdir"
mkdir -p "$include_dir" mkdir -p "$include_dir"
echo "$PWD/*.h --> $include_dir" echo "$PWD/*.h --> $include_dir"
sed_includes() { collect_sed_commands() {
while [ -n "$1" ]; do while [ -n "$1" ]; do
fname="$1" fname="$1"
shift shift
echo 'sed -i "s,^#include \"'$fname'\"$,#include <'$include_subdir/$fname'>," *.[hc]' echo "s,^#include \"$fname\"$,#include <$include_subdir/$fname>,"
sed -i "s,^#include \"$fname\"$,#include <$include_subdir/$fname>," *.[hc]
done done
} }
@ -28,8 +30,15 @@ move_headers() {
mv $@ "$include_dir/" mv $@ "$include_dir/"
} }
# first replace all `#include "foo.h"' with `#include <dir/foo.h>' locally # Replace all `#include "foo.h"' with `#include <dir/foo.h>' locally
sed_includes $@ # - Collect sed commands to replace all header includes, for efficiency
cmds="$(mktemp)"
echo "collecting sed commands..."
collect_sed_commands $@ > "$cmds"
# - Run commands on all h and c files
echo "sed -i -f \"$cmds\" *.[hc]"
sed -i -f "$cmds" *.[hc]
rm "$cmds"
# move sed'ed *.h files to the proper include/dir # Now move sed'ed *.h files to the proper ../include/dir
move_headers $@ move_headers $@