dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / out-of-source.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: out-of-source.eclass
5 # @MAINTAINER:
6 # Michał Górny <mgorny@gentoo.org>
7 # @SUPPORTED_EAPIS: 6 7
8 # @BLURB: convenient wrapper to build autotools packages out-of-source
9 # @DESCRIPTION:
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.
14 #
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.
24 #
25 # Example use:
26 # @CODE
27 # inherit out-of-source
28 #
29 # my_src_configure() {
30 #     econf \
31 #         --disable-static
32 # }
33 # @CODE
34
35 case ${EAPI} in
36         6|7);;
37         *) die "EAPI ${EAPI:-0} unsupported (too old)";;
38 esac
39
40 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
41
42 if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
43
44 # @FUNCTION: out-of-source_src_configure
45 # @DESCRIPTION:
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} "$@"
51
52         # set some BUILD_DIR if we don't have one yet
53         : "${BUILD_DIR:=${WORKDIR}/${P}_build}"
54         local ECONF_SOURCE=${PWD}
55
56         mkdir -p "${BUILD_DIR}" || die
57         pushd "${BUILD_DIR}" >/dev/null || die
58         if declare -f my_src_configure >/dev/null ; then
59                 my_src_configure
60         else
61                 default_src_configure
62         fi
63         popd >/dev/null || die
64 }
65
66 # @FUNCTION: out-of-source_src_compile
67 # @DESCRIPTION:
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} "$@"
72
73         pushd "${BUILD_DIR}" >/dev/null || die
74         if declare -f my_src_compile >/dev/null ; then
75                 my_src_compile
76         else
77                 default_src_compile
78         fi
79         popd >/dev/null || die
80 }
81
82 # @FUNCTION: out-of-source_src_test
83 # @DESCRIPTION:
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} "$@"
88
89         pushd "${BUILD_DIR}" >/dev/null || die
90         if declare -f my_src_test >/dev/null ; then
91                 my_src_test
92         else
93                 default_src_test
94         fi
95         popd >/dev/null || die
96 }
97
98 # @FUNCTION: out-of-source_src_install
99 # @DESCRIPTION:
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} "$@"
106
107         pushd "${BUILD_DIR}" >/dev/null || die
108         if declare -f my_src_install >/dev/null ; then
109                 my_src_install
110         else
111                 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
112                         emake DESTDIR="${D}" install
113                 fi
114         fi
115         popd >/dev/null || die
116
117         if declare -f my_src_install_all >/dev/null ; then
118                 my_src_install_all
119         else
120                 einstalldocs
121         fi
122 }
123
124 _OUT_OF_SOURCE_ECLASS=1
125 fi