1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: waf-utils.eclass
7 # maintainer-needed@gentoo.org
9 # Original Author: Gilles Dartiguelongue <eva@gentoo.org>
10 # Various improvements based on cmake-utils.eclass: Tomáš Chvátal <scarabeus@gentoo.org>
11 # Proper prefix support: Jonathan Callen <jcallen@gentoo.org>
12 # @BLURB: common ebuild functions for waf-based packages
14 # The waf-utils eclass contains functions that make creating ebuild for
15 # waf-based packages much easier.
16 # Its main features are support of common portage default settings.
18 inherit eutils multilib toolchain-funcs multiprocessing
21 4|5|6) EXPORT_FUNCTIONS src_configure src_compile src_install ;;
22 *) die "EAPI=${EAPI} is not supported" ;;
25 # Python with threads is required to run waf. We do not know which python slot
26 # is being used as the system interpreter, so we are forced to block all
27 # slots that have USE=-threads.
30 !dev-lang/python[-threads]"
32 # @ECLASS-VARIABLE: WAF_VERBOSE
34 # Set to OFF to disable verbose messages during compilation
35 # this is _not_ meant to be set in ebuilds
38 # @FUNCTION: waf-utils_src_configure
40 # General function for configuring with waf.
41 waf-utils_src_configure() {
42 debug-print-function ${FUNCNAME} "$@"
45 if [[ ! ${_PYTHON_ANY_R1} && ! ${_PYTHON_SINGLE_R1} && ! ${_PYTHON_R1} ]]; then
46 eerror "Using waf-utils.eclass without any python-r1 suite eclass is not supported."
47 eerror "Please make sure to configure and inherit appropriate -r1 eclass."
48 eerror "For more information and examples, please see:"
49 eerror " https://wiki.gentoo.org/wiki/Project:Python/waf-utils_integration"
52 if [[ ! ${EPYTHON} ]]; then
53 eerror "EPYTHON is unset while calling waf-utils. This most likely means that"
54 eerror "the ebuild did not call the appropriate eclass function before calling waf."
55 if [[ ${_PYTHON_ANY_R1} ]]; then
56 eerror "Please ensure that python-any-r1_pkg_setup is called in pkg_setup()."
57 elif [[ ${_PYTHON_SINGLE_R1} ]]; then
58 eerror "Please ensure that python-single-r1_pkg_setup is called in pkg_setup()."
60 eerror "Please ensure that python_setup is called before waf-utils_src_configure(),"
61 eerror "or that the latter is used within python_foreach_impl as appropriate."
67 if [[ ${PYTHON_REQ_USE} != *threads* ]]; then
68 eerror "Waf requires threading support in Python. To accomodate this requirement,"
69 eerror "please add 'threads(+)' to PYTHON_REQ_USE variable (above inherit line)."
70 eerror "For more information and examples, please see:"
71 eerror " https://wiki.gentoo.org/wiki/Project:Python/waf-utils_integration"
76 [[ ${fail} ]] || die "Invalid use of ${ECLASS}"
80 # @ECLASS-VARIABLE: WAF_BINARY
82 # Eclass can use different waf executable. Usually it is located in "${S}/waf".
83 : ${WAF_BINARY:="${S}/waf"}
85 # @ECLASS-VARIABLE: NO_WAF_LIBDIR
88 # Variable specifying that you don't want to set the libdir for waf script.
89 # Some scripts does not allow setting it at all and die if they find it.
90 [[ -z ${NO_WAF_LIBDIR} ]] && libdir="--libdir=${EPREFIX}/usr/$(get_libdir)"
92 tc-export AR CC CPP CXX RANLIB
93 echo "CCFLAGS=\"${CFLAGS}\" LINKFLAGS=\"${CFLAGS} ${LDFLAGS}\" \"${WAF_BINARY}\" --prefix=${EPREFIX}/usr ${libdir} $@ configure"
95 # This condition is required because waf takes even whitespace as function
96 # calls, awesome isn't it?
97 if [[ -z ${NO_WAF_LIBDIR} ]]; then
98 CCFLAGS="${CFLAGS}" LINKFLAGS="${CFLAGS} ${LDFLAGS}" "${WAF_BINARY}" \
99 "--prefix=${EPREFIX}/usr" \
102 configure || die "configure failed"
104 CCFLAGS="${CFLAGS}" LINKFLAGS="${CFLAGS} ${LDFLAGS}" "${WAF_BINARY}" \
105 "--prefix=${EPREFIX}/usr" \
107 configure || die "configure failed"
111 # @FUNCTION: waf-utils_src_compile
113 # General function for compiling with waf.
114 waf-utils_src_compile() {
115 debug-print-function ${FUNCNAME} "$@"
117 [[ "${WAF_VERBOSE}" ]] && _mywafconfig="--verbose"
119 local jobs="--jobs=$(makeopts_jobs)"
120 echo "\"${WAF_BINARY}\" build ${_mywafconfig} ${jobs}"
121 "${WAF_BINARY}" ${_mywafconfig} ${jobs} || die "build failed"
124 # @FUNCTION: waf-utils_src_install
126 # Function for installing the package.
127 waf-utils_src_install() {
128 debug-print-function ${FUNCNAME} "$@"
130 echo "\"${WAF_BINARY}\" --destdir=\"${D}\" install"
131 "${WAF_BINARY}" --destdir="${D}" install || die "Make install failed"
133 # Manual document installation