summaryrefslogtreecommitdiff
path: root/tools/notsd-fixup
blob: 820d2fec17d9a29ae74c91687ea76db0e5524e25 (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
#!/usr/bin/env bash
# Copyright (C) 2015-2016  Luke Shumaker

main() {
	set -e
	set -o pipefail
	export LC_COLLATE=C

	# We wrap the programs called by xargs with `sh` because xargs only exits early
	# if the status is 255, but we want to exit early for all non-zero statuses.
	# We use xargs instead of `find -exec` because `-exec` won't do much of
	# anything useful with the exit status.

	# Makefiles
	find "$@" -type f -name Makefile -print0 |
		xargs -r0 sh -c "$0--makefiles \"\$@\" || exit 255" --

	# GNUmakefiles
	find "$@" -type l -name GNUmakefile -delete
	# It's OK for the top-level one to fail
	find "$@" -type f -name Makefile -printf '%h\0' |
		xargs -r0 -I {} ln -s -t {} GNUmakefile

	# C includes
	rm -rf -- "$0"--includes.cache
	find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.gperf' -o -name '*.gperf.m4' \) -type f -print0 |
		xargs -r0 sh -c "$0--includes \"\$@\" || exit 255" --
	rm -rf -- "$0"--includes.cache
}

main "$@"