1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: libtool.eclass
6 # base-system@gentoo.org
7 # @BLURB: quickly update bundled libtool code
9 # This eclass patches ltmain.sh distributed with libtoolized packages with the
10 # relink and portage patch among others
12 # Note, this eclass does not require libtool as it only applies patches to
13 # generated libtool files. We do not run the libtoolize program because that
14 # requires a regeneration of the main autotool files in order to work properly.
16 if [[ -z ${_LIBTOOL_ECLASS} ]]; then
19 DEPEND=">=app-portage/elt-patches-20170317"
21 libtool_elt_patch_dir() {
22 echo "${EPREFIX}/usr/share/elt-patches"
25 inherit multilib toolchain-funcs
28 # See if we can apply $2 on $1, and if so, do it
30 ELT_try_and_apply_patch() {
35 local disp="${src} patch"
36 local log="${T}/elibtool.log"
38 if [[ -z ${_ELT_NOTED_TMP} ]] ; then
40 printf 'temp patch: %s\n' "${patch}" > "${log}"
42 printf '\nTrying %s\n' "${disp}" >> "${log}"
44 if [[ ! -e ${file} ]] ; then
45 echo "File not found: ${file}" >> "${log}"
49 # Save file for permission restoration. `patch` sometimes resets things.
50 # Ideally we'd want 'stat -c %a', but stat is highly non portable and we are
51 # guaranted to have GNU find, so use that instead.
52 local perms="$(find ${file} -maxdepth 0 -printf '%m')"
53 # We only support patchlevel of 0 - why worry if its static patches?
54 if patch -p0 --dry-run "${file}" "${patch}" >> "${log}" 2>&1 ; then
55 einfo " Applying ${disp} ..."
56 patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${log}" 2>&1
58 export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${src}"
62 chmod "${perms}" "${file}"
68 # Get string version of ltmain.sh or ltconfig (passed as $1)
70 ELT_libtool_version() {
73 eval $(grep -e '^[[:space:]]*VERSION=' "$1")
79 # Run through the patches in $2 and see if any
87 local patch_dir="$(libtool_elt_patch_dir)/${patch_set}"
90 [[ -z ${patch_set} ]] && return 1
91 [[ ! -d ${patch_dir} ]] && return 1
93 # Allow patches to use @GENTOO_LIBDIR@ replacements
94 local sed_args=( -e "s:@GENTOO_LIBDIR@:$(get_libdir):g" )
95 if [[ -n ${rem_int_dep} ]] ; then
96 # replace @REM_INT_DEP@ with what was passed
97 # to --remove-internal-dep
98 sed_args+=( -e "s|@REM_INT_DEP@|${rem_int_dep}|g" )
101 pushd "$(libtool_elt_patch_dir)" >/dev/null || die
103 # Go through the patches in reverse order (newer version to older)
104 for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r) ; do
105 tmp="${T}/libtool-elt.patch"
106 sed "${sed_args[@]}" "${patch}" > "${tmp}" || die
107 if ELT_try_and_apply_patch "${file}" "${tmp}" "${patch}" ; then
108 # Break to unwind w/popd rather than return directly
118 # @FUNCTION: elibtoolize
119 # @USAGE: [dirs] [--portage] [--reverse-deps] [--patch-only] [--remove-internal-dep=xxx] [--shallow] [--no-uclibc]
121 # Apply a smorgasbord of patches to bundled libtool files. This function
122 # should always be safe to run. If no directories are specified, then
123 # ${S} will be searched for appropriate files.
125 # If the --shallow option is used, then only ${S}/ltmain.sh will be patched.
127 # The other options should be avoided in general unless you know what's going on.
131 local do_portage="no"
132 local do_reversedeps="yes"
133 local do_only_patches="no"
134 local do_uclibc="yes"
136 local do_shallow="no"
138 local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed target-nm ppc64le"
143 # Only apply portage patch, and don't
144 # 'libtoolize --copy --force' if all patches fail.
148 # Apply the reverse-deps patch
149 # http://bugzilla.gnome.org/show_bug.cgi?id=75635
151 elt_patches+=" fix-relink"
154 # Do not run libtoolize if none of the patches apply ..
155 do_only_patches="yes"
157 --remove-internal-dep=*)
158 # We will replace @REM_INT_DEP@ with what is needed
159 # in ELT_walk_patches() ...
160 deptoremove=${x#--remove-internal-dep=}
162 # Add the patch for this ...
163 [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
166 # Only patch the ltmain.sh in ${S}
176 eerror "Invalid elibtoolize option: ${x}"
177 die "elibtoolize called with ${x} ??"
183 [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf"
186 *-aix*) elt_patches+=" hardcode aixrtl" ;; #213277
187 *-darwin*) elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf" ;;
188 *-solaris*) elt_patches+=" sol2-conf sol2-ltmain" ;;
189 *-freebsd*) elt_patches+=" fbsd-conf fbsd-ltconf" ;;
190 *-hpux*) elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc" ;;
191 *-irix*) elt_patches+=" irix-ltmain" ;;
192 *-mint*) elt_patches+=" mint-conf" ;;
195 if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
196 elt_patches+=" gold-conf"
199 # Find out what dirs to scan.
200 if [[ ${do_shallow} == "yes" ]] ; then
201 [[ ${#dirs[@]} -ne 0 ]] && die "Using --shallow with explicit dirs doesn't make sense"
202 [[ -f ${S}/ltmain.sh || -f ${S}/configure ]] && dirs+=( "${S}" )
204 [[ ${#dirs[@]} -eq 0 ]] && dirs+=( "${S}" )
205 dirs=( $(find "${dirs[@]}" '(' -name ltmain.sh -o -name configure ')' -printf '%h\n' | sort -u) )
209 for d in "${dirs[@]}" ; do
210 export ELT_APPLIED_PATCHES=
212 if [[ -f ${d}/.elibtoolized ]] ; then
216 local outfunc="einfo"
217 [[ -f ${d}/.elibtoolized ]] && outfunc="ewarn"
218 ${outfunc} "Running elibtoolize in: ${d#${WORKDIR}/}/"
219 if [[ ${outfunc} == "ewarn" ]] ; then
220 ewarn " We've already been run in this tree; you should"
221 ewarn " avoid this if possible (perhaps by filing a bug)"
225 [[ -f ${d}/ltmain.sh ]] &&
226 for p in ${elt_patches} ; do
231 # Stupid test to see if its already applied ...
232 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
233 ELT_walk_patches "${d}/ltmain.sh" "${p}"
238 ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}"
242 # Do not apply if we do not have the relink patch applied ...
243 if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" ; then
244 ELT_walk_patches "${d}/ltmain.sh" "${p}"
249 # Do not apply if $max_cmd_len is not used ...
250 if grep -qs 'max_cmd_len' "${d}/ltmain.sh" ; then
251 ELT_walk_patches "${d}/ltmain.sh" "${p}"
256 ELT_walk_patches "${d}/ltmain.sh" "${p}"
260 # Newer libtoolize clears ltconfig, as not used anymore
261 if [[ -s ${d}/ltconfig ]] ; then
262 ELT_walk_patches "${d}/ltconfig" "${p}"
267 if [[ -s ${d}/ltconfig ]] ; then
268 ELT_walk_patches "${d}/ltconfig" "${p}"
273 # Newer libtoolize clears ltconfig, as not used anymore
274 if [[ -s ${d}/ltconfig ]] ; then
275 ELT_walk_patches "${d}/ltconfig" "${p}"
280 # special case to avoid false positives (failing to apply
281 # ltmain.sh path message), newer libtools have this patch
282 # built in, so not much to patch around then
283 if [[ -e ${d}/ltmain.sh ]] && \
284 ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh" ; then
285 ELT_walk_patches "${d}/ltmain.sh" "${p}"
290 ELT_walk_patches "${d}/install-sh" "${p}"
294 if tc-is-cross-compiler ; then
295 ELT_walk_patches "${d}/ltmain.sh" "${p}"
300 ELT_walk_patches "${d}/ltmain.sh" "${p}"
305 if [[ ${ret} -ne 0 ]] ; then
308 local version=$(ELT_libtool_version "${d}/ltmain.sh")
309 # Critical patch, but could be applied ...
310 # FIXME: Still need a patch for ltmain.sh > 1.4.0
311 if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && \
312 [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]] ; then
313 ewarn " Could not apply relink.patch!"
317 # Critical patch - for this one we abort, as it can really
318 # cause breakage without it applied!
319 if [[ ${do_portage} == "yes" ]] ; then
320 # Stupid test to see if its already applied ...
321 if ! grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
323 eerror "Portage patch requested, but failed to apply!"
324 eerror "Please file a bug report to add a proper patch."
325 die "Portage patch requested, but failed to apply!"
328 if grep -qs 'We do not want portage' "${d}/ltmain.sh" ; then
329 # ewarn " Portage patch seems to be already applied."
330 # ewarn " Please verify that it is not needed."
333 local version=$(ELT_libtool_version "${d}"/ltmain.sh)
335 eerror "Portage patch failed to apply (ltmain.sh version ${version})!"
336 eerror "Please file a bug report to add a proper patch."
337 die "Portage patch failed to apply!"
339 # We do not want to run libtoolize ...
340 ELT_APPLIED_PATCHES="portage"
344 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
350 # makes sense for ltmain.sh patches only
351 [[ -f ${d}/ltmain.sh ]] &&
352 if [[ -z ${ELT_APPLIED_PATCHES} ]] ; then
353 if [[ ${do_portage} == "no" && \
354 ${do_reversedeps} == "no" && \
355 ${do_only_patches} == "no" && \
356 ${deptoremove} == "" ]]
358 ewarn "Cannot apply any patches, please file a bug about this"
364 [[ -f ${d}/configure ]] &&
365 for p in ${elt_patches} ; do
370 if grep -qs 'Transform linux' "${d}/configure" ; then
371 ELT_walk_patches "${d}/configure" "${p}"
376 if grep -qs 'version_type=freebsd-' "${d}/configure" ; then
377 ELT_walk_patches "${d}/configure" "${p}"
382 if grep -qs '&& echo \.so ||' "${d}/configure" ; then
383 ELT_walk_patches "${d}/configure" "${p}"
390 # apply multiple patches as often as they match
391 while [[ $subret -eq 0 ]]; do
393 if [[ -e ${d}/configure ]]; then
394 ELT_walk_patches "${d}/configure" "${p}"
397 if [[ $subret -eq 0 ]]; then
398 # have at least one patch succeeded.
403 mint-conf|gold-conf|sol2-conf)
404 ELT_walk_patches "${d}/configure" "${p}"
408 ELT_walk_patches "${d}/configure" "${p}"
412 ELT_walk_patches "${d}/configure" "${p}"
416 # ltmain.sh patches are applied above
420 if [[ ${ret} -ne 0 ]] ; then
423 [[ ${CHOST} == *-uclibc ]] && ewarn " uClibc patch set '${p}' failed to apply!"
426 if [[ ${CHOST} == *-freebsd* ]] ; then
427 if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux' \
428 "${d}/configure" 2>/dev/null) ]]; then
429 eerror " FreeBSD patch set '${p}' failed to apply!"
430 die "FreeBSD patch set '${p}' failed to apply!"
435 [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
443 > "${d}/.elibtoolized"
447 uclibctoolize() { die "Use elibtoolize"; }
448 darwintoolize() { die "Use elibtoolize"; }
450 # char *VER_major(string)
452 # Return the Major (X of X.Y.Z) version
455 [[ -z $1 ]] && return 1
458 echo "${VER%%[^[:digit:]]*}"
461 # char *VER_minor(string)
463 # Return the Minor (Y of X.Y.Z) version
466 [[ -z $1 ]] && return 1
470 echo "${VER%%[^[:digit:]]*}"
473 # char *VER_micro(string)
475 # Return the Micro (Z of X.Y.Z) version.
478 [[ -z $1 ]] && return 1
482 echo "${VER%%[^[:digit:]]*}"
485 # int VER_to_int(string)
487 # Convert a string type version (2.4.0) to an int (132096)
488 # for easy compairing or versions ...
491 [[ -z $1 ]] && return 1
493 local VER_MAJOR=$(VER_major "$1")
494 local VER_MINOR=$(VER_minor "$1")
495 local VER_MICRO=$(VER_micro "$1")
496 local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ))
498 # We make version 1.0.0 the minimum version we will handle as
499 # a sanity check ... if its less, we fail ...
500 if [[ ${VER_int} -ge 65536 ]] ; then