1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: autotools-utils.eclass
6 # Maciej Mrozowski <reavertm@gentoo.org>
7 # Michał Górny <mgorny@gentoo.org>
8 # @BLURB: common ebuild functions for autotools-based packages
10 # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper
11 # providing all inherited features along with econf arguments as Bash array,
12 # out of source build with overridable build dir location, static archives
13 # handling, libtool files removal.
15 # Please note that autotools-utils does not support mixing of its phase
16 # functions with regular econf/emake calls. If necessary, please call
17 # autotools-utils_src_compile instead of the latter.
20 # Typical ebuild using autotools-utils.eclass:
25 # inherit autotools-utils
27 # DESCRIPTION="Foo bar application"
28 # HOMEPAGE="http://example.org/foo/"
29 # SRC_URI="mirror://sourceforge/foo/${P}.tar.bz2"
34 # IUSE="debug doc examples qt4 static-libs tiff"
42 # tiff? ( media-libs/tiff:0 )
48 # doc? ( app-doc/doxygen )
52 # AUTOTOOLS_IN_SOURCE_BUILD=1
54 # DOCS=(AUTHORS ChangeLog README "Read me.txt" TODO)
57 # "${FILESDIR}/${P}-gcc44.patch" # bug 123458
58 # "${FILESDIR}/${P}-as-needed.patch"
59 # "${FILESDIR}/${P}-unbundle_libpng.patch"
66 # $(use_enable threads multithreading)
69 # autotools-utils_src_configure
73 # autotools-utils_src_compile
74 # use doc && autotools-utils_src_compile docs
78 # use doc && HTML_DOCS=("${BUILD_DIR}/apidocs/html/")
79 # autotools-utils_src_install
80 # if use examples; then
81 # dobin "${BUILD_DIR}"/foo_example{1,2,3} \\
82 # || die 'dobin examples failed'
88 # Keep variable names synced with cmake-utils and the other way around!
91 6) die "${ECLASS}.eclass is banned in EAPI ${EAPI}";;
93 *) die "EAPI=${EAPI} is not supported" ;;
96 # @ECLASS-VARIABLE: AUTOTOOLS_AUTORECONF
99 # Set to a non-empty value before calling inherit to enable running autoreconf
100 # in src_prepare() and adding autotools dependencies.
102 # This is usually necessary when using live sources or applying patches
103 # modifying configure.ac or Makefile.am files. Note that in the latter case
104 # setting this variable is obligatory even though the eclass will work without
105 # it (to add the necessary dependencies).
107 # The eclass will try to determine the correct autotools to run including a few
108 # external tools: gettext, glib-gettext, intltool, gtk-doc, gnome-doc-prepare.
109 # If your tool is not supported, please open a bug and we'll add support for it.
111 # Note that dependencies are added for autoconf, automake and libtool only.
112 # If your package needs one of the external tools listed above, you need to add
113 # appropriate packages to DEPEND yourself.
114 [[ ${AUTOTOOLS_AUTORECONF} ]] || : ${AUTOTOOLS_AUTO_DEPEND:=no}
116 # eutils for eqawarn, path_exists
117 inherit autotools epatch eutils libtool ltprune
119 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
121 # @ECLASS-VARIABLE: BUILD_DIR
124 # Build directory, location where all autotools generated files should be
125 # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build.
127 # This variable has been called AUTOTOOLS_BUILD_DIR formerly.
128 # It is set under that name for compatibility.
130 # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
133 # Set to enable in-source build.
135 # @ECLASS-VARIABLE: ECONF_SOURCE
138 # Specify location of autotools' configure script. By default it uses ${S}.
140 # @ECLASS-VARIABLE: DOCS
143 # Array containing documents passed to dodoc command.
145 # In EAPIs 4+, can list directories as well.
149 # DOCS=( NEWS README )
152 # @ECLASS-VARIABLE: HTML_DOCS
155 # Array containing documents passed to dohtml command.
159 # HTML_DOCS=( doc/html/ )
162 # @ECLASS-VARIABLE: PATCHES
165 # PATCHES array variable containing all various patches to be applied.
169 # PATCHES=( "${FILESDIR}"/${P}-mypatch.patch )
172 # @ECLASS-VARIABLE: AUTOTOOLS_PRUNE_LIBTOOL_FILES
175 # Sets the mode of pruning libtool files. The values correspond to
176 # prune_libtool_files parameters, with leading dashes stripped.
178 # Defaults to pruning the libtool files when static libraries are not
179 # installed or can be linked properly without them. Libtool files
180 # for modules (plugins) will be kept in case plugin loader needs them.
182 # If set to 'modules', the .la files for modules will be removed
183 # as well. This is often the preferred option.
185 # If set to 'all', all .la files will be removed unconditionally. This
186 # option is discouraged and shall be used only if 'modules' does not
189 # If set to 'none', no .la files will be pruned ever. Use in corner
192 # Determine using IN or OUT source build
194 : ${ECONF_SOURCE:=${S}}
195 # Respect both the old variable and the new one, depending
196 # on which one was set by the ebuild.
197 if [[ ! ${BUILD_DIR} && ${AUTOTOOLS_BUILD_DIR} ]]; then
198 eqawarn "The AUTOTOOLS_BUILD_DIR variable has been renamed to BUILD_DIR."
199 eqawarn "Please migrate the ebuild to use the new one."
201 # In the next call, both variables will be set already
202 # and we'd have to know which one takes precedence.
203 _RESPECT_AUTOTOOLS_BUILD_DIR=1
206 if [[ ${_RESPECT_AUTOTOOLS_BUILD_DIR} ]]; then
207 BUILD_DIR=${AUTOTOOLS_BUILD_DIR:-${WORKDIR}/${P}_build}
209 if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
210 : ${BUILD_DIR:=${ECONF_SOURCE}}
212 : ${BUILD_DIR:=${WORKDIR}/${P}_build}
216 # Backwards compatibility for getting the value.
217 AUTOTOOLS_BUILD_DIR=${BUILD_DIR}
218 echo ">>> Working in BUILD_DIR: \"${BUILD_DIR}\""
221 # @FUNCTION: autotools-utils_src_prepare
223 # The src_prepare function.
225 # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
226 autotools-utils_src_prepare() {
227 debug-print-function ${FUNCNAME} "$@"
229 local want_autoreconf=${AUTOTOOLS_AUTORECONF}
231 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
234 find '(' -name 'Makefile.am' \
235 -o -name 'configure.ac' \
236 -o -name 'configure.in' ')' \
237 -exec cksum {} + | sort -k2
240 [[ ! ${want_autoreconf} ]] && local checksum=$(at_checksum)
242 if [[ ! ${want_autoreconf} ]]; then
243 if [[ ${checksum} != $(at_checksum) ]]; then
244 einfo 'Will autoreconfigure due to user patches applied.'
249 [[ ${want_autoreconf} ]] && eautoreconf
250 elibtoolize --patch-only
253 # @FUNCTION: autotools-utils_src_configure
255 # The src_configure function. For out of source build it creates build
256 # directory and runs econf there. Configuration parameters defined
257 # in myeconfargs are passed here to econf. Additionally following USE
260 # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
261 # to econf respectively.
263 # @VARIABLE: myeconfargs
266 # Optional econf arguments as Bash array. Should be defined before calling src_configure.
269 # local myeconfargs=(
271 # --with-confdir="/etc/nasty foo confdir/"
272 # $(use_enable debug cnddebug)
273 # $(use_enable threads multithreading)
275 # autotools-utils_src_configure
278 autotools-utils_src_configure() {
279 debug-print-function ${FUNCNAME} "$@"
281 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
282 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
288 if "${ECONF_SOURCE}"/configure --help 2>&1 | grep -q '^ *--docdir='; then
290 --docdir="${EPREFIX}"/usr/share/doc/${PF}
294 # Handle static-libs found in IUSE, disable them by default
295 if in_iuse static-libs; then
298 $(use_enable static-libs static)
303 econfargs+=("${myeconfargs[@]}")
305 mkdir -p "${BUILD_DIR}" || die
306 pushd "${BUILD_DIR}" > /dev/null || die
307 econf "${econfargs[@]}" "$@"
308 popd > /dev/null || die
311 # @FUNCTION: autotools-utils_src_compile
313 # The autotools src_compile function, invokes emake in specified BUILD_DIR.
314 autotools-utils_src_compile() {
315 debug-print-function ${FUNCNAME} "$@"
318 pushd "${BUILD_DIR}" > /dev/null || die
319 emake "$@" || die 'emake failed'
320 popd > /dev/null || die
323 # @FUNCTION: autotools-utils_src_install
325 # The autotools src_install function. Runs emake install, unconditionally
326 # removes unnecessary static libs (based on shouldnotlink libtool property)
327 # and removes unnecessary libtool files when static-libs USE flag is defined
330 # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
331 autotools-utils_src_install() {
332 debug-print-function ${FUNCNAME} "$@"
335 pushd "${BUILD_DIR}" > /dev/null || die
336 emake DESTDIR="${D}" "$@" install || die "emake install failed"
337 popd > /dev/null || die
339 # XXX: support installing them from builddir as well?
340 if declare -p DOCS &>/dev/null; then
341 # an empty list == don't install anything
342 if [[ ${DOCS[@]} ]]; then
344 dodoc -r "${DOCS[@]}"
348 # same list as in PMS
349 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
350 THANKS BUGS FAQ CREDITS CHANGELOG; do
351 if [[ -s ${f} ]]; then
352 dodoc "${f}" || die "(default) dodoc ${f} failed"
356 if [[ ${HTML_DOCS} ]]; then
357 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
360 # Remove libtool files and unnecessary static libs
361 local prune_ltfiles=${AUTOTOOLS_PRUNE_LIBTOOL_FILES}
362 if [[ ${prune_ltfiles} != none ]]; then
363 prune_libtool_files ${prune_ltfiles:+--${prune_ltfiles}}
367 # @FUNCTION: autotools-utils_src_test
369 # The autotools src_test function. Runs emake check in build directory.
370 autotools-utils_src_test() {
371 debug-print-function ${FUNCNAME} "$@"
374 pushd "${BUILD_DIR}" > /dev/null || die
376 if make -ni check "${@}" &>/dev/null; then
377 emake check "${@}" || die 'emake check failed.'
378 elif make -ni test "${@}" &>/dev/null; then
379 emake test "${@}" || die 'emake test failed.'
382 popd > /dev/null || die