epunt-cxx.eclass: Split C++ check punting code out of eutils
[gentoo.git] / eclass / epunt-cxx.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: epunt-cxx.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @BLURB: A function to punt C++ compiler checks from autoconf
8 # @DESCRIPTION:
9 # Support for punting C++ compiler checks from autoconf (based
10 # on ELT-patches).
11
12 if [[ -z ${_EPUNT_CXX_ECLASS} ]]; then
13
14 # TODO: replace this with 'inherit eutils' once eutils stops inheriting
15 # us
16 if ! declare -F eqawarn >/dev/null ; then
17         eqawarn() {
18                 has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
19                 :
20         }
21 fi
22
23 # If an overlay has eclass overrides, but doesn't actually override the
24 # libtool.eclass, we'll have ECLASSDIR pointing to the active overlay's
25 # eclass/ dir, but libtool.eclass is still in the main Gentoo tree.  So
26 # add a check to locate the ELT-patches/ regardless of what's going on.
27 # Note: Duplicated in libtool.eclass.
28 _EUTILS_ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
29 eutils_elt_patch_dir() {
30         local d="${ECLASSDIR}/ELT-patches"
31         if [[ ! -d ${d} ]] ; then
32                 d="${_EUTILS_ECLASSDIR_LOCAL}/ELT-patches"
33         fi
34         echo "${d}"
35 }
36
37 # @FUNCTION: epunt_cxx
38 # @USAGE: [dir to scan]
39 # @DESCRIPTION:
40 # Many configure scripts wrongly bail when a C++ compiler could not be
41 # detected.  If dir is not specified, then it defaults to ${S}.
42 #
43 # https://bugs.gentoo.org/73450
44 epunt_cxx() {
45         local dir=$1
46         [[ -z ${dir} ]] && dir=${S}
47         ebegin "Removing useless C++ checks"
48         local f p any_found
49         while IFS= read -r -d '' f; do
50                 for p in "$(eutils_elt_patch_dir)"/nocxx/*.patch ; do
51                         if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
52                                 any_found=1
53                                 break
54                         fi
55                 done
56         done < <(find "${dir}" -name configure -print0)
57
58         if [[ -z ${any_found} ]]; then
59                 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
60         fi
61         eend 0
62 }
63
64 _EPUNT_CXX_ECLASS=1
65 fi #_EPUNT_CXX_ECLASS