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

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Fri Sep 16 15:38:26 2011 UTC (3 years, 3 months ago) by mgorny
Branch: MAIN
Changes since 1.17: +17 -7 lines
Drop 'empty' .la files as well (those lacking libs & flags).

1 reavertm 1.1 # Copyright 1999-2010 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.17 2011/09/16 15:38:13 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 reavertm 1.1 # $(use_with qt4)
62     # $(use_enable threads multithreading)
63     # $(use_with tiff)
64     # )
65     # autotools-utils_src_configure
66     # }
67     #
68     # src_compile() {
69     # autotools-utils_src_compile
70     # use doc && autotools-utils_src_compile docs
71     # }
72     #
73     # src_install() {
74     # use doc && HTML_DOCS=("${AUTOTOOLS_BUILD_DIR}/apidocs/html/")
75     # autotools-utils_src_install
76     # if use examples; then
77     # dobin "${AUTOTOOLS_BUILD_DIR}"/foo_example{1,2,3} \\
78     # || die 'dobin examples failed'
79     # fi
80     # }
81     #
82     # @CODE
83    
84     # Keep variable names synced with cmake-utils and the other way around!
85    
86     case ${EAPI:-0} in
87 scarabeus 1.8 2|3|4) ;;
88 reavertm 1.2 *) die "EAPI=${EAPI} is not supported" ;;
89 reavertm 1.1 esac
90    
91     inherit autotools base
92    
93     EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
94    
95     # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
96     # @DESCRIPTION:
97     # Build directory, location where all autotools generated files should be
98     # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build.
99    
100     # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
101     # @DESCRIPTION:
102     # Set to enable in-source build.
103    
104     # @ECLASS-VARIABLE: ECONF_SOURCE
105     # @DESCRIPTION:
106     # Specify location of autotools' configure script. By default it uses ${S}.
107    
108     # @ECLASS-VARIABLE: myeconfargs
109     # @DESCRIPTION:
110     # Optional econf arguments as Bash array. Should be defined before calling src_configure.
111     # @CODE
112     # src_configure() {
113 reavertm 1.7 # local myeconfargs=(
114 reavertm 1.1 # --disable-readline
115     # --with-confdir="/etc/nasty foo confdir/"
116     # $(use_enable debug cnddebug)
117     # $(use_enable threads multithreading)
118     # )
119     # autotools-utils_src_configure
120     # }
121     # @CODE
122    
123     # Determine using IN or OUT source build
124     _check_build_dir() {
125     : ${ECONF_SOURCE:=${S}}
126     if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
127     AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}"
128     else
129     : ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build}
130     fi
131     echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
132     }
133    
134     # @FUNCTION: remove_libtool_files
135 mgorny 1.14 # @USAGE: [all]
136 reavertm 1.1 # @DESCRIPTION:
137     # Determines unnecessary libtool files (.la) and libtool static archives (.a)
138     # and removes them from installation image.
139 mgorny 1.14 #
140 reavertm 1.1 # To unconditionally remove all libtool files, pass 'all' as argument.
141 mgorny 1.14 # Otherwise, libtool archives required for static linking will be preserved.
142 reavertm 1.1 #
143     # In most cases it's not necessary to manually invoke this function.
144     # See autotools-utils_src_install for reference.
145     remove_libtool_files() {
146     debug-print-function ${FUNCNAME} "$@"
147 mgorny 1.16 local removing_all
148     [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
149     if [[ ${#} -eq 1 ]]; then
150     case "${1}" in
151     all)
152     removing_all=1
153     ;;
154     *)
155     die "Invalid argument to ${FUNCNAME}(): ${1}"
156     esac
157     fi
158 reavertm 1.1
159     local f
160 mgorny 1.12 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
161 reavertm 1.1 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
162 mgorny 1.14 local archivefile=${f/%.la/.a}
163 mgorny 1.15 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
164 mgorny 1.14
165 mgorny 1.18 # Remove static libs we're not supposed to link against.
166 mgorny 1.17 if [[ ${shouldnotlink} ]]; then
167     einfo "Removing unnecessary ${archivefile#${D%/}}"
168     rm -f "${archivefile}" || die
169 mgorny 1.18 # The .la file may be used by a module loader, so avoid removing it
170     # unless explicitly requested.
171 mgorny 1.17 [[ ${removing_all} ]] || continue
172     fi
173    
174 mgorny 1.18 # Remove .la files when:
175     # - user explicitly wants us to remove all .la files,
176     # - respective static archive doesn't exist,
177     # - they don't provide any new information (no libs & no flags).
178     local removing
179     if [[ ${removing_all} ]]; then removing=1
180     elif [[ ! -f ${archivefile} ]]; then removing=1
181     elif [[ ! $(sed -n -e \
182     "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
183     "${f}") ]]; then removing=1
184     fi
185    
186     if [[ ${removing} ]]; then
187 mgorny 1.14 einfo "Removing unnecessary ${f#${D%/}}"
188 mgorny 1.15 rm -f "${f}" || die
189 reavertm 1.1 fi
190     done
191     }
192    
193     # @FUNCTION: autotools-utils_src_prepare
194     # @DESCRIPTION:
195     # The src_prepare function.
196     #
197     # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
198     autotools-utils_src_prepare() {
199     debug-print-function ${FUNCNAME} "$@"
200    
201     base_src_prepare
202     }
203    
204     # @FUNCTION: autotools-utils_src_configure
205     # @DESCRIPTION:
206     # The src_configure function. For out of source build it creates build
207     # directory and runs econf there. Configuration parameters defined
208     # in myeconfargs are passed here to econf. Additionally following USE
209     # flags are known:
210     #
211     # IUSE="debug" passes --disable-debug/--enable-debug to econf respectively.
212     #
213     # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
214     # to econf respectively.
215     autotools-utils_src_configure() {
216     debug-print-function ${FUNCNAME} "$@"
217    
218     # Common args
219     local econfargs=()
220    
221     # Handle debug found in IUSE
222     if has debug ${IUSE//+}; then
223     econfargs+=($(use_enable debug))
224     fi
225    
226     # Handle static-libs found in IUSE, disable them by default
227     if has static-libs ${IUSE//+}; then
228     econfargs+=(
229     --enable-shared
230     $(use_enable static-libs static)
231     )
232     fi
233    
234     # Append user args
235 reavertm 1.5 econfargs+=("${myeconfargs[@]}")
236 reavertm 1.1
237     _check_build_dir
238     mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
239     pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
240 reavertm 1.4 base_src_configure "${econfargs[@]}" "$@"
241 reavertm 1.1 popd > /dev/null
242     }
243    
244     # @FUNCTION: autotools-utils_src_compile
245     # @DESCRIPTION:
246     # The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
247     autotools-utils_src_compile() {
248     debug-print-function ${FUNCNAME} "$@"
249    
250     _check_build_dir
251     pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
252     base_src_compile "$@"
253     popd > /dev/null
254     }
255    
256     # @FUNCTION: autotools-utils_src_install
257     # @DESCRIPTION:
258     # The autotools src_install function. Runs emake install, unconditionally
259     # removes unnecessary static libs (based on shouldnotlink libtool property)
260     # and removes unnecessary libtool files when static-libs USE flag is defined
261     # and unset.
262     #
263     # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
264     autotools-utils_src_install() {
265     debug-print-function ${FUNCNAME} "$@"
266    
267     _check_build_dir
268     pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
269 reavertm 1.9 base_src_install "$@"
270 reavertm 1.1 popd > /dev/null
271    
272     # Remove libtool files and unnecessary static libs
273 mgorny 1.14 remove_libtool_files
274 reavertm 1.1 }
275    
276     # @FUNCTION: autotools-utils_src_test
277     # @DESCRIPTION:
278     # The autotools src_test function. Runs emake check in build directory.
279     autotools-utils_src_test() {
280     debug-print-function ${FUNCNAME} "$@"
281    
282     _check_build_dir
283     pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
284     # Run default src_test as defined in ebuild.sh
285     default_src_test
286     popd > /dev/null
287     }

  ViewVC Help
Powered by ViewVC 1.1.20