aboutsummaryrefslogtreecommitdiff
path: root/aux/prune-includes.sh
blob: 3a10fa2e9a038425f44043316c1cf62933ae4edc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
set -eu

. aux/lib.sh

prune() {
	file="$1"
	lines="$(grep -n '^#include ' "$file" | cut -d: -f1)"
	ORIG="$(mkstemp)"
	cp "$file" "$ORIG"
	for line in $lines; do
		sed "${line}d" "$ORIG" > "$file"
		if make -e; then
			prune "$file"
			break
		else
			cp "$ORIG" "$file"
		fi
	done
}

for f in "$@"; do
	prune "$f"
done