| 1 | # Copyright 1999-2010 Gentoo Foundation |
1 | # Copyright 1999-2010 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.2 2010/07/19 16:15:14 reavertm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.25 2011/10/14 20:28:29 mgorny Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: autotools-utils.eclass |
5 | # @ECLASS: autotools-utils.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Maciej Mrozowski <reavertm@gentoo.org> |
7 | # Maciej Mrozowski <reavertm@gentoo.org> |
|
|
8 | # Michał Górny <mgorny@gentoo.org> |
| 8 | # @BLURB: common ebuild functions for autotools-based packages |
9 | # @BLURB: common ebuild functions for autotools-based packages |
| 9 | # @DESCRIPTION: |
10 | # @DESCRIPTION: |
| 10 | # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper |
11 | # 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 | # providing all inherited features along with econf arguments as Bash array, |
| 12 | # out of source build with overridable build dir location, static archives |
13 | # out of source build with overridable build dir location, static archives |
| … | |
… | |
| 54 | # "${FILESDIR}/${P}-as-needed.patch" |
55 | # "${FILESDIR}/${P}-as-needed.patch" |
| 55 | # "${FILESDIR}/${P}-unbundle_libpng.patch" |
56 | # "${FILESDIR}/${P}-unbundle_libpng.patch" |
| 56 | # ) |
57 | # ) |
| 57 | # |
58 | # |
| 58 | # src_configure() { |
59 | # src_configure() { |
| 59 | # myeconfargs=( |
60 | # local myeconfargs=( |
|
|
61 | # $(use_enable debug) |
| 60 | # $(use_with qt4) |
62 | # $(use_with qt4) |
| 61 | # $(use_enable threads multithreading) |
63 | # $(use_enable threads multithreading) |
| 62 | # $(use_with tiff) |
64 | # $(use_with tiff) |
| 63 | # ) |
65 | # ) |
| 64 | # autotools-utils_src_configure |
66 | # autotools-utils_src_configure |
| … | |
… | |
| 85 | case ${EAPI:-0} in |
87 | case ${EAPI:-0} in |
| 86 | 2|3|4) ;; |
88 | 2|3|4) ;; |
| 87 | *) die "EAPI=${EAPI} is not supported" ;; |
89 | *) die "EAPI=${EAPI} is not supported" ;; |
| 88 | esac |
90 | esac |
| 89 | |
91 | |
| 90 | inherit autotools base |
92 | inherit autotools base eutils libtool |
| 91 | |
93 | |
| 92 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
94 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
| 93 | |
95 | |
| 94 | # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
96 | # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
| 95 | # @DESCRIPTION: |
97 | # @DESCRIPTION: |
| … | |
… | |
| 107 | # @ECLASS-VARIABLE: myeconfargs |
109 | # @ECLASS-VARIABLE: myeconfargs |
| 108 | # @DESCRIPTION: |
110 | # @DESCRIPTION: |
| 109 | # Optional econf arguments as Bash array. Should be defined before calling src_configure. |
111 | # Optional econf arguments as Bash array. Should be defined before calling src_configure. |
| 110 | # @CODE |
112 | # @CODE |
| 111 | # src_configure() { |
113 | # src_configure() { |
| 112 | # myeconfargs=( |
114 | # local myeconfargs=( |
| 113 | # --disable-readline |
115 | # --disable-readline |
| 114 | # --with-confdir="/etc/nasty foo confdir/" |
116 | # --with-confdir="/etc/nasty foo confdir/" |
| 115 | # $(use_enable debug cnddebug) |
117 | # $(use_enable debug cnddebug) |
| 116 | # $(use_enable threads multithreading) |
118 | # $(use_enable threads multithreading) |
| 117 | # ) |
119 | # ) |
| … | |
… | |
| 129 | fi |
131 | fi |
| 130 | echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
132 | echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
| 131 | } |
133 | } |
| 132 | |
134 | |
| 133 | # @FUNCTION: remove_libtool_files |
135 | # @FUNCTION: remove_libtool_files |
| 134 | # @USAGE: [all|none] |
136 | # @USAGE: [all] |
| 135 | # @DESCRIPTION: |
137 | # @DESCRIPTION: |
| 136 | # Determines unnecessary libtool files (.la) and libtool static archives (.a) |
138 | # Determines unnecessary libtool files (.la) and libtool static archives (.a) |
| 137 | # and removes them from installation image. |
139 | # and removes them from installation image. |
|
|
140 | # |
| 138 | # To unconditionally remove all libtool files, pass 'all' as argument. |
141 | # To unconditionally remove all libtool files, pass 'all' as argument. |
| 139 | # To leave all libtool files alone, pass 'none' as argument. |
142 | # Otherwise, libtool archives required for static linking will be preserved. |
| 140 | # Unnecessary static archives are removed in any case. |
|
|
| 141 | # |
143 | # |
| 142 | # In most cases it's not necessary to manually invoke this function. |
144 | # In most cases it's not necessary to manually invoke this function. |
| 143 | # See autotools-utils_src_install for reference. |
145 | # See autotools-utils_src_install for reference. |
| 144 | remove_libtool_files() { |
146 | remove_libtool_files() { |
| 145 | debug-print-function ${FUNCNAME} "$@" |
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 |
| 146 | |
168 | |
| 147 | local f |
169 | local f |
| 148 | for f in $(find "${D}" -type f -name '*.la'); do |
170 | find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do |
| 149 | # Keep only .la files with shouldnotlink=yes - likely plugins |
|
|
| 150 | local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
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. |
| 151 | if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then |
176 | if [[ ${shouldnotlink} ]]; then |
| 152 | if [[ "$1" != 'none' ]]; then |
177 | einfo "Removing unnecessary ${archivefile#${D%/}}" |
| 153 | echo "Removing unnecessary ${f}" |
178 | rm -f "${archivefile}" || die |
| 154 | rm -f "${f}" |
179 | # The .la file may be used by a module loader, so avoid removing it |
| 155 | fi |
180 | # unless explicitly requested. |
|
|
181 | [[ ${removing_all} ]] || continue |
| 156 | fi |
182 | fi |
| 157 | # Remove static libs we're not supposed to link against |
183 | |
| 158 | if [[ -n ${shouldnotlink} ]]; then |
184 | # Remove .la files when: |
| 159 | local remove=${f/%.la/.a} |
185 | # - user explicitly wants us to remove all .la files, |
| 160 | [[ "${f}" != "${remove}" ]] || die 'regex sanity check failed' |
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 |
| 161 | echo "Removing unnecessary ${remove}" |
200 | einfo "Removing unnecessary ${f#${D%/}} (${removing})" |
| 162 | rm -f "${remove}" |
201 | rm -f "${f}" || die |
| 163 | fi |
202 | fi |
| 164 | done |
203 | done |
| 165 | } |
204 | } |
| 166 | |
205 | |
| 167 | # @FUNCTION: autotools-utils_src_prepare |
206 | # @FUNCTION: autotools-utils_src_prepare |
| … | |
… | |
| 171 | # Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
210 | # Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
| 172 | autotools-utils_src_prepare() { |
211 | autotools-utils_src_prepare() { |
| 173 | debug-print-function ${FUNCNAME} "$@" |
212 | debug-print-function ${FUNCNAME} "$@" |
| 174 | |
213 | |
| 175 | base_src_prepare |
214 | base_src_prepare |
|
|
215 | elibtoolize --patch-only |
| 176 | } |
216 | } |
| 177 | |
217 | |
| 178 | # @FUNCTION: autotools-utils_src_configure |
218 | # @FUNCTION: autotools-utils_src_configure |
| 179 | # @DESCRIPTION: |
219 | # @DESCRIPTION: |
| 180 | # The src_configure function. For out of source build it creates build |
220 | # The src_configure function. For out of source build it creates build |
| 181 | # directory and runs econf there. Configuration parameters defined |
221 | # directory and runs econf there. Configuration parameters defined |
| 182 | # in myeconfargs are passed here to econf. Additionally following USE |
222 | # in myeconfargs are passed here to econf. Additionally following USE |
| 183 | # flags are known: |
223 | # flags are known: |
| 184 | # |
224 | # |
| 185 | # IUSE="debug" passes --disable-debug/--enable-debug to econf respectively. |
|
|
| 186 | # |
|
|
| 187 | # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
225 | # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
| 188 | # to econf respectively. |
226 | # to econf respectively. |
| 189 | autotools-utils_src_configure() { |
227 | autotools-utils_src_configure() { |
| 190 | debug-print-function ${FUNCNAME} "$@" |
228 | debug-print-function ${FUNCNAME} "$@" |
| 191 | |
229 | |
|
|
230 | [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
|
|
231 | || die 'autotools-utils.eclass: myeconfargs has to be an array.' |
|
|
232 | |
| 192 | # Common args |
233 | # Common args |
| 193 | local econfargs=() |
234 | local econfargs=() |
| 194 | |
235 | |
| 195 | # Handle debug found in IUSE |
236 | # Handle debug found in IUSE |
| 196 | if has debug ${IUSE//+}; then |
237 | if in_iuse debug; then |
| 197 | econfargs+=($(use_enable debug)) |
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 |
| 198 | fi |
244 | fi |
| 199 | |
245 | |
| 200 | # Handle static-libs found in IUSE, disable them by default |
246 | # Handle static-libs found in IUSE, disable them by default |
| 201 | if has static-libs ${IUSE//+}; then |
247 | if in_iuse static-libs; then |
| 202 | econfargs+=( |
248 | econfargs+=( |
| 203 | --enable-shared |
249 | --enable-shared |
| 204 | $(use_enable static-libs static) |
250 | $(use_enable static-libs static) |
| 205 | ) |
251 | ) |
| 206 | fi |
252 | fi |
| 207 | |
253 | |
| 208 | # Append user args |
254 | # Append user args |
| 209 | econfargs+=(${myeconfargs[@]}) |
255 | econfargs+=("${myeconfargs[@]}") |
| 210 | |
256 | |
| 211 | _check_build_dir |
257 | _check_build_dir |
| 212 | mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
258 | mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
| 213 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
259 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
| 214 | base_src_configure "${econfargs[@]}" |
260 | base_src_configure "${econfargs[@]}" "$@" |
| 215 | popd > /dev/null |
261 | popd > /dev/null |
| 216 | } |
262 | } |
| 217 | |
263 | |
| 218 | # @FUNCTION: autotools-utils_src_compile |
264 | # @FUNCTION: autotools-utils_src_compile |
| 219 | # @DESCRIPTION: |
265 | # @DESCRIPTION: |
| … | |
… | |
| 238 | autotools-utils_src_install() { |
284 | autotools-utils_src_install() { |
| 239 | debug-print-function ${FUNCNAME} "$@" |
285 | debug-print-function ${FUNCNAME} "$@" |
| 240 | |
286 | |
| 241 | _check_build_dir |
287 | _check_build_dir |
| 242 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
288 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
| 243 | base_src_install |
289 | base_src_install "$@" |
| 244 | popd > /dev/null |
290 | popd > /dev/null |
| 245 | |
291 | |
| 246 | # Remove libtool files and unnecessary static libs |
292 | # Remove libtool files and unnecessary static libs |
| 247 | local args |
|
|
| 248 | has static-libs ${IUSE//+} && ! use static-libs || args='none' |
|
|
| 249 | remove_libtool_files ${args} |
293 | remove_libtool_files |
| 250 | } |
294 | } |
| 251 | |
295 | |
| 252 | # @FUNCTION: autotools-utils_src_test |
296 | # @FUNCTION: autotools-utils_src_test |
| 253 | # @DESCRIPTION: |
297 | # @DESCRIPTION: |
| 254 | # The autotools src_test function. Runs emake check in build directory. |
298 | # The autotools src_test function. Runs emake check in build directory. |