# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: package/.../automake/parse-config
# Copyright (C) 2004 - 2007 The T2 SDE Project
# Copyright (C) 1998 - 2003 ROCK Linux Project
# 
# More information can be found in the files COPYING and README.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- T2-COPYRIGHT-NOTE-END ---

# If an application is running automake, it includes all the stuff
# from usr/share/aclocal/ and so depends on all packages placing
# something there.
#
# We can savely ignore those dependencies, since a package which is really
# using an others package aclocal file will also access other files related
# to the package outside of usr/share/aclocal.
#
var_append flistrfilter "|" ".*:	.*/share/aclocal/.*"

automake_fixup() {
	# do not do anything if we're outside builddir (like sysfiles is)
	[[ ${PWD//src.$pkg.$config.$id/} = $PWD ]] && return

	local pref=$root
	if ! atstage native; then
		pref=$base/build/$SDECFG_ID/TOOLCHAIN/tools.cross
	fi

	if [ -d $pref/usr/share/automake/ ]; then
		# search (recursively) for the files
		find -name config.guess -o -name config.sub -o \
		     -name configfsf.guess  -o -name configfsf.sub |
		while read file; do
		  if grep -q Autoconf $file ; then
			echo "Updating $file"
			local f=${file##*/}; f=${f/fsf/}
			cp -fv $pref/usr/share/automake/$f $file
		  fi
		done
	fi
}

# some packages do not include an up-to-date config.{sub,guess}
if hasflag AUTOMAKE-QUIRK ||
   [ $arch = 'avr32' ] || [ $arch = 'blackfin' ]; then
	hook_add preconf 2 automake_fixup
fi
