summaryrefslogtreecommitdiff
path: root/tools/notsd-fixup
blob: 0bd5c10bd968fc3a82870f6ca279aabeca228c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash

# The reason we do `find`/`while read`-loops instead of `find -exec` commands
# is that we want errors from the inner loop to bubble up.

fixup_makefiles() (
	find -type f -name Makefile | while read -r filename; do
		sed -r -i "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="${filename%/*}" config.mk)|" "$filename"
	done
)

fixup_includes() (
        find $(find . -type d -name include) -type d | while read -r dir; do
                lib="${dir##*/}"
                pushd "$dir" >/dev/null
                find . -type f -exec sed -ri -e "s|$lib/||" -- {} +
                popd >/dev/null
        done

        find src \( -name '*.h' -o -name '*.c' \) -type f | while read -r filename; do
                "$0"--includes "$filename"
        done
)

main() {
        set -e
        set -o pipefail
        fixup_makefiles
        fixup_includes
}

main "$@"