waf-utils.eclass: Ban non-python-r1 uses
[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 # $Id$
4
5 # @ECLASS: waf-utils.eclass
6 # @MAINTAINER:
7 # maintainer-needed@gentoo.org
8 # @AUTHOR:
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
13 # @DESCRIPTION:
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.
17
18 inherit eutils 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 # 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.
28 DEPEND="${DEPEND}
29         dev-lang/python
30         !dev-lang/python[-threads]"
31
32 # @ECLASS-VARIABLE: WAF_VERBOSE
33 # @DESCRIPTION:
34 # Set to OFF to disable verbose messages during compilation
35 # this is _not_ meant to be set in ebuilds
36 : ${WAF_VERBOSE:=ON}
37
38 # @FUNCTION: waf-utils_src_configure
39 # @DESCRIPTION:
40 # General function for configuring with waf.
41 waf-utils_src_configure() {
42         debug-print-function ${FUNCNAME} "$@"
43
44         local fail
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"
50                 fail=1
51         else
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()."
59                         else # python-r1
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."
62                         fi
63                         eerror
64                         fail=1
65                 fi
66
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"
72                         fail=1
73                 fi
74         fi
75
76         [[ ${fail} ]] || die "Invalid use of ${ECLASS}"
77
78         local libdir=""
79
80         # @ECLASS-VARIABLE: WAF_BINARY
81         # @DESCRIPTION:
82         # Eclass can use different waf executable. Usually it is located in "${S}/waf".
83         : ${WAF_BINARY:="${S}/waf"}
84
85         # @ECLASS-VARIABLE: NO_WAF_LIBDIR
86         # @DEFAULT_UNSET
87         # @DESCRIPTION:
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)"
91
92         tc-export AR CC CPP CXX RANLIB
93         echo "CCFLAGS=\"${CFLAGS}\" LINKFLAGS=\"${CFLAGS} ${LDFLAGS}\" \"${WAF_BINARY}\" --prefix=${EPREFIX}/usr ${libdir} $@ configure"
94
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" \
100                         "${libdir}" \
101                         "$@" \
102                         configure || die "configure failed"
103         else
104                 CCFLAGS="${CFLAGS}" LINKFLAGS="${CFLAGS} ${LDFLAGS}" "${WAF_BINARY}" \
105                         "--prefix=${EPREFIX}/usr" \
106                         "$@" \
107                         configure || die "configure failed"
108         fi
109 }
110
111 # @FUNCTION: waf-utils_src_compile
112 # @DESCRIPTION:
113 # General function for compiling with waf.
114 waf-utils_src_compile() {
115         debug-print-function ${FUNCNAME} "$@"
116         local _mywafconfig
117         [[ "${WAF_VERBOSE}" ]] && _mywafconfig="--verbose"
118
119         local jobs="--jobs=$(makeopts_jobs)"
120         echo "\"${WAF_BINARY}\" build ${_mywafconfig} ${jobs}"
121         "${WAF_BINARY}" ${_mywafconfig} ${jobs} || die "build failed"
122 }
123
124 # @FUNCTION: waf-utils_src_install
125 # @DESCRIPTION:
126 # Function for installing the package.
127 waf-utils_src_install() {
128         debug-print-function ${FUNCNAME} "$@"
129
130         echo "\"${WAF_BINARY}\" --destdir=\"${D}\" install"
131         "${WAF_BINARY}" --destdir="${D}" install  || die "Make install failed"
132
133         # Manual document installation
134         einstalldocs
135 }