1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: out-of-source.eclass
6 # Michał Górny <mgorny@gentoo.org>
7 # @BLURB: convenient wrapper to build autotools packages out-of-source
9 # This eclass provides a minimalistic wrapper interface to easily
10 # build autotools (and alike) packages out-of-source. It is meant
11 # to resemble the interface used by multilib-minimal without actually
12 # requiring the package to be multilib.
14 # For the simplest ebuilds, it is enough to inherit the eclass
15 # and the new phase functions will automatically build the package
16 # out-of-source. If you need to redefine one of the default phases
17 # src_configure() through src_install(), you need to define
18 # the matching sub-phases: my_src_configure(), my_src_compile(),
19 # my_src_test() and/or my_src_install(). Those sub-phase functions
20 # will be run inside the build directory. Additionally,
21 # my_src_install_all() is provided to perform doc-install and other
22 # common tasks that are done in source directory.
26 # inherit out-of-source
28 # my_src_configure() {
36 *) die "EAPI ${EAPI:-0} unsupported (too old)";;
39 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
41 if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
43 # @FUNCTION: out-of-source_src_configure
45 # The default src_configure() implementation establishes a BUILD_DIR,
46 # sets ECONF_SOURCE to the current directory (usually S), and runs
47 # my_src_configure() (or the default) inside it.
48 out-of-source_src_configure() {
49 debug-print-function ${FUNCNAME} "$@"
51 # set some BUILD_DIR if we don't have one yet
52 : "${BUILD_DIR:=${WORKDIR}/${P}_build}"
53 local ECONF_SOURCE=${PWD}
55 mkdir -p "${BUILD_DIR}" || die
56 pushd "${BUILD_DIR}" >/dev/null || die
57 if declare -f my_src_configure >/dev/null ; then
62 popd >/dev/null || die
65 # @FUNCTION: out-of-source_src_compile
67 # The default src_compile() implementation runs my_src_compile()
68 # (or the default) inside the build directory.
69 out-of-source_src_compile() {
70 debug-print-function ${FUNCNAME} "$@"
72 pushd "${BUILD_DIR}" >/dev/null || die
73 if declare -f my_src_compile >/dev/null ; then
78 popd >/dev/null || die
81 # @FUNCTION: out-of-source_src_test
83 # The default src_test() implementation runs my_src_test()
84 # (or the default) inside the build directory.
85 out-of-source_src_test() {
86 debug-print-function ${FUNCNAME} "$@"
88 pushd "${BUILD_DIR}" >/dev/null || die
89 if declare -f my_src_test >/dev/null ; then
94 popd >/dev/null || die
97 # @FUNCTION: out-of-source_src_install
99 # The default src_install() implementation runs my_src_install()
100 # (or the 'make install' part of the default) inside the build directory,
101 # followed by a call to my_src_install_all() (or 'einstalldocs' part
102 # of the default) in the original working directory.
103 out-of-source_src_install() {
104 debug-print-function ${FUNCNAME} "$@"
106 pushd "${BUILD_DIR}" >/dev/null || die
107 if declare -f my_src_install >/dev/null ; then
110 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
111 emake DESTDIR="${D}" install
114 popd >/dev/null || die
116 if declare -f my_src_install_all >/dev/null ; then
123 _OUT_OF_SOURCE_ECLASS=1