#!/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 { <"$filename" sed -r \ -e "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="$(dirname -- "$filename")" config.mk)|" \ -e '/^nested\.subdirs/d' \ -e '/^include \$\(topsrcdir\)\/build-aux\/Makefile\.tail\.mk$/d' echo find "$(dirname "$filename")" -mindepth 2 -maxdepth 2 -name Makefile -print0 | xargs -r0 dirname -z -- | xargs -r0 basename -a -z | xargs -r0 printf 'nested.subdirs += %s\n' | sort echo echo 'include $(topsrcdir)/build-aux/Makefile.tail.mk' } | cat -s | build-aux/write-ifchanged "$filename" done ) fixup_includes() ( dirs=($(find "$@" -type d -name include)) if [[ ${#dirs[@]} -gt 0 ]]; then find "${dirs[@]}" -type d | while read -r dir; do printf '=> libdir %q\n' "$dir" lib="${dir##*/}" find "$dir" -type f | while read -r filename; do printf ' => sed -ir %q %q\n' "s|$lib/||" "$filename" sed -r "s|$lib/||" < "$filename" | build-aux/write-ifchanged "$filename" done done fi find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.gperf' \) -type f | while read -r filename; do "$0"--includes "$filename" done ) main() { set -e set -o pipefail export LC_COLLATE=C fixup_makefiles "$@" fixup_includes "$@" } main "$@"