blob: b9683236816406d31b13821408e299ef7b7069ff [file] [log] [blame]
Harald Welte3aa901d2018-08-13 18:32:36 +02001#!/bin/sh
2# Usage:
3# ../../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.
7
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
19collect_sed_commands() {
20 while [ -n "$1" ]; do
21 fname="$1"
22 shift
23
24 echo "s,^#include \"$fname\"$,#include <$include_subdir/$fname>,"
25 done
26}
27
28move_headers() {
29 echo mv $@ "$include_dir/"
30 mv $@ "$include_dir/"
31}
32
33# 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"
42
43# Now move sed'ed *.h files to the proper ../include/dir
44move_headers $@