summaryrefslogtreecommitdiff
blob: 81e03f3894db34ed5157698c63d3d7f44b91ada1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: out-of-source.eclass
# @MAINTAINER:
# Michał Górny <mgorny@gentoo.org>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: convenient wrapper to build autotools packages out-of-source
# @DESCRIPTION:
# This eclass provides a minimalistic wrapper interface to easily
# build autotools (and alike) packages out-of-source. It is meant
# to resemble the interface used by multilib-minimal without actually
# requiring the package to be multilib.
#
# For the simplest ebuilds, it is enough to inherit the eclass
# and the new phase functions will automatically build the package
# out-of-source. If you need to redefine one of the default phases
# src_configure() through src_install(), you need to define
# the matching sub-phases: my_src_configure(), my_src_compile(),
# my_src_test() and/or my_src_install(). Those sub-phase functions
# will be run inside the build directory. Additionally,
# my_src_install_all() is provided to perform doc-install and other
# common tasks that are done in source directory.
#
# Example use:
# @CODE
# inherit out-of-source
#
# my_src_configure() {
#     econf \
#         --disable-static
# }
# @CODE

case ${EAPI} in
	7|8);;
	*) die "EAPI ${EAPI:-0} unsupported (too old)";;
esac

if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
_OUT_OF_SOURCE_ECLASS=1

# @FUNCTION: out-of-source_src_configure
# @DESCRIPTION:
# The default src_configure() implementation establishes a BUILD_DIR,
# sets ECONF_SOURCE to the current directory (usually S), and runs
# my_src_configure() (or the default) inside it.
out-of-source_src_configure() {
	debug-print-function ${FUNCNAME} "$@"

	# set some BUILD_DIR if we don't have one yet
	: "${BUILD_DIR:=${WORKDIR}/${P}_build}"
	local ECONF_SOURCE=${PWD}

	mkdir -p "${BUILD_DIR}" || die
	pushd "${BUILD_DIR}" >/dev/null || die
	if declare -f my_src_configure >/dev/null ; then
		my_src_configure
	else
		default_src_configure
	fi
	popd >/dev/null || die
}

# @FUNCTION: out-of-source_src_compile
# @DESCRIPTION:
# The default src_compile() implementation runs my_src_compile()
# (or the default) inside the build directory.
out-of-source_src_compile() {
	debug-print-function ${FUNCNAME} "$@"

	pushd "${BUILD_DIR}" >/dev/null || die
	if declare -f my_src_compile >/dev/null ; then
		my_src_compile
	else
		default_src_compile
	fi
	popd >/dev/null || die
}

# @FUNCTION: out-of-source_src_test
# @DESCRIPTION:
# The default src_test() implementation runs my_src_test()
# (or the default) inside the build directory.
out-of-source_src_test() {
	debug-print-function ${FUNCNAME} "$@"

	pushd "${BUILD_DIR}" >/dev/null || die
	if declare -f my_src_test >/dev/null ; then
		my_src_test
	else
		default_src_test
	fi
	popd >/dev/null || die
}

# @FUNCTION: out-of-source_src_install
# @DESCRIPTION:
# The default src_install() implementation runs my_src_install()
# (or the 'make install' part of the default) inside the build directory,
# followed by a call to my_src_install_all() (or 'einstalldocs' part
# of the default) in the original working directory.
out-of-source_src_install() {
	debug-print-function ${FUNCNAME} "$@"

	pushd "${BUILD_DIR}" >/dev/null || die
	if declare -f my_src_install >/dev/null ; then
		my_src_install
	else
		if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
			emake DESTDIR="${D}" install
		fi
	fi
	popd >/dev/null || die

	if declare -f my_src_install_all >/dev/null ; then
		my_src_install_all
	else
		einstalldocs
	fi
}

fi

EXPORT_FUNCTIONS src_configure src_compile src_test src_install