x11-misc/alock: Take ownership of package
[gentoo.git] / eclass / gnuconfig.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 #
5 # THIS ECLASS IS DEAD: It has been integrated into portage
6 #
7 # Author: Will Woods <wwoods@gentoo.org>
8 #
9 # This eclass is used to automatically update files that typically come with
10 # automake to the newest version available on the system. The most common use
11 # of this is to update config.guess and config.sub when configure dies from
12 # misguessing your canonical system name (CHOST). It can also be used to update
13 # other files that come with automake, e.g. depcomp, mkinstalldirs, etc.
14 #
15 # usage: gnuconfig_update [file1 file2 ...]
16 # if called without arguments, config.guess and config.sub will be updated.
17 # All files in the source tree ($S) with the given name(s) will be replaced
18 # with the newest available versions chosen from the list of locations in
19 # gnuconfig_findnewest(), below.
20 #
21 # gnuconfig_update should generally be called from src_unpack()
22
23
24 DEPEND="sys-devel/gnuconfig"
25
26 # Wrapper function for gnuconfig_do_update. If no arguments are given, update
27 # config.sub and config.guess (old default behavior), otherwise update the
28 # named files.
29 gnuconfig_update() {
30
31 # hmm some packages (like binutils gcc glibc) still use this ...
32 #       echo
33 #       ewarn "QA Notice: Please stop using me, portage updates files for you."
34 #       echo
35
36         local startdir  # declared here ... used in gnuconfig_do_update
37
38         if [[ $1 == /* ]] ; then
39                 startdir=$1
40                 shift
41         else
42                 startdir=${S}
43         fi
44
45         if [[ $# -gt 0 ]] ; then
46                 gnuconfig_do_update "$@"
47         else
48                 gnuconfig_do_update config.sub config.guess
49         fi
50
51         return $?
52 }
53
54 # Copy the newest available version of specified files over any old ones in the
55 # source dir. This function shouldn't be called directly - use gnuconfig_update
56 #
57 # Note that since bash using dynamic scoping, startdir is available here from
58 # the gnuconfig_update function
59 gnuconfig_do_update() {
60         local configsubs_dir target targetlist file
61
62         [[ $# -eq 0 ]] && die "do not call gnuconfig_do_update; use gnuconfig_update"
63
64         configsubs_dir=$(gnuconfig_findnewest)
65         einfo "Using GNU config files from ${configsubs_dir}"
66         for file in "$@" ; do
67                 if [[ ! -r ${configsubs_dir}/${file} ]] ; then
68                         eerror "Can't read ${configsubs_dir}/${file}, skipping.."
69                         continue
70                 fi
71                 targetlist=$(find "${startdir}" -name "${file}")
72                 if [[ -n ${targetlist} ]] ; then
73                         for target in ${targetlist} ; do
74                                 [[ -L ${target} ]] && rm -f "${target}"
75                                 einfo "  Updating ${target/$startdir\//}"
76                                 cp -f "${configsubs_dir}/${file}" "${target}"
77                                 eend $?
78                         done
79                 else
80                         ewarn "  No ${file} found in ${startdir}, skipping ..."
81                 fi
82         done
83
84         return 0
85 }
86
87 # this searches the standard locations for the newest config.{sub|guess}, and
88 # returns the directory where they can be found.
89 gnuconfig_findnewest() {
90         local locations=(
91                 "${EPREFIX}"/usr/share/misc/config.sub
92                 "${EPREFIX}"/usr/share/gnuconfig/config.sub
93                 "${EPREFIX}"/usr/share/automake*/config.sub
94                 "${EPREFIX}"/usr/share/libtool/config.sub
95         )
96         grep -s '^timestamp' "${locations[@]}" | \
97                 sort -r -n -t\' -k2 | \
98                 sed -n '1{s,/config.sub:.*$,,;p;q}'
99 }