1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: libtool.eclass
7 # base-system@gentoo.org
8 # @BLURB: quickly update bundled libtool code
10 # This eclass patches ltmain.sh distributed with libtoolized packages with the
11 # relink and portage patch among others
13 # Note, this eclass does not require libtool as it only applies patches to
14 # generated libtool files. We do not run the libtoolize program because that
15 # requires a regeneration of the main autotool files in order to work properly.
17 if [[ -z ${_LIBTOOL_ECLASS} ]]; then
20 # If an overlay has eclass overrides, but doesn't actually override the
21 # libtool.eclass, we'll have ECLASSDIR pointing to the active overlay's
22 # eclass/ dir, but libtool.eclass is still in the main Gentoo tree. So
23 # add a check to locate the ELT-patches/ regardless of what's going on.
24 # Note: Duplicated in eutils.eclass.
25 _LIBTOOL_ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
26 libtool_elt_patch_dir() {
27 local d="${ECLASSDIR}/ELT-patches"
28 if [[ ! -d ${d} ]] ; then
29 d="${_LIBTOOL_ECLASSDIR_LOCAL}/ELT-patches"
34 inherit multilib toolchain-funcs
37 # See if we can apply $2 on $1, and if so, do it
39 ELT_try_and_apply_patch() {
44 local disp="${src} patch"
45 local log="${T}/elibtool.log"
47 if [[ -z ${_ELT_NOTED_TMP} ]] ; then
49 printf 'temp patch: %s\n' "${patch}" > "${log}"
51 printf '\nTrying %s\n' "${disp}" >> "${log}"
53 if [[ ! -e ${file} ]] ; then
54 echo "File not found: ${file}" >> "${log}"
58 # Save file for permission restoration. `patch` sometimes resets things.
59 # Ideally we'd want 'stat -c %a', but stat is highly non portable and we are
60 # guaranted to have GNU find, so use that instead.
61 local perms="$(find ${file} -maxdepth 0 -printf '%m')"
62 # We only support patchlevel of 0 - why worry if its static patches?
63 if patch -p0 --dry-run "${file}" "${patch}" >> "${log}" 2>&1 ; then
64 einfo " Applying ${disp} ..."
65 patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${log}" 2>&1
67 export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${src}"
71 chmod "${perms}" "${file}"
77 # Get string version of ltmain.sh or ltconfig (passed as $1)
79 ELT_libtool_version() {
82 eval $(grep -e '^[[:space:]]*VERSION=' "$1")
88 # Run through the patches in $2 and see if any
96 local patch_dir="$(libtool_elt_patch_dir)/${patch_set}"
99 [[ -z ${patch_set} ]] && return 1
100 [[ ! -d ${patch_dir} ]] && return 1
102 # Allow patches to use @GENTOO_LIBDIR@ replacements
103 local sed_args=( -e "s:@GENTOO_LIBDIR@:$(get_libdir):g" )
104 if [[ -n ${rem_int_dep} ]] ; then
105 # replace @REM_INT_DEP@ with what was passed
106 # to --remove-internal-dep
107 sed_args+=( -e "s|@REM_INT_DEP@|${rem_int_dep}|g" )
110 pushd "$(libtool_elt_patch_dir)" >/dev/null || die
112 # Go through the patches in reverse order (newer version to older)
113 for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r) ; do
114 tmp="${T}/libtool-elt.patch"
115 sed "${sed_args[@]}" "${patch}" > "${tmp}" || die
116 if ELT_try_and_apply_patch "${file}" "${tmp}" "${patch}" ; then
117 # Break to unwind w/popd rather than return directly
127 # @FUNCTION: elibtoolize
128 # @USAGE: [dirs] [--portage] [--reverse-deps] [--patch-only] [--remove-internal-dep=xxx] [--shallow] [--no-uclibc]
130 # Apply a smorgasbord of patches to bundled libtool files. This function
131 # should always be safe to run. If no directories are specified, then
132 # ${S} will be searched for appropriate files.
134 # If the --shallow option is used, then only ${S}/ltmain.sh will be patched.
136 # The other options should be avoided in general unless you know what's going on.
140 local do_portage="no"
141 local do_reversedeps="yes"
142 local do_only_patches="no"
143 local do_uclibc="yes"
145 local do_shallow="no"
147 local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed target-nm"
152 # Only apply portage patch, and don't
153 # 'libtoolize --copy --force' if all patches fail.
157 # Apply the reverse-deps patch
158 # http://bugzilla.gnome.org/show_bug.cgi?id=75635
160 elt_patches+=" fix-relink"
163 # Do not run libtoolize if none of the patches apply ..
164 do_only_patches="yes"
166 --remove-internal-dep=*)
167 # We will replace @REM_INT_DEP@ with what is needed
168 # in ELT_walk_patches() ...
169 deptoremove=${x#--remove-internal-dep=}
171 # Add the patch for this ...
172 [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
175 # Only patch the ltmain.sh in ${S}
185 eerror "Invalid elibtoolize option: ${x}"
186 die "elibtoolize called with ${x} ??"
192 [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf"
195 *-aix*) elt_patches+=" hardcode aixrtl" ;; #213277
196 *-darwin*) elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf" ;;
197 *-solaris*) elt_patches+=" sol2-conf sol2-ltmain" ;;
198 *-freebsd*) elt_patches+=" fbsd-conf fbsd-ltconf" ;;
199 *-hpux*) elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc" ;;
200 *-irix*) elt_patches+=" irix-ltmain" ;;
201 *-mint*) elt_patches+=" mint-conf" ;;
204 if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
205 elt_patches+=" gold-conf"
208 # Find out what dirs to scan.
209 if [[ ${do_shallow} == "yes" ]] ; then
210 [[ ${#dirs[@]} -ne 0 ]] && die "Using --shallow with explicit dirs doesn't make sense"
211 [[ -f ${S}/ltmain.sh || -f ${S}/configure ]] && dirs+=( "${S}" )
213 [[ ${#dirs[@]} -eq 0 ]] && dirs+=( "${S}" )
214 dirs=( $(find "${dirs[@]}" '(' -name ltmain.sh -o -name configure ')' -printf '%h\n' | sort -u) )
218 for d in "${dirs[@]}" ; do
219 export ELT_APPLIED_PATCHES=
221 if [[ -f ${d}/.elibtoolized ]] ; then
225 local outfunc="einfo"
226 [[ -f ${d}/.elibtoolized ]] && outfunc="ewarn"
227 ${outfunc} "Running elibtoolize in: ${d#${WORKDIR}/}/"
228 if [[ ${outfunc} == "ewarn" ]] ; then
229 ewarn " We've already been run in this tree; you should"
230 ewarn " avoid this if possible (perhaps by filing a bug)"
234 [[ -f ${d}/ltmain.sh ]] &&
235 for p in ${elt_patches} ; do
240 # Stupid test to see if its already applied ...
241 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
242 ELT_walk_patches "${d}/ltmain.sh" "${p}"
247 ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}"
251 # Do not apply if we do not have the relink patch applied ...
252 if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" ; then
253 ELT_walk_patches "${d}/ltmain.sh" "${p}"
258 # Do not apply if $max_cmd_len is not used ...
259 if grep -qs 'max_cmd_len' "${d}/ltmain.sh" ; then
260 ELT_walk_patches "${d}/ltmain.sh" "${p}"
265 ELT_walk_patches "${d}/ltmain.sh" "${p}"
269 # Newer libtoolize clears ltconfig, as not used anymore
270 if [[ -s ${d}/ltconfig ]] ; then
271 ELT_walk_patches "${d}/ltconfig" "${p}"
276 if [[ -s ${d}/ltconfig ]] ; then
277 ELT_walk_patches "${d}/ltconfig" "${p}"
282 # Newer libtoolize clears ltconfig, as not used anymore
283 if [[ -s ${d}/ltconfig ]] ; then
284 ELT_walk_patches "${d}/ltconfig" "${p}"
289 # special case to avoid false positives (failing to apply
290 # ltmain.sh path message), newer libtools have this patch
291 # built in, so not much to patch around then
292 if [[ -e ${d}/ltmain.sh ]] && \
293 ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh" ; then
294 ELT_walk_patches "${d}/ltmain.sh" "${p}"
299 ELT_walk_patches "${d}/install-sh" "${p}"
303 if tc-is-cross-compiler ; then
304 ELT_walk_patches "${d}/ltmain.sh" "${p}"
309 ELT_walk_patches "${d}/ltmain.sh" "${p}"
314 if [[ ${ret} -ne 0 ]] ; then
317 local version=$(ELT_libtool_version "${d}/ltmain.sh")
318 # Critical patch, but could be applied ...
319 # FIXME: Still need a patch for ltmain.sh > 1.4.0
320 if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && \
321 [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]] ; then
322 ewarn " Could not apply relink.patch!"
326 # Critical patch - for this one we abort, as it can really
327 # cause breakage without it applied!
328 if [[ ${do_portage} == "yes" ]] ; then
329 # Stupid test to see if its already applied ...
330 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
332 eerror "Portage patch requested, but failed to apply!"
333 eerror "Please file a bug report to add a proper patch."
334 die "Portage patch requested, but failed to apply!"
337 if grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
338 # ewarn " Portage patch seems to be already applied."
339 # ewarn " Please verify that it is not needed."
342 local version=$(ELT_libtool_version "${d}"/ltmain.sh)
344 eerror "Portage patch failed to apply (ltmain.sh version ${version})!"
345 eerror "Please file a bug report to add a proper patch."
346 die "Portage patch failed to apply!"
348 # We do not want to run libtoolize ...
349 ELT_APPLIED_PATCHES="portage"
353 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
359 # makes sense for ltmain.sh patches only
360 [[ -f ${d}/ltmain.sh ]] &&
361 if [[ -z ${ELT_APPLIED_PATCHES} ]] ; then
362 if [[ ${do_portage} == "no" && \
363 ${do_reversedeps} == "no" && \
364 ${do_only_patches} == "no" && \
365 ${deptoremove} == "" ]]
367 ewarn "Cannot apply any patches, please file a bug about this"
373 [[ -f ${d}/configure ]] &&
374 for p in ${elt_patches} ; do
379 if grep -qs 'Transform linux' "${d}/configure" ; then
380 ELT_walk_patches "${d}/configure" "${p}"
385 if grep -qs 'version_type=freebsd-' "${d}/configure" ; then
386 ELT_walk_patches "${d}/configure" "${p}"
391 if grep -qs '&& echo \.so ||' "${d}/configure" ; then
392 ELT_walk_patches "${d}/configure" "${p}"
399 # apply multiple patches as often as they match
400 while [[ $subret -eq 0 ]]; do
402 if [[ -e ${d}/configure ]]; then
403 ELT_walk_patches "${d}/configure" "${p}"
406 if [[ $subret -eq 0 ]]; then
407 # have at least one patch succeeded.
412 mint-conf|gold-conf|sol2-conf)
413 ELT_walk_patches "${d}/configure" "${p}"
417 ELT_walk_patches "${d}/configure" "${p}"
421 # ltmain.sh patches are applied above
425 if [[ ${ret} -ne 0 ]] ; then
428 [[ ${CHOST} == *-uclibc ]] && ewarn " uClibc patch set '${p}' failed to apply!"
431 if [[ ${CHOST} == *-freebsd* ]] ; then
432 if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux' \
433 "${d}/configure" 2>/dev/null) ]]; then
434 eerror " FreeBSD patch set '${p}' failed to apply!"
435 die "FreeBSD patch set '${p}' failed to apply!"
440 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
448 > "${d}/.elibtoolized"
452 uclibctoolize() { die "Use elibtoolize"; }
453 darwintoolize() { die "Use elibtoolize"; }
455 # char *VER_major(string)
457 # Return the Major (X of X.Y.Z) version
460 [[ -z $1 ]] && return 1
463 echo "${VER%%[^[:digit:]]*}"
466 # char *VER_minor(string)
468 # Return the Minor (Y of X.Y.Z) version
471 [[ -z $1 ]] && return 1
475 echo "${VER%%[^[:digit:]]*}"
478 # char *VER_micro(string)
480 # Return the Micro (Z of X.Y.Z) version.
483 [[ -z $1 ]] && return 1
487 echo "${VER%%[^[:digit:]]*}"
490 # int VER_to_int(string)
492 # Convert a string type version (2.4.0) to an int (132096)
493 # for easy compairing or versions ...
496 [[ -z $1 ]] && return 1
498 local VER_MAJOR=$(VER_major "$1")
499 local VER_MINOR=$(VER_minor "$1")
500 local VER_MICRO=$(VER_micro "$1")
501 local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ))
503 # We make version 1.0.0 the minimum version we will handle as
504 # a sanity check ... if its less, we fail ...
505 if [[ ${VER_int} -ge 65536 ]] ; then