1#!/bin/sh 2[ "${0%/*}" = "$0" ] || cd "${0%/*}" || exit 3 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 7automake --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 13 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 18 19 reldir="${dir#$root}" 20 reldir="${reldir#/}" 21 22 canon_reldir="$(printf '%s' "$reldir" | tr -C 'a-zA-Z0-9@_' '_')" 23 24 reldir_slash="$reldir/" 25 canon_reldir_slash="${canon_reldir}_" 26 [ -z "$reldir" ] && reldir_slash= 27 [ -z "$reldir" ] && canon_reldir_slash= 28 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" 33 } 34 35 rollback() { 36 while read -r f; do 37 mv "$f~" "$f" 38 done < "$substituted_files" 39 rm -f "$substituted_files" 40 } 41 42 43 echo "Automake <1.14; papering over missing %reldir%/%canon_reldir% support" >&2 44 45 substituted_files="$(mktemp)" 46 trap rollback EXIT 47 48 roots="$(sed '/Makefile$/!d;/module/d;s:^\s*:./:;s:/Makefile::;/^\.$/d' configure.ac)" 49 50 IFS=" 51" 52 for root in $roots; do 53 root="${root#./}" 54 process_root "$root" 55 done 56 57 set -f 58 # shellcheck disable=SC2086,SC2046 59 process_root . $(printf '!\n-path\n%s/*\n' $roots) 60} 61 62autoreconf -fiv && rm -rf autom4te.cache 63