zvol_os: fix build on Linux <3.13
[zfs.git] / autogen.sh
blob39eb82203d69a9b582acfbe2d89e9947d86c5937
1 #!/bin/sh
2 [ "${0%/*}" = "$0" ] || cd "${0%/*}" || exit
4 # %reldir%/%canon_reldir% (%D%/%C%) only appeared in automake 1.14, but RHEL/CentOS 7 has 1.13.4
5 # This is an (overly) simplistic preprocessor that papers around this for the duration of the generation step,
6 # and can be removed once support for CentOS 7 is dropped
7 automake --version | awk '{print $NF; exit}' | (
8 IFS=. read -r AM_MAJ AM_MIN _
9 [ "$AM_MAJ" -gt 1 ] || [ "$AM_MIN" -ge 14 ]
10 ) || {
11 process_root() {
12 root="$1"; shift
14 grep -q '%[CD]%' "$root/Makefile.am" || return
15 find "$root" -name Makefile.am "$@" | while read -r dir; do
16 dir="${dir%/Makefile.am}"
17 grep -q '%[CD]%' "$dir/Makefile.am" || continue
19 reldir="${dir#"$root"}"
20 reldir="${reldir#/}"
22 canon_reldir="$(printf '%s' "$reldir" | tr -C 'a-zA-Z0-9@_' '_')"
24 reldir_slash="$reldir/"
25 canon_reldir_slash="${canon_reldir}_"
26 [ -z "$reldir" ] && reldir_slash=
27 [ -z "$reldir" ] && canon_reldir_slash=
29 echo "$dir/Makefile.am" >&3
30 sed -i~ -e "s:%D%/:$reldir_slash:g" -e "s:%D%:$reldir:g" \
31 -e "s:%C%_:$canon_reldir_slash:g" -e "s:%C%:$canon_reldir:g" "$dir/Makefile.am"
32 done 3>>"$substituted_files"
35 rollback() {
36 while read -r f; do
37 mv "$f~" "$f"
38 done < "$substituted_files"
39 rm -f "$substituted_files"
43 echo "Automake <1.14; papering over missing %reldir%/%canon_reldir% support" >&2
45 substituted_files="$(mktemp)"
46 trap rollback EXIT
48 roots="$(sed '/Makefile$/!d;/module/d;s:^\s*:./:;s:/Makefile::;/^\.$/d' configure.ac)"
50 IFS="
52 for root in $roots; do
53 root="${root#./}"
54 process_root "$root"
55 done
57 set -f
58 # shellcheck disable=SC2086,SC2046
59 process_root . $(printf '!\n-path\n%s/*\n' $roots)
62 autoreconf -fiv && rm -rf autom4te.cache