1 # Copyright 1999-2018 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 # @SUPPORTED_EAPIS: 6 7
8 # @BLURB: convenient wrapper to build autotools packages out-of-source
10 # This eclass provides a minimalistic wrapper interface to easily
11 # build autotools (and alike) packages out-of-source. It is meant
12 # to resemble the interface used by multilib-minimal without actually
13 # requiring the package to be multilib.
15 # For the simplest ebuilds, it is enough to inherit the eclass
16 # and the new phase functions will automatically build the package
17 # out-of-source. If you need to redefine one of the default phases
18 # src_configure() through src_install(), you need to define
19 # the matching sub-phases: my_src_configure(), my_src_compile(),
20 # my_src_test() and/or my_src_install(). Those sub-phase functions
21 # will be run inside the build directory. Additionally,
22 # my_src_install_all() is provided to perform doc-install and other
23 # common tasks that are done in source directory.
27 # inherit out-of-source
29 # my_src_configure() {
37 *) die "EAPI ${EAPI:-0} unsupported (too old)";;
40 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
42 if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
44 # @FUNCTION: out-of-source_src_configure
46 # The default src_configure() implementation establishes a BUILD_DIR,
47 # sets ECONF_SOURCE to the current directory (usually S), and runs
48 # my_src_configure() (or the default) inside it.
49 out-of-source_src_configure() {
50 debug-print-function ${FUNCNAME} "$@"
52 # set some BUILD_DIR if we don't have one yet
53 : "${BUILD_DIR:=${WORKDIR}/${P}_build}"
54 local ECONF_SOURCE=${PWD}
56 mkdir -p "${BUILD_DIR}" || die
57 pushd "${BUILD_DIR}" >/dev/null || die
58 if declare -f my_src_configure >/dev/null ; then
63 popd >/dev/null || die
66 # @FUNCTION: out-of-source_src_compile
68 # The default src_compile() implementation runs my_src_compile()
69 # (or the default) inside the build directory.
70 out-of-source_src_compile() {
71 debug-print-function ${FUNCNAME} "$@"
73 pushd "${BUILD_DIR}" >/dev/null || die
74 if declare -f my_src_compile >/dev/null ; then
79 popd >/dev/null || die
82 # @FUNCTION: out-of-source_src_test
84 # The default src_test() implementation runs my_src_test()
85 # (or the default) inside the build directory.
86 out-of-source_src_test() {
87 debug-print-function ${FUNCNAME} "$@"
89 pushd "${BUILD_DIR}" >/dev/null || die
90 if declare -f my_src_test >/dev/null ; then
95 popd >/dev/null || die
98 # @FUNCTION: out-of-source_src_install
100 # The default src_install() implementation runs my_src_install()
101 # (or the 'make install' part of the default) inside the build directory,
102 # followed by a call to my_src_install_all() (or 'einstalldocs' part
103 # of the default) in the original working directory.
104 out-of-source_src_install() {
105 debug-print-function ${FUNCNAME} "$@"
107 pushd "${BUILD_DIR}" >/dev/null || die
108 if declare -f my_src_install >/dev/null ; then
111 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
112 emake DESTDIR="${D}" install
115 popd >/dev/null || die
117 if declare -f my_src_install_all >/dev/null ; then
124 _OUT_OF_SOURCE_ECLASS=1