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

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (hide annotations) (download)
Sat Nov 26 20:43:55 2011 UTC (2 years, 8 months ago) by mgorny
Branch: MAIN
Changes since 1.26: +1 -11 lines
Remove implicit IUSE=debug deprecation warning.

1 mgorny 1.26 # Copyright 1999-2011 Gentoo Foundation
2 reavertm 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.27 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.26 2011/11/26 20:42:02 mgorny Exp $
4 reavertm 1.1
5     # @ECLASS: autotools-utils.eclass
6     # @MAINTAINER:
7     # Maciej Mrozowski <reavertm@gentoo.org>
8 reavertm 1.10 # Michał Górny <mgorny@gentoo.org>
9 reavertm 1.1 # @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 reavertm 1.6 # local myeconfargs=(
61 mgorny 1.23 # $(use_enable debug)
62 reavertm 1.1 # $(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 scarabeus 1.8 2|3|4) ;;
89 reavertm 1.2 *) die "EAPI=${EAPI} is not supported" ;;
90 reavertm 1.1 esac
91    
92 mgorny 1.25 inherit autotools base eutils libtool
93 reavertm 1.1
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 reavertm 1.7 # local myeconfargs=(
115 reavertm 1.1 # --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 mgorny 1.14 # @USAGE: [all]
137 reavertm 1.1 # @DESCRIPTION:
138     # Determines unnecessary libtool files (.la) and libtool static archives (.a)
139     # and removes them from installation image.
140 mgorny 1.14 #
141 reavertm 1.1 # To unconditionally remove all libtool files, pass 'all' as argument.
142 mgorny 1.14 # Otherwise, libtool archives required for static linking will be preserved.
143 reavertm 1.1 #
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 mgorny 1.16 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 reavertm 1.1
160 mgorny 1.19 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 reavertm 1.1 local f
170 mgorny 1.12 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
171 reavertm 1.1 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
172 mgorny 1.14 local archivefile=${f/%.la/.a}
173 mgorny 1.15 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
174 mgorny 1.14
175 mgorny 1.18 # Remove static libs we're not supposed to link against.
176 mgorny 1.17 if [[ ${shouldnotlink} ]]; then
177     einfo "Removing unnecessary ${archivefile#${D%/}}"
178     rm -f "${archivefile}" || die
179 mgorny 1.18 # The .la file may be used by a module loader, so avoid removing it
180     # unless explicitly requested.
181 mgorny 1.17 [[ ${removing_all} ]] || continue
182     fi
183    
184 mgorny 1.18 # Remove .la files when:
185     # - user explicitly wants us to remove all .la files,
186     # - respective static archive doesn't exist,
187 mgorny 1.19 # - they are covered by a .pc file already,
188 mgorny 1.18 # - they don't provide any new information (no libs & no flags).
189     local removing
190 mgorny 1.20 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 mgorny 1.18 elif [[ ! $(sed -n -e \
195     "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
196 mgorny 1.20 "${f}") ]]; then removing='no libs & flags'
197 mgorny 1.18 fi
198    
199     if [[ ${removing} ]]; then
200 mgorny 1.20 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
201 mgorny 1.15 rm -f "${f}" || die
202 reavertm 1.1 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 mgorny 1.25 elibtoolize --patch-only
216 reavertm 1.1 }
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 mgorny 1.22 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
231     || die 'autotools-utils.eclass: myeconfargs has to be an array.'
232    
233 reavertm 1.1 # Common args
234     local econfargs=()
235    
236     # Handle static-libs found in IUSE, disable them by default
237 mgorny 1.24 if in_iuse static-libs; then
238 reavertm 1.1 econfargs+=(
239     --enable-shared
240     $(use_enable static-libs static)
241     )
242     fi
243    
244     # Append user args
245 reavertm 1.5 econfargs+=("${myeconfargs[@]}")
246 reavertm 1.1
247     _check_build_dir
248     mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
249 mgorny 1.26 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
250 reavertm 1.4 base_src_configure "${econfargs[@]}" "$@"
251 mgorny 1.26 popd > /dev/null || die
252 reavertm 1.1 }
253    
254     # @FUNCTION: autotools-utils_src_compile
255     # @DESCRIPTION:
256     # The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
257     autotools-utils_src_compile() {
258     debug-print-function ${FUNCNAME} "$@"
259    
260     _check_build_dir
261 mgorny 1.26 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
262 reavertm 1.1 base_src_compile "$@"
263 mgorny 1.26 popd > /dev/null || die
264 reavertm 1.1 }
265    
266     # @FUNCTION: autotools-utils_src_install
267     # @DESCRIPTION:
268     # The autotools src_install function. Runs emake install, unconditionally
269     # removes unnecessary static libs (based on shouldnotlink libtool property)
270     # and removes unnecessary libtool files when static-libs USE flag is defined
271     # and unset.
272     #
273     # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
274     autotools-utils_src_install() {
275     debug-print-function ${FUNCNAME} "$@"
276    
277     _check_build_dir
278 mgorny 1.26 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
279 reavertm 1.9 base_src_install "$@"
280 mgorny 1.26 popd > /dev/null || die
281 reavertm 1.1
282     # Remove libtool files and unnecessary static libs
283 mgorny 1.14 remove_libtool_files
284 reavertm 1.1 }
285    
286     # @FUNCTION: autotools-utils_src_test
287     # @DESCRIPTION:
288     # The autotools src_test function. Runs emake check in build directory.
289     autotools-utils_src_test() {
290     debug-print-function ${FUNCNAME} "$@"
291    
292     _check_build_dir
293 mgorny 1.26 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
294 reavertm 1.1 # Run default src_test as defined in ebuild.sh
295     default_src_test
296 mgorny 1.26 popd > /dev/null || die
297 reavertm 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20