meson.eclass: Don't mix host *FLAGS with build *FLAGS
[gentoo.git] / eclass / waf-utils.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: waf-utils.eclass
5 # @MAINTAINER:
6 # maintainer-needed@gentoo.org
7 # @AUTHOR:
8 # Original Author: Gilles Dartiguelongue <eva@gentoo.org>
9 # Various improvements based on cmake-utils.eclass: Tomáš Chvátal <scarabeus@gentoo.org>
10 # Proper prefix support: Jonathan Callen <jcallen@gentoo.org>
11 # @BLURB: common ebuild functions for waf-based packages
12 # @DESCRIPTION:
13 # The waf-utils eclass contains functions that make creating ebuild for
14 # waf-based packages much easier.
15 # Its main features are support of common portage default settings.
16
17 [[ ${EAPI} == [45] ]] && inherit eutils
18 inherit multilib toolchain-funcs multiprocessing
19
20 case ${EAPI:-0} in
21         4|5|6) EXPORT_FUNCTIONS src_configure src_compile src_install ;;
22         *) die "EAPI=${EAPI} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: WAF_VERBOSE
26 # @DESCRIPTION:
27 # Set to OFF to disable verbose messages during compilation
28 # this is _not_ meant to be set in ebuilds
29 : ${WAF_VERBOSE:=ON}
30
31 # @FUNCTION: waf-utils_src_configure
32 # @DESCRIPTION:
33 # General function for configuring with waf.
34 waf-utils_src_configure() {
35         debug-print-function ${FUNCNAME} "$@"
36
37         local fail
38         if [[ ! ${_PYTHON_ANY_R1} && ! ${_PYTHON_SINGLE_R1} && ! ${_PYTHON_R1} ]]; then
39                 eerror "Using waf-utils.eclass without any python-r1 suite eclass is not supported."
40                 eerror "Please make sure to configure and inherit appropriate -r1 eclass."
41                 eerror "For more information and examples, please see:"
42                 eerror "    https://wiki.gentoo.org/wiki/Project:Python/waf-utils_integration"
43                 fail=1
44         else
45                 if [[ ! ${EPYTHON} ]]; then
46                         eerror "EPYTHON is unset while calling waf-utils. This most likely means that"
47                         eerror "the ebuild did not call the appropriate eclass function before calling waf."
48                         if [[ ${_PYTHON_ANY_R1} ]]; then
49                                 eerror "Please ensure that python-any-r1_pkg_setup is called in pkg_setup()."
50                         elif [[ ${_PYTHON_SINGLE_R1} ]]; then
51                                 eerror "Please ensure that python-single-r1_pkg_setup is called in pkg_setup()."
52                         else # python-r1
53                                 eerror "Please ensure that python_setup is called before waf-utils_src_configure(),"
54                                 eerror "or that the latter is used within python_foreach_impl as appropriate."
55                         fi
56                         eerror
57                         fail=1
58                 fi
59
60                 if [[ ${PYTHON_REQ_USE} != *threads* ]]; then
61                         eerror "Waf requires threading support in Python. To accomodate this requirement,"
62                         eerror "please add 'threads(+)' to PYTHON_REQ_USE variable (above inherit line)."
63                         eerror "For more information and examples, please see:"
64                         eerror "    https://wiki.gentoo.org/wiki/Project:Python/waf-utils_integration"
65                         fail=1
66                 fi
67         fi
68
69         [[ ${fail} ]] && die "Invalid use of waf-utils.eclass"
70
71         local libdir=()
72
73         # @ECLASS-VARIABLE: WAF_BINARY
74         # @DESCRIPTION:
75         # Eclass can use different waf executable. Usually it is located in "${S}/waf".
76         : ${WAF_BINARY:="${S}/waf"}
77
78         # @ECLASS-VARIABLE: NO_WAF_LIBDIR
79         # @DEFAULT_UNSET
80         # @DESCRIPTION:
81         # Variable specifying that you don't want to set the libdir for waf script.
82         # Some scripts does not allow setting it at all and die if they find it.
83         [[ -z ${NO_WAF_LIBDIR} ]] && libdir=(--libdir="${EPREFIX}/usr/$(get_libdir)")
84
85         tc-export AR CC CPP CXX RANLIB
86         echo "CCFLAGS=\"${CFLAGS}\" LINKFLAGS=\"${CFLAGS} ${LDFLAGS}\" \"${WAF_BINARY}\" --prefix=${EPREFIX}/usr ${libdir[@]} $@ configure"
87
88         CCFLAGS="${CFLAGS}" LINKFLAGS="${CFLAGS} ${LDFLAGS}" "${WAF_BINARY}" \
89                 "--prefix=${EPREFIX}/usr" \
90                 "${libdir[@]}" \
91                 "$@" \
92                 configure || die "configure failed"
93 }
94
95 # @FUNCTION: waf-utils_src_compile
96 # @DESCRIPTION:
97 # General function for compiling with waf.
98 waf-utils_src_compile() {
99         debug-print-function ${FUNCNAME} "$@"
100         local _mywafconfig
101         [[ "${WAF_VERBOSE}" ]] && _mywafconfig="--verbose"
102
103         local jobs="--jobs=$(makeopts_jobs)"
104         echo "\"${WAF_BINARY}\" build ${_mywafconfig} ${jobs}"
105         "${WAF_BINARY}" ${_mywafconfig} ${jobs} || die "build failed"
106 }
107
108 # @FUNCTION: waf-utils_src_install
109 # @DESCRIPTION:
110 # Function for installing the package.
111 waf-utils_src_install() {
112         debug-print-function ${FUNCNAME} "$@"
113
114         echo "\"${WAF_BINARY}\" --destdir=\"${D}\" install"
115         "${WAF_BINARY}" --destdir="${D}" install  || die "Make install failed"
116
117         # Manual document installation
118         einstalldocs
119 }