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

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (hide annotations) (download)
Sun Nov 27 09:57:20 2011 UTC (2 years, 8 months ago) by mgorny
Branch: MAIN
Changes since 1.28: +18 -9 lines
Revert making pushd/popd fatal due to humongous breakage. Add a warning message instead.

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

  ViewVC Help
Powered by ViewVC 1.1.20