1 |
commit: 333acdfca16e2dfef81f65ddc6fce8e91405b8ac |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Aug 12 22:15:48 2017 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Nov 20 17:34:02 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=333acdfc |
7 |
|
8 |
out-of-source.eclass: A new eclass to help with out-of-source builds |
9 |
|
10 |
The out-of-source.eclass is a simple multilib-minimal-style wrapper |
11 |
to perform out of source builds of autotools (and other) packages. It is |
12 |
mostly derived from the function served in the past by autotools-utils |
13 |
since a number of developers found it useful. However, in order to avoid |
14 |
the mistakes of autotools-utils, it is meant to be focused on a single |
15 |
feature and have a better API. |
16 |
|
17 |
This eclass has two use cases: |
18 |
|
19 |
1. Ensuring that packages are tested with out-of-source builds. |
20 |
|
21 |
2. Improving consistency between multilib and non-multilib packages. |
22 |
|
23 |
In the most basic form, it just redefines the phases from src_configure() |
24 |
to src_install() with out-of-source wrappers. However, each phase can |
25 |
be overriden using my_src_*() sub-phase that is run inside build dir |
26 |
(alike multilib_src_*() in multilib-minimal). There is also |
27 |
my_src_install_all() for the trailing source-dir actions. |
28 |
|
29 |
eclass/out-of-source.eclass | 124 ++++++++++++++++++++++++++++++++++++++++++++ |
30 |
1 file changed, 124 insertions(+) |
31 |
|
32 |
diff --git a/eclass/out-of-source.eclass b/eclass/out-of-source.eclass |
33 |
new file mode 100644 |
34 |
index 00000000000..4d9c8d05fd6 |
35 |
--- /dev/null |
36 |
+++ b/eclass/out-of-source.eclass |
37 |
@@ -0,0 +1,124 @@ |
38 |
+# Copyright 1999-2017 Gentoo Foundation |
39 |
+# Distributed under the terms of the GNU General Public License v2 |
40 |
+ |
41 |
+# @ECLASS: out-of-source.eclass |
42 |
+# @MAINTAINER: |
43 |
+# Michał Górny <mgorny@g.o> |
44 |
+# @BLURB: convenient wrapper to build autotools packages out-of-source |
45 |
+# @DESCRIPTION: |
46 |
+# This eclass provides a minimalistic wrapper interface to easily |
47 |
+# build autotools (and alike) packages out-of-source. It is meant |
48 |
+# to resemble the interface used by multilib-minimal without actually |
49 |
+# requiring the package to be multilib. |
50 |
+# |
51 |
+# For the simplest ebuilds, it is enough to inherit the eclass |
52 |
+# and the new phase functions will automatically build the package |
53 |
+# out-of-source. If you need to redefine one of the default phases |
54 |
+# src_configure() through src_install(), you need to define |
55 |
+# the matching sub-phases: my_src_configure(), my_src_compile(), |
56 |
+# my_src_test() and/or my_src_install(). Those sub-phase functions |
57 |
+# will be run inside the build directory. Additionally, |
58 |
+# my_src_install_all() is provided to perform doc-install and other |
59 |
+# common tasks that are done in source directory. |
60 |
+# |
61 |
+# Example use: |
62 |
+# @CODE |
63 |
+# inherit out-of-source |
64 |
+# |
65 |
+# my_src_configure() { |
66 |
+# econf \ |
67 |
+# --disable-static |
68 |
+# } |
69 |
+# @CODE |
70 |
+ |
71 |
+case ${EAPI} in |
72 |
+ 6);; |
73 |
+ *) die "EAPI ${EAPI:-0} unsupported (too old)";; |
74 |
+esac |
75 |
+ |
76 |
+EXPORT_FUNCTIONS src_configure src_compile src_test src_install |
77 |
+ |
78 |
+if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then |
79 |
+ |
80 |
+# @FUNCTION: out-of-source_src_configure |
81 |
+# @DESCRIPTION: |
82 |
+# The default src_configure() implementation establishes a BUILD_DIR, |
83 |
+# sets ECONF_SOURCE to the current directory (usually S), and runs |
84 |
+# my_src_configure() (or the default) inside it. |
85 |
+out-of-source_src_configure() { |
86 |
+ debug-print-function ${FUNCNAME} "$@" |
87 |
+ |
88 |
+ # set some BUILD_DIR if we don't have one yet |
89 |
+ : "${BUILD_DIR:=${WORKDIR}/${P}_build}" |
90 |
+ local ECONF_SOURCE=${PWD} |
91 |
+ |
92 |
+ mkdir -p "${BUILD_DIR}" || die |
93 |
+ pushd "${BUILD_DIR}" >/dev/null || die |
94 |
+ if declare -f my_src_configure >/dev/null ; then |
95 |
+ my_src_configure |
96 |
+ else |
97 |
+ default_src_configure |
98 |
+ fi |
99 |
+ popd >/dev/null || die |
100 |
+} |
101 |
+ |
102 |
+# @FUNCTION: out-of-source_src_compile |
103 |
+# @DESCRIPTION: |
104 |
+# The default src_compile() implementation runs my_src_compile() |
105 |
+# (or the default) inside the build directory. |
106 |
+out-of-source_src_compile() { |
107 |
+ debug-print-function ${FUNCNAME} "$@" |
108 |
+ |
109 |
+ pushd "${BUILD_DIR}" >/dev/null || die |
110 |
+ if declare -f my_src_compile >/dev/null ; then |
111 |
+ my_src_compile |
112 |
+ else |
113 |
+ default_src_compile |
114 |
+ fi |
115 |
+ popd >/dev/null || die |
116 |
+} |
117 |
+ |
118 |
+# @FUNCTION: out-of-source_src_test |
119 |
+# @DESCRIPTION: |
120 |
+# The default src_test() implementation runs my_src_test() |
121 |
+# (or the default) inside the build directory. |
122 |
+out-of-source_src_test() { |
123 |
+ debug-print-function ${FUNCNAME} "$@" |
124 |
+ |
125 |
+ pushd "${BUILD_DIR}" >/dev/null || die |
126 |
+ if declare -f my_src_test >/dev/null ; then |
127 |
+ my_src_test |
128 |
+ else |
129 |
+ default_src_test |
130 |
+ fi |
131 |
+ popd >/dev/null || die |
132 |
+} |
133 |
+ |
134 |
+# @FUNCTION: out-of-source_src_install |
135 |
+# @DESCRIPTION: |
136 |
+# The default src_install() implementation runs my_src_install() |
137 |
+# (or the 'make install' part of the default) inside the build directory, |
138 |
+# followed by a call to my_src_install_all() (or 'einstalldocs' part |
139 |
+# of the default) in the original working directory. |
140 |
+out-of-source_src_install() { |
141 |
+ debug-print-function ${FUNCNAME} "$@" |
142 |
+ |
143 |
+ pushd "${BUILD_DIR}" >/dev/null || die |
144 |
+ if declare -f my_src_install >/dev/null ; then |
145 |
+ my_src_install |
146 |
+ else |
147 |
+ if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then |
148 |
+ emake DESTDIR="${D}" install |
149 |
+ fi |
150 |
+ fi |
151 |
+ popd >/dev/null || die |
152 |
+ |
153 |
+ if declare -f my_src_install_all >/dev/null ; then |
154 |
+ my_src_install_all |
155 |
+ else |
156 |
+ einstalldocs |
157 |
+ fi |
158 |
+} |
159 |
+ |
160 |
+_OUT_OF_SOURCE_ECLASS=1 |
161 |
+fi |