kde5.eclass: Add KDE_PO_DIRS
[gentoo.git] / eclass / out-of-source.eclass
1 # Copyright 1999-2017 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 # @BLURB: convenient wrapper to build autotools packages out-of-source
8 # @DESCRIPTION:
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.
13 #
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.
23 #
24 # Example use:
25 # @CODE
26 # inherit out-of-source
27 #
28 # my_src_configure() {
29 #     econf \
30 #         --disable-static
31 # }
32 # @CODE
33
34 case ${EAPI} in
35         6);;
36         *) die "EAPI ${EAPI:-0} unsupported (too old)";;
37 esac
38
39 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
40
41 if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
42
43 # @FUNCTION: out-of-source_src_configure
44 # @DESCRIPTION:
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} "$@"
50
51         # set some BUILD_DIR if we don't have one yet
52         : "${BUILD_DIR:=${WORKDIR}/${P}_build}"
53         local ECONF_SOURCE=${PWD}
54
55         mkdir -p "${BUILD_DIR}" || die
56         pushd "${BUILD_DIR}" >/dev/null || die
57         if declare -f my_src_configure >/dev/null ; then
58                 my_src_configure
59         else
60                 default_src_configure
61         fi
62         popd >/dev/null || die
63 }
64
65 # @FUNCTION: out-of-source_src_compile
66 # @DESCRIPTION:
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} "$@"
71
72         pushd "${BUILD_DIR}" >/dev/null || die
73         if declare -f my_src_compile >/dev/null ; then
74                 my_src_compile
75         else
76                 default_src_compile
77         fi
78         popd >/dev/null || die
79 }
80
81 # @FUNCTION: out-of-source_src_test
82 # @DESCRIPTION:
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} "$@"
87
88         pushd "${BUILD_DIR}" >/dev/null || die
89         if declare -f my_src_test >/dev/null ; then
90                 my_src_test
91         else
92                 default_src_test
93         fi
94         popd >/dev/null || die
95 }
96
97 # @FUNCTION: out-of-source_src_install
98 # @DESCRIPTION:
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} "$@"
105
106         pushd "${BUILD_DIR}" >/dev/null || die
107         if declare -f my_src_install >/dev/null ; then
108                 my_src_install
109         else
110                 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
111                         emake DESTDIR="${D}" install
112                 fi
113         fi
114         popd >/dev/null || die
115
116         if declare -f my_src_install_all >/dev/null ; then
117                 my_src_install_all
118         else
119                 einstalldocs
120         fi
121 }
122
123 _OUT_OF_SOURCE_ECLASS=1
124 fi