summaryrefslogtreecommitdiffstats
path: root/autogen.sh
blob: 39eb82203d69a9b582acfbe2d89e9947d86c5937 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
[ "${0%/*}" = "$0" ] || cd "${0%/*}" || exit

# %reldir%/%canon_reldir% (%D%/%C%) only appeared in automake 1.14, but RHEL/CentOS 7 has 1.13.4
# This is an (overly) simplistic preprocessor that papers around this for the duration of the generation step,
# and can be removed once support for CentOS 7 is dropped
automake --version | awk '{print $NF; exit}' | (
	IFS=. read -r AM_MAJ AM_MIN _
	[ "$AM_MAJ" -gt 1 ] || [ "$AM_MIN" -ge 14 ]
) || {
	process_root() {
		root="$1"; shift

		grep -q '%[CD]%' "$root/Makefile.am" || return
		find "$root" -name Makefile.am "$@" | while read -r dir; do
			dir="${dir%/Makefile.am}"
			grep -q '%[CD]%' "$dir/Makefile.am" || continue

			reldir="${dir#"$root"}"
			reldir="${reldir#/}"

			canon_reldir="$(printf '%s' "$reldir" | tr -C 'a-zA-Z0-9@_' '_')"

			reldir_slash="$reldir/"
			canon_reldir_slash="${canon_reldir}_"
			[ -z "$reldir" ] && reldir_slash=
			[ -z "$reldir" ] && canon_reldir_slash=

			echo "$dir/Makefile.am" >&3
			sed -i~ -e "s:%D%/:$reldir_slash:g"       -e "s:%D%:$reldir:g" \
			        -e "s:%C%_:$canon_reldir_slash:g" -e "s:%C%:$canon_reldir:g" "$dir/Makefile.am"
		done 3>>"$substituted_files"
	}

	rollback() {
		while read -r f; do
			mv "$f~" "$f"
		done < "$substituted_files"
		rm -f "$substituted_files"
	}


	echo "Automake <1.14; papering over missing %reldir%/%canon_reldir% support" >&2

	substituted_files="$(mktemp)"
	trap rollback EXIT

	roots="$(sed '/Makefile$/!d;/module/d;s:^\s*:./:;s:/Makefile::;/^\.$/d' configure.ac)"

	IFS="
"
	for root in $roots; do
		root="${root#./}"
		process_root "$root"
	done

	set -f
	# shellcheck disable=SC2086,SC2046
	process_root . $(printf '!\n-path\n%s/*\n' $roots)
}

autoreconf -fiv && rm -rf autom4te.cache