blob: b9683236816406d31b13821408e299ef7b7069ff [file] [log] [blame]
Neels Hofmeyr5aabad12016-01-04 15:23:09 +01001#!/bin/sh
2# Usage:
Neels Hofmeyrc23146e2016-07-11 18:36:46 +02003# ../../move-asn1-headers.sh subdir_name File1.h File2.h ...
4# All .h and .c files in the current directory are edited to use #include <...>
5# style for the .h files given on the cmdline. The given .h files are also
6# moved to ../include/<subdir_name>/ so that #include <...> will work.
Neels Hofmeyr5aabad12016-01-04 15:23:09 +01007
8set -e
9
10base_dir="$(dirname "$0")"
11
12include_subdir="$1"
13shift
14
15include_dir="$base_dir/include/$include_subdir"
16mkdir -p "$include_dir"
17echo "$PWD/*.h --> $include_dir"
18
Neels Hofmeyrc23146e2016-07-11 18:36:46 +020019collect_sed_commands() {
Neels Hofmeyr5aabad12016-01-04 15:23:09 +010020 while [ -n "$1" ]; do
21 fname="$1"
22 shift
23
Neels Hofmeyrc23146e2016-07-11 18:36:46 +020024 echo "s,^#include \"$fname\"$,#include <$include_subdir/$fname>,"
Neels Hofmeyr5aabad12016-01-04 15:23:09 +010025 done
26}
27
28move_headers() {
29 echo mv $@ "$include_dir/"
30 mv $@ "$include_dir/"
31}
32
Neels Hofmeyrc23146e2016-07-11 18:36:46 +020033# Replace all `#include "foo.h"' with `#include <dir/foo.h>' locally
34# - Collect sed commands to replace all header includes, for efficiency
35cmds="$(mktemp)"
36echo "collecting sed commands..."
37collect_sed_commands $@ > "$cmds"
38# - Run commands on all h and c files
39echo "sed -i -f \"$cmds\" *.[hc]"
40sed -i -f "$cmds" *.[hc]
41rm "$cmds"
Neels Hofmeyr5aabad12016-01-04 15:23:09 +010042
Neels Hofmeyrc23146e2016-07-11 18:36:46 +020043# Now move sed'ed *.h files to the proper ../include/dir
Neels Hofmeyre8b14652016-01-04 15:39:35 +010044move_headers $@