/[gentoo-x86]/eclass/autotools-utils.eclass
Gentoo

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (show annotations) (download)
Fri Oct 14 20:28:29 2011 UTC (3 years, 1 month ago) by mgorny
Branch: MAIN
Changes since 1.24: +3 -2 lines
Use elibtoolize from libtool.eclass to fix libtool magic.

We're calling it with '--patch-only' to avoid heavy changes to ebuilds.
This should handle gracefully eautoreconfed packages and those not using
libtool as well (in worst case, it should try to apply patches twice).

1 # Copyright 1999-2010 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.24 2011/09/23 07:56:41 mgorny Exp $
4
5 # @ECLASS: autotools-utils.eclass
6 # @MAINTAINER:
7 # Maciej Mrozowski <reavertm@gentoo.org>
8 # Michał Górny <mgorny@gentoo.org>
9 # @BLURB: common ebuild functions for autotools-based packages
10 # @DESCRIPTION:
11 # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper
12 # providing all inherited features along with econf arguments as Bash array,
13 # out of source build with overridable build dir location, static archives
14 # handling, libtool files removal, enable/disable debug handling.
15 #
16 # @EXAMPLE:
17 # Typical ebuild using autotools-utils.eclass:
18 #
19 # @CODE
20 # EAPI="2"
21 #
22 # inherit autotools-utils
23 #
24 # DESCRIPTION="Foo bar application"
25 # HOMEPAGE="http://example.org/foo/"
26 # SRC_URI="mirror://sourceforge/foo/${P}.tar.bz2"
27 #
28 # LICENSE="LGPL-2.1"
29 # KEYWORDS=""
30 # SLOT="0"
31 # IUSE="debug doc examples qt4 static-libs tiff"
32 #
33 # CDEPEND="
34 # media-libs/libpng:0
35 # qt4? (
36 # x11-libs/qt-core:4
37 # x11-libs/qt-gui:4
38 # )
39 # tiff? ( media-libs/tiff:0 )
40 # "
41 # RDEPEND="${CDEPEND}
42 # !media-gfx/bar
43 # "
44 # DEPEND="${CDEPEND}
45 # doc? ( app-doc/doxygen )
46 # "
47 #
48 # # bug 123456
49 # AUTOTOOLS_IN_SOURCE_BUILD=1
50 #
51 # DOCS=(AUTHORS ChangeLog README "Read me.txt" TODO)
52 #
53 # PATCHES=(
54 # "${FILESDIR}/${P}-gcc44.patch" # bug 123458
55 # "${FILESDIR}/${P}-as-needed.patch"
56 # "${FILESDIR}/${P}-unbundle_libpng.patch"
57 # )
58 #
59 # src_configure() {
60 # local myeconfargs=(
61 # $(use_enable debug)
62 # $(use_with qt4)
63 # $(use_enable threads multithreading)
64 # $(use_with tiff)
65 # )
66 # autotools-utils_src_configure
67 # }
68 #
69 # src_compile() {
70 # autotools-utils_src_compile
71 # use doc && autotools-utils_src_compile docs
72 # }
73 #
74 # src_install() {
75 # use doc && HTML_DOCS=("${AUTOTOOLS_BUILD_DIR}/apidocs/html/")
76 # autotools-utils_src_install
77 # if use examples; then
78 # dobin "${AUTOTOOLS_BUILD_DIR}"/foo_example{1,2,3} \\
79 # || die 'dobin examples failed'
80 # fi
81 # }
82 #
83 # @CODE
84
85 # Keep variable names synced with cmake-utils and the other way around!
86
87 case ${EAPI:-0} in
88 2|3|4) ;;
89 *) die "EAPI=${EAPI} is not supported" ;;
90 esac
91
92 inherit autotools base eutils libtool
93
94 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
95
96 # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
97 # @DESCRIPTION:
98 # Build directory, location where all autotools generated files should be
99 # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build.
100
101 # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
102 # @DESCRIPTION:
103 # Set to enable in-source build.
104
105 # @ECLASS-VARIABLE: ECONF_SOURCE
106 # @DESCRIPTION:
107 # Specify location of autotools' configure script. By default it uses ${S}.
108
109 # @ECLASS-VARIABLE: myeconfargs
110 # @DESCRIPTION:
111 # Optional econf arguments as Bash array. Should be defined before calling src_configure.
112 # @CODE
113 # src_configure() {
114 # local myeconfargs=(
115 # --disable-readline
116 # --with-confdir="/etc/nasty foo confdir/"
117 # $(use_enable debug cnddebug)
118 # $(use_enable threads multithreading)
119 # )
120 # autotools-utils_src_configure
121 # }
122 # @CODE
123
124 # Determine using IN or OUT source build
125 _check_build_dir() {
126 : ${ECONF_SOURCE:=${S}}
127 if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
128 AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}"
129 else
130 : ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build}
131 fi
132 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
133 }
134
135 # @FUNCTION: remove_libtool_files
136 # @USAGE: [all]
137 # @DESCRIPTION:
138 # Determines unnecessary libtool files (.la) and libtool static archives (.a)
139 # and removes them from installation image.
140 #
141 # To unconditionally remove all libtool files, pass 'all' as argument.
142 # Otherwise, libtool archives required for static linking will be preserved.
143 #
144 # In most cases it's not necessary to manually invoke this function.
145 # See autotools-utils_src_install for reference.
146 remove_libtool_files() {
147 debug-print-function ${FUNCNAME} "$@"
148 local removing_all
149 [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
150 if [[ ${#} -eq 1 ]]; then
151 case "${1}" in
152 all)
153 removing_all=1
154 ;;
155 *)
156 die "Invalid argument to ${FUNCNAME}(): ${1}"
157 esac
158 fi
159
160 local pc_libs=()
161 if [[ ! ${removing_all} ]]; then
162 local arg
163 for arg in $(find "${D}" -name '*.pc' -exec \
164 sed -n -e 's;^Libs:;;p' {} +); do
165 [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
166 done
167 fi
168
169 local f
170 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
171 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
172 local archivefile=${f/%.la/.a}
173 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
174
175 # Remove static libs we're not supposed to link against.
176 if [[ ${shouldnotlink} ]]; then
177 einfo "Removing unnecessary ${archivefile#${D%/}}"
178 rm -f "${archivefile}" || die
179 # The .la file may be used by a module loader, so avoid removing it
180 # unless explicitly requested.
181 [[ ${removing_all} ]] || continue
182 fi
183
184 # Remove .la files when:
185 # - user explicitly wants us to remove all .la files,
186 # - respective static archive doesn't exist,
187 # - they are covered by a .pc file already,
188 # - they don't provide any new information (no libs & no flags).
189 local removing
190 if [[ ${removing_all} ]]; then removing='forced'
191 elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
192 elif has "$(basename "${f}")" "${pc_libs[@]}"; then
193 removing='covered by .pc'
194 elif [[ ! $(sed -n -e \
195 "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
196 "${f}") ]]; then removing='no libs & flags'
197 fi
198
199 if [[ ${removing} ]]; then
200 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
201 rm -f "${f}" || die
202 fi
203 done
204 }
205
206 # @FUNCTION: autotools-utils_src_prepare
207 # @DESCRIPTION:
208 # The src_prepare function.
209 #
210 # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
211 autotools-utils_src_prepare() {
212 debug-print-function ${FUNCNAME} "$@"
213
214 base_src_prepare
215 elibtoolize --patch-only
216 }
217
218 # @FUNCTION: autotools-utils_src_configure
219 # @DESCRIPTION:
220 # The src_configure function. For out of source build it creates build
221 # directory and runs econf there. Configuration parameters defined
222 # in myeconfargs are passed here to econf. Additionally following USE
223 # flags are known:
224 #
225 # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
226 # to econf respectively.
227 autotools-utils_src_configure() {
228 debug-print-function ${FUNCNAME} "$@"
229
230 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
231 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
232
233 # Common args
234 local econfargs=()
235
236 # Handle debug found in IUSE
237 if in_iuse debug; then
238 local debugarg=$(use_enable debug)
239 if ! has "${debugarg}" "${myeconfargs[@]}"; then
240 eqawarn 'Implicit $(use_enable debug) for IUSE="debug" is no longer supported.'
241 eqawarn 'Please add the necessary arg to myeconfargs if requested.'
242 eqawarn 'The autotools-utils eclass will stop warning about it on Oct 15th.'
243 fi
244 fi
245
246 # Handle static-libs found in IUSE, disable them by default
247 if in_iuse static-libs; then
248 econfargs+=(
249 --enable-shared
250 $(use_enable static-libs static)
251 )
252 fi
253
254 # Append user args
255 econfargs+=("${myeconfargs[@]}")
256
257 _check_build_dir
258 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
259 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
260 base_src_configure "${econfargs[@]}" "$@"
261 popd > /dev/null
262 }
263
264 # @FUNCTION: autotools-utils_src_compile
265 # @DESCRIPTION:
266 # The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
267 autotools-utils_src_compile() {
268 debug-print-function ${FUNCNAME} "$@"
269
270 _check_build_dir
271 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
272 base_src_compile "$@"
273 popd > /dev/null
274 }
275
276 # @FUNCTION: autotools-utils_src_install
277 # @DESCRIPTION:
278 # The autotools src_install function. Runs emake install, unconditionally
279 # removes unnecessary static libs (based on shouldnotlink libtool property)
280 # and removes unnecessary libtool files when static-libs USE flag is defined
281 # and unset.
282 #
283 # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
284 autotools-utils_src_install() {
285 debug-print-function ${FUNCNAME} "$@"
286
287 _check_build_dir
288 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
289 base_src_install "$@"
290 popd > /dev/null
291
292 # Remove libtool files and unnecessary static libs
293 remove_libtool_files
294 }
295
296 # @FUNCTION: autotools-utils_src_test
297 # @DESCRIPTION:
298 # The autotools src_test function. Runs emake check in build directory.
299 autotools-utils_src_test() {
300 debug-print-function ${FUNCNAME} "$@"
301
302 _check_build_dir
303 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
304 # Run default src_test as defined in ebuild.sh
305 default_src_test
306 popd > /dev/null
307 }

  ViewVC Help
Powered by ViewVC 1.1.20