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 _LIBTOOL_ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
26 local d="${ECLASSDIR}/ELT-patches"
27 if [[ ! -d ${d} ]] ; then
28 d="${_LIBTOOL_ECLASSDIR_LOCAL}/ELT-patches"
33 inherit multilib toolchain-funcs
36 # See if we can apply $2 on $1, and if so, do it
38 ELT_try_and_apply_patch() {
43 local disp="${src} patch"
44 local log="${T}/elibtool.log"
46 if [[ -z ${_ELT_NOTED_TMP} ]] ; then
48 printf 'temp patch: %s\n' "${patch}" > "${log}"
50 printf '\nTrying %s\n' "${disp}" >> "${log}"
52 if [[ ! -e ${file} ]] ; then
53 echo "File not found: ${file}" >> "${log}"
57 # Save file for permission restoration. `patch` sometimes resets things.
58 # Ideally we'd want 'stat -c %a', but stat is highly non portable and we are
59 # guaranted to have GNU find, so use that instead.
60 local perms="$(find ${file} -maxdepth 0 -printf '%m')"
61 # We only support patchlevel of 0 - why worry if its static patches?
62 if patch -p0 --dry-run "${file}" "${patch}" >> "${log}" 2>&1 ; then
63 einfo " Applying ${disp} ..."
64 patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${log}" 2>&1
66 export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${src}"
70 chmod "${perms}" "${file}"
76 # Get string version of ltmain.sh or ltconfig (passed as $1)
78 ELT_libtool_version() {
81 eval $(grep -e '^[[:space:]]*VERSION=' "$1")
87 # Run through the patches in $2 and see if any
95 local patch_dir="$(elt_patch_dir)/${patch_set}"
98 [[ -z ${patch_set} ]] && return 1
99 [[ ! -d ${patch_dir} ]] && return 1
101 # Allow patches to use @GENTOO_LIBDIR@ replacements
102 local sed_args=( -e "s:@GENTOO_LIBDIR@:$(get_libdir):g" )
103 if [[ -n ${rem_int_dep} ]] ; then
104 # replace @REM_INT_DEP@ with what was passed
105 # to --remove-internal-dep
106 sed_args+=( -e "s|@REM_INT_DEP@|${rem_int_dep}|g" )
109 pushd "$(elt_patch_dir)" >/dev/null || die
111 # Go through the patches in reverse order (newer version to older)
112 for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r) ; do
113 tmp="${T}/libtool-elt.patch"
114 sed "${sed_args[@]}" "${patch}" > "${tmp}" || die
115 if ELT_try_and_apply_patch "${file}" "${tmp}" "${patch}" ; then
116 # Break to unwind w/popd rather than return directly
126 # @FUNCTION: elibtoolize
127 # @USAGE: [dirs] [--portage] [--reverse-deps] [--patch-only] [--remove-internal-dep=xxx] [--shallow] [--no-uclibc]
129 # Apply a smorgasbord of patches to bundled libtool files. This function
130 # should always be safe to run. If no directories are specified, then
131 # ${S} will be searched for appropriate files.
133 # If the --shallow option is used, then only ${S}/ltmain.sh will be patched.
135 # The other options should be avoided in general unless you know what's going on.
139 local do_portage="no"
140 local do_reversedeps="no"
141 local do_only_patches="no"
142 local do_uclibc="yes"
144 local do_shallow="no"
146 local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed target-nm"
151 # Only apply portage patch, and don't
152 # 'libtoolize --copy --force' if all patches fail.
156 # Apply the reverse-deps patch
157 # http://bugzilla.gnome.org/show_bug.cgi?id=75635
159 elt_patches+=" fix-relink"
162 # Do not run libtoolize if none of the patches apply ..
163 do_only_patches="yes"
165 --remove-internal-dep=*)
166 # We will replace @REM_INT_DEP@ with what is needed
167 # in ELT_walk_patches() ...
168 deptoremove=${x#--remove-internal-dep=}
170 # Add the patch for this ...
171 [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
174 # Only patch the ltmain.sh in ${S}
184 eerror "Invalid elibtoolize option: ${x}"
185 die "elibtoolize called with ${x} ??"
191 [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf"
194 *-aix*) elt_patches+=" hardcode aixrtl" ;; #213277
195 *-darwin*) elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf" ;;
196 *-solaris*) elt_patches+=" sol2-conf sol2-ltmain" ;;
197 *-freebsd*) elt_patches+=" fbsd-conf fbsd-ltconf" ;;
198 *-hpux*) elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc" ;;
199 *-irix*) elt_patches+=" irix-ltmain" ;;
200 *-mint*) elt_patches+=" mint-conf" ;;
203 if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
204 elt_patches+=" gold-conf"
207 # Find out what dirs to scan.
208 if [[ ${do_shallow} == "yes" ]] ; then
209 [[ ${#dirs[@]} -ne 0 ]] && die "Using --shallow with explicit dirs doesn't make sense"
210 [[ -f ${S}/ltmain.sh || -f ${S}/configure ]] && dirs+=( "${S}" )
212 [[ ${#dirs[@]} -eq 0 ]] && dirs+=( "${S}" )
213 dirs=( $(find "${dirs[@]}" '(' -name ltmain.sh -o -name configure ')' -printf '%h\n' | sort -u) )
217 for d in "${dirs[@]}" ; do
218 export ELT_APPLIED_PATCHES=
220 if [[ -f ${d}/.elibtoolized ]] ; then
224 local outfunc="einfo"
225 [[ -f ${d}/.elibtoolized ]] && outfunc="ewarn"
226 ${outfunc} "Running elibtoolize in: ${d#${WORKDIR}/}/"
227 if [[ ${outfunc} == "ewarn" ]] ; then
228 ewarn " We've already been run in this tree; you should"
229 ewarn " avoid this if possible (perhaps by filing a bug)"
233 [[ -f ${d}/ltmain.sh ]] &&
234 for p in ${elt_patches} ; do
239 # Stupid test to see if its already applied ...
240 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
241 ELT_walk_patches "${d}/ltmain.sh" "${p}"
246 ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}"
250 # Do not apply if we do not have the relink patch applied ...
251 if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" ; then
252 ELT_walk_patches "${d}/ltmain.sh" "${p}"
257 # Do not apply if $max_cmd_len is not used ...
258 if grep -qs 'max_cmd_len' "${d}/ltmain.sh" ; then
259 ELT_walk_patches "${d}/ltmain.sh" "${p}"
264 ELT_walk_patches "${d}/ltmain.sh" "${p}"
268 # Newer libtoolize clears ltconfig, as not used anymore
269 if [[ -s ${d}/ltconfig ]] ; then
270 ELT_walk_patches "${d}/ltconfig" "${p}"
275 if [[ -s ${d}/ltconfig ]] ; then
276 ELT_walk_patches "${d}/ltconfig" "${p}"
281 # Newer libtoolize clears ltconfig, as not used anymore
282 if [[ -s ${d}/ltconfig ]] ; then
283 ELT_walk_patches "${d}/ltconfig" "${p}"
288 # special case to avoid false positives (failing to apply
289 # ltmain.sh path message), newer libtools have this patch
290 # built in, so not much to patch around then
291 if [[ -e ${d}/ltmain.sh ]] && \
292 ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh" ; then
293 ELT_walk_patches "${d}/ltmain.sh" "${p}"
298 ELT_walk_patches "${d}/install-sh" "${p}"
302 if tc-is-cross-compiler ; then
303 ELT_walk_patches "${d}/ltmain.sh" "${p}"
308 ELT_walk_patches "${d}/ltmain.sh" "${p}"
313 if [[ ${ret} -ne 0 ]] ; then
316 local version=$(ELT_libtool_version "${d}/ltmain.sh")
317 # Critical patch, but could be applied ...
318 # FIXME: Still need a patch for ltmain.sh > 1.4.0
319 if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && \
320 [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]] ; then
321 ewarn " Could not apply relink.patch!"
325 # Critical patch - for this one we abort, as it can really
326 # cause breakage without it applied!
327 if [[ ${do_portage} == "yes" ]] ; then
328 # Stupid test to see if its already applied ...
329 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
331 eerror "Portage patch requested, but failed to apply!"
332 eerror "Please file a bug report to add a proper patch."
333 die "Portage patch requested, but failed to apply!"
336 if grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
337 # ewarn " Portage patch seems to be already applied."
338 # ewarn " Please verify that it is not needed."
341 local version=$(ELT_libtool_version "${d}"/ltmain.sh)
343 eerror "Portage patch failed to apply (ltmain.sh version ${version})!"
344 eerror "Please file a bug report to add a proper patch."
345 die "Portage patch failed to apply!"
347 # We do not want to run libtoolize ...
348 ELT_APPLIED_PATCHES="portage"
352 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
358 # makes sense for ltmain.sh patches only
359 [[ -f ${d}/ltmain.sh ]] &&
360 if [[ -z ${ELT_APPLIED_PATCHES} ]] ; then
361 if [[ ${do_portage} == "no" && \
362 ${do_reversedeps} == "no" && \
363 ${do_only_patches} == "no" && \
364 ${deptoremove} == "" ]]
366 ewarn "Cannot apply any patches, please file a bug about this"
372 [[ -f ${d}/configure ]] &&
373 for p in ${elt_patches} ; do
378 if grep -qs 'Transform linux' "${d}/configure" ; then
379 ELT_walk_patches "${d}/configure" "${p}"
384 if grep -qs 'version_type=freebsd-' "${d}/configure" ; then
385 ELT_walk_patches "${d}/configure" "${p}"
390 if grep -qs '&& echo \.so ||' "${d}/configure" ; then
391 ELT_walk_patches "${d}/configure" "${p}"
398 # apply multiple patches as often as they match
399 while [[ $subret -eq 0 ]]; do
401 if [[ -e ${d}/configure ]]; then
402 ELT_walk_patches "${d}/configure" "${p}"
405 if [[ $subret -eq 0 ]]; then
406 # have at least one patch succeeded.
411 mint-conf|gold-conf|sol2-conf)
412 ELT_walk_patches "${d}/configure" "${p}"
416 ELT_walk_patches "${d}/configure" "${p}"
420 # ltmain.sh patches are applied above
424 if [[ ${ret} -ne 0 ]] ; then
427 [[ ${CHOST} == *-uclibc ]] && ewarn " uClibc patch set '${p}' failed to apply!"
430 if [[ ${CHOST} == *-freebsd* ]] ; then
431 if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux' \
432 "${d}/configure" 2>/dev/null) ]]; then
433 eerror " FreeBSD patch set '${p}' failed to apply!"
434 die "FreeBSD patch set '${p}' failed to apply!"
439 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
447 > "${d}/.elibtoolized"
451 uclibctoolize() { die "Use elibtoolize"; }
452 darwintoolize() { die "Use elibtoolize"; }
454 # char *VER_major(string)
456 # Return the Major (X of X.Y.Z) version
459 [[ -z $1 ]] && return 1
462 echo "${VER%%[^[:digit:]]*}"
465 # char *VER_minor(string)
467 # Return the Minor (Y of X.Y.Z) version
470 [[ -z $1 ]] && return 1
474 echo "${VER%%[^[:digit:]]*}"
477 # char *VER_micro(string)
479 # Return the Micro (Z of X.Y.Z) version.
482 [[ -z $1 ]] && return 1
486 echo "${VER%%[^[:digit:]]*}"
489 # int VER_to_int(string)
491 # Convert a string type version (2.4.0) to an int (132096)
492 # for easy compairing or versions ...
495 [[ -z $1 ]] && return 1
497 local VER_MAJOR=$(VER_major "$1")
498 local VER_MINOR=$(VER_minor "$1")
499 local VER_MICRO=$(VER_micro "$1")
500 local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ))
502 # We make version 1.0.0 the minimum version we will handle as
503 # a sanity check ... if its less, we fail ...
504 if [[ ${VER_int} -ge 65536 ]] ; then