--- misc-functions.sh.old 2009-05-05 22:18:46.000000000 +0200 +++ misc-functions.sh 2009-05-05 23:29:48.000000000 +0200 @@ -463,10 +463,142 @@ fi done done [[ ${abort} == yes ]] && die "multilib-strict check failed!" fi + + if hasq fixlafiles ${FEATURES} && [[ -x /usr/bin/find ]] + then + labanner=true + while read -r lafile + do + if [[ "$labanner" == "true" ]] + then + vecho "fixing .la link references" + labanner=false + fi + vecho " ${lafile:${#D}}" + local has_inh_link_flags="no" + local new_inh_link_flags="" + local dependency_libs="" + local inh_link_flags="" + local has_dep_libs="no" + local new_dep_libs="" + local remove_lib="" + local contents="$(<"${lafile}")" + local libladir="" + local librpath="" + local dep_libs="" + local NEWLINE=$'\n' + local line="" + local lib="" + + # Extract the dependency_libs and inherited_linker_flags + # variables from the .la file. Technically a .la file + # should be posix sh, so should be sourceable. But we + # know better than to trust random files with source(). + # We extract. + save_IFS="${IFS}" + IFS="$NEWLINE" + for line in $contents + do + if [[ "${line#dependency_libs=\'}" != "${line}" ]] + then + [[ "$has_dep_libs" == "no" ]] || { eqawarn "dependency_libs= assigned more than once in ${lafile:${#D}}"; continue 2; } + line="${line#dependency_libs=\'}" + dep_libs="${line%\'}" + has_dep_libs="yes" + + elif [[ "${line#inherited_linker_flags=\'}" != "${line}" ]] + then + + [[ "$has_inh_link_flags" == "no" ]] || { eqawarn "inherited_linker_flags= assigned more than once in ${lafile:${#D}}"; continue 2; } + line="${line#inherited_linker_flags=\'}" + inh_link_flags="${line%\'}" + new_inh_link_flags="${inh_link_flags}" + has_inh_link_flags="yes" + fi + done + IFS="$save_IFS" + + if [[ "$has_dep_libs" == "no" ]] + then + # Clearly, this is not libtool archive. + vecho "$lafile is not a libtool archive. Skipping." + continue + fi + + # We can assume that as long as the format doesn't change + # radically, paths won't contain spaces. + for entry in $dep_libs + do + case $entry in + -l*) + has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}" + ;; + *.la) + + if [[ "${entry##*\/lib}" == "${entry}" ]] + then + # When we get here, we're dealing with something that + # can't be replaced with a -llibrary entry. Just put it + # in dep_libs. + has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}" + else + lib="${entry##*\/lib}" + lib="${lib%.la}" + lib="-l${lib}" + has ${lib} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${lib}" + has -L${entry%/*.la} ${libladir} || libladir="${libladir} -L${entry%/*.la}" + fi + ;; + -L*) + # Do some path clean-up, so we eliminate redundant entries. + [[ ${entry/X11R6\/lib} != ${entry} ]] && entry="${entry/X11R6\/}" + [[ ${entry/usr\/lib*\/pkgconfig\/..\/..} != ${entry} ]] && entry="${entry/\/lib*\/pkgconfig\/..\/..}" + [[ ${entry/usr\/lib*\/pkgconfig\/..} != ${entry} ]] && entry="${entry/\/pkgconfig\/..}" + has ${entry} ${libladir} || libladir="${libladir} ${entry}" + ;; + -R*) + has ${entry} ${librpath} || librpath="${librpath} ${entry}" + ;; + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + # If we got here, we're probably in a libtool-1.5 file, so we + # won't have inherited_linker_flags, but there was a bug in early + # libtool-2.2 that would mean that -pthread would be put in + # dependency_libs + if [[ "${has_inh_link_flags}" == "yes" ]] + then + has ${entry} ${new_inh_link_flags} || new_inh_link_flags="${new_inh_link_flags} ${entry}" + else + has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}" + fi + ;; + *) + # Unkown thingie. Put before all the dep_libs so it can work on + # them if it's that kind of a thingie. After ladirs and rpaths so + # they can work on it if it's that kind of thingie. + # I've never encountered such a thingie, so this is an attempt + # at a reasonable default. Doing die() is probably not acceptable. + new_dep_libs="${entry} ${new_dep_libs}" + ;; + esac + done + + # We got the same result as libtool, abort early so we don't have + # to write to disk. + [[ "${dep_libs}" == "${librpath}${libladir}${new_dep_libs}" && "${new_inh_link_flags}" == "${inh_link_flags}" ]] && continue + + # Replace dependency_libs and inherited_linker_flags with our + # generated values. Write to disk. + contents="${contents/${NEWLINE}dependency_libs=\'${dep_libs}\'${NEWLINE}/${NEWLINE}dependency_libs='${librpath}${libladir}${new_dep_libs}'${NEWLINE}}" + [[ "${has_inh_link_flags}" == "yes" ]] && \ + contents="${contents/${NEWLINE}inherited_linker_flags=\'${inh_link_flags}\'${NEWLINE}/${NEWLINE}inherited_linker_flags='${new_inh_link_flags}'${NEWLINE}}" + + printf '%s' "$contents" > "${lafile}" + done < <(find "${D}" -type f -name '*.la') + fi } install_mask() { local root="$1"