aboutsummaryrefslogtreecommitdiffstats
path: root/move-asn1-header-files.sh
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2016-07-11 18:36:46 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2016-07-12 00:44:18 +0200
commitc23146e7f18b0f1bea67ba7b48ad4bc6cc76958b (patch)
tree9879630868f7984256eb72dc5be5826e8c9b5a22 /move-asn1-header-files.sh
parent156fa393fc7472ba57683905c054adc6892b3cbd (diff)
make regen: ~8x faster: use sed script instead of single invocations
Diffstat (limited to 'move-asn1-header-files.sh')
-rwxr-xr-xmove-asn1-header-files.sh25
1 files changed, 17 insertions, 8 deletions
diff --git a/move-asn1-header-files.sh b/move-asn1-header-files.sh
index c16816a..b968323 100755
--- a/move-asn1-header-files.sh
+++ b/move-asn1-header-files.sh
@@ -1,6 +1,9 @@
#!/bin/sh
# 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
@@ -13,13 +16,12 @@ include_dir="$base_dir/include/$include_subdir"
mkdir -p "$include_dir"
echo "$PWD/*.h --> $include_dir"
-sed_includes() {
+collect_sed_commands() {
while [ -n "$1" ]; do
fname="$1"
shift
- echo 'sed -i "s,^#include \"'$fname'\"$,#include <'$include_subdir/$fname'>," *.[hc]'
- sed -i "s,^#include \"$fname\"$,#include <$include_subdir/$fname>," *.[hc]
+ echo "s,^#include \"$fname\"$,#include <$include_subdir/$fname>,"
done
}
@@ -28,8 +30,15 @@ move_headers() {
mv $@ "$include_dir/"
}
-# first replace all `#include "foo.h"' with `#include <dir/foo.h>' locally
-sed_includes $@
-
-# move sed'ed *.h files to the proper include/dir
+# Replace all `#include "foo.h"' with `#include <dir/foo.h>' locally
+# - 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"
+
+# Now move sed'ed *.h files to the proper ../include/dir
move_headers $@