1 # Copyright 1999-2017 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.'
284 [[ ${EAPI} == 2 ]] && ! use prefix && EPREFIX=
290 if "${ECONF_SOURCE}"/configure --help 2>&1 | grep -q '^ *--docdir='; then
292 --docdir="${EPREFIX}"/usr/share/doc/${PF}
296 # Handle static-libs found in IUSE, disable them by default
297 if in_iuse static-libs; then
300 $(use_enable static-libs static)
305 econfargs+=("${myeconfargs[@]}")
307 mkdir -p "${BUILD_DIR}" || die
308 pushd "${BUILD_DIR}" > /dev/null || die
309 econf "${econfargs[@]}" "$@"
310 popd > /dev/null || die
313 # @FUNCTION: autotools-utils_src_compile
315 # The autotools src_compile function, invokes emake in specified BUILD_DIR.
316 autotools-utils_src_compile() {
317 debug-print-function ${FUNCNAME} "$@"
320 pushd "${BUILD_DIR}" > /dev/null || die
321 emake "$@" || die 'emake failed'
322 popd > /dev/null || die
325 # @FUNCTION: autotools-utils_src_install
327 # The autotools src_install function. Runs emake install, unconditionally
328 # removes unnecessary static libs (based on shouldnotlink libtool property)
329 # and removes unnecessary libtool files when static-libs USE flag is defined
332 # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
333 autotools-utils_src_install() {
334 debug-print-function ${FUNCNAME} "$@"
337 pushd "${BUILD_DIR}" > /dev/null || die
338 emake DESTDIR="${D}" "$@" install || die "emake install failed"
339 popd > /dev/null || die
341 # Move docs installed by autotools (in EAPI < 4).
342 if [[ ${EAPI} == [23] ]] \
343 && path_exists "${D}${EPREFIX}"/usr/share/doc/${PF}/*; then
344 if [[ $(find "${D}${EPREFIX}"/usr/share/doc/${PF}/* -type d) ]]; then
345 eqawarn "autotools-utils: directories in docdir require at least EAPI 4"
347 mkdir "${T}"/temp-docdir
348 mv "${D}${EPREFIX}"/usr/share/doc/${PF}/* "${T}"/temp-docdir/ \
349 || die "moving docs to tempdir failed"
351 dodoc "${T}"/temp-docdir/* || die "docdir dodoc failed"
352 rm -r "${T}"/temp-docdir || die
356 # XXX: support installing them from builddir as well?
357 if declare -p DOCS &>/dev/null; then
358 # an empty list == don't install anything
359 if [[ ${DOCS[@]} ]]; then
360 if [[ ${EAPI} == [23] ]]; then
361 dodoc "${DOCS[@]}" || die
364 dodoc -r "${DOCS[@]}"
369 # same list as in PMS
370 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
371 THANKS BUGS FAQ CREDITS CHANGELOG; do
372 if [[ -s ${f} ]]; then
373 dodoc "${f}" || die "(default) dodoc ${f} failed"
377 if [[ ${HTML_DOCS} ]]; then
378 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
381 # Remove libtool files and unnecessary static libs
382 local prune_ltfiles=${AUTOTOOLS_PRUNE_LIBTOOL_FILES}
383 if [[ ${prune_ltfiles} != none ]]; then
384 prune_libtool_files ${prune_ltfiles:+--${prune_ltfiles}}
388 # @FUNCTION: autotools-utils_src_test
390 # The autotools src_test function. Runs emake check in build directory.
391 autotools-utils_src_test() {
392 debug-print-function ${FUNCNAME} "$@"
395 pushd "${BUILD_DIR}" > /dev/null || die
397 if make -ni check "${@}" &>/dev/null; then
398 emake check "${@}" || die 'emake check failed.'
399 elif make -ni test "${@}" &>/dev/null; then
400 emake test "${@}" || die 'emake test failed.'
403 popd > /dev/null || die