146 lines
4.1 KiB
Bash
146 lines
4.1 KiB
Bash
#!/bin/bash
|
|
|
|
source "${PALUDIS_EBUILD_DIR}/echo_functions.bash"
|
|
|
|
prune_libtool_files() {
|
|
local removing_all removing_modules opt
|
|
for opt; do
|
|
case "${opt}" in
|
|
--all)
|
|
removing_all=1
|
|
removing_modules=1
|
|
;;
|
|
--modules)
|
|
removing_modules=1
|
|
;;
|
|
*)
|
|
die "Invalid argument to ${FUNCNAME}(): ${opt}"
|
|
esac
|
|
done
|
|
|
|
local f
|
|
local queue=()
|
|
while IFS= read -r -d '' f; do # for all .la files
|
|
local archivefile=${f/%.la/.a}
|
|
|
|
# The following check is done by libtool itself.
|
|
# It helps us avoid removing random files which match '*.la',
|
|
# see bug #468380.
|
|
if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
|
|
continue
|
|
fi
|
|
|
|
[[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
|
|
local reason= pkgconfig_scanned=
|
|
local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
|
|
|
|
if [[ ${snotlink} == yes ]]; then
|
|
|
|
# Remove static libs we're not supposed to link against.
|
|
if [[ -f ${archivefile} ]]; then
|
|
einfo "Removing unnecessary ${archivefile#${IMAGE%/}} (static plugin)"
|
|
queue+=( "${archivefile}" )
|
|
fi
|
|
|
|
# The .la file may be used by a module loader, so avoid removing it
|
|
# unless explicitly requested.
|
|
if [[ ${removing_modules} ]]; then
|
|
reason='module'
|
|
fi
|
|
|
|
else
|
|
|
|
# Remove .la files when:
|
|
# - user explicitly wants us to remove all .la files,
|
|
# - respective static archive doesn't exist,
|
|
# - they are covered by a .pc file already,
|
|
# - they don't provide any new information (no libs & no flags).
|
|
|
|
if [[ ${removing_all} ]]; then
|
|
reason='requested'
|
|
elif [[ ! -f ${archivefile} ]]; then
|
|
reason='no static archive'
|
|
elif [[ ! $(sed -nre \
|
|
"s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
|
|
"${f}") ]]; then
|
|
reason='no libs & flags'
|
|
else
|
|
if [[ ! ${pkgconfig_scanned} ]]; then
|
|
# Create a list of all .pc-covered libs.
|
|
local pc_libs=()
|
|
if [[ ! ${removing_all} ]]; then
|
|
local pc
|
|
local tf=${T}/prune-lt-files.pc
|
|
local pkgconf=${PKG_CONFIG}
|
|
|
|
while IFS= read -r -d '' pc; do # for all .pc files
|
|
local arg libs
|
|
|
|
# Use pkg-config if available (and works),
|
|
# fallback to sed.
|
|
if ${pkgconf} --exists "${pc}" &>/dev/null; then
|
|
sed -e '/^Requires:/d' "${pc}" > "${tf}"
|
|
libs=$(${pkgconf} --libs "${tf}")
|
|
else
|
|
libs=$(sed -ne 's/^Libs://p' "${pc}")
|
|
fi
|
|
|
|
for arg in ${libs}; do
|
|
if [[ ${arg} == -l* ]]; then
|
|
if [[ ${arg} == '*$*' ]]; then
|
|
ewarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
|
|
ewarn "(arg: ${arg})"
|
|
ewarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
|
|
fi
|
|
|
|
pc_libs+=( lib${arg#-l}.la )
|
|
fi
|
|
done
|
|
done < <(find "${IMAGE}" -type f -name '*.pc' -print0)
|
|
|
|
rm -f "${tf}"
|
|
fi
|
|
|
|
pkgconfig_scanned=1
|
|
fi # pkgconfig_scanned
|
|
|
|
has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
|
|
fi # removal due to .pc
|
|
|
|
fi # shouldnotlink==no
|
|
|
|
if [[ ${reason} ]]; then
|
|
einfo "Removing unnecessary ${f#${IMAGE%/}} (${reason})"
|
|
queue+=( "${f}" )
|
|
fi
|
|
done < <(find "${IMAGE}" -xtype f -name '*.la' -print0)
|
|
|
|
if [[ ${queue[@]} ]]; then
|
|
rm -f "${queue[@]}"
|
|
fi
|
|
}
|
|
|
|
if [[ "${CATEGORY}/${PN}" != "sys-devel/gcc" &&
|
|
"${CATEGORY}/${PN}" != "dev-libs/openssl" &&
|
|
"${CATEGORY}/${PN}" != "dev-libs/libressl" &&
|
|
"${CATEGORY}/${PN}" != "sys-libs/db" &&
|
|
"${CATEGORY}/${PN}" != "media-libs/giflib" &&
|
|
"${CATEGORY}/${PN}" != "dev-libs/gmp" &&
|
|
"${CATEGORY}/${PN}" != "dev-lang/mono" &&
|
|
"${CATEGORY}/${PN}" != "media-libs/libpng" &&
|
|
"${CATEGORY}/${PN}" != "sys-devel/binutils" &&
|
|
"${CATEGORY}/${PN}" != "dev-lang/llvm" &&
|
|
"${CATEGORY}/${PN}" != "dev-lang/clang" &&
|
|
"${CATEGORY}/${PN}" != "media-gfx/ImageMagick" &&
|
|
"${CATEGORY}/${PN}" != "sys-libs/libstdc++" &&
|
|
"${CATEGORY}/${PN}" != "app-text/opensp" &&
|
|
"${CATEGORY}/${PN}" != "x11-libs/graphite2" &&
|
|
"${CATEGORY}/${PN}" != "sys-apps/dbus" &&
|
|
"${CATEGORY}/${PN}" != "sys-apps/util-linux" &&
|
|
"${CATEGORY}/${PN}" != "media-libs/freetype" &&
|
|
"${CATEGORY}/${PN}" != "dev-libs/expat"
|
|
]] ; then
|
|
prune_libtool_files --all
|
|
fi
|
|
|