2020-04-24 23:36:52 +00:00
|
|
|
# This setup hook strips libraries and executables in the fixup phase.
|
|
|
|
|
|
|
|
fixupOutputHooks+=(_doStrip)
|
|
|
|
|
|
|
|
_doStrip() {
|
|
|
|
# We don't bother to strip build platform code because it shouldn't make it
|
|
|
|
# to $out anyways---if it does, that's a bigger problem that a lack of
|
|
|
|
# stripping will help catch.
|
|
|
|
local -ra flags=(dontStripHost dontStripTarget)
|
2022-08-12 12:06:08 +00:00
|
|
|
local -ra debugDirs=(stripDebugList stripDebugListTarget)
|
|
|
|
local -ra allDirs=(stripAllList stripAllListTarget)
|
|
|
|
local -ra stripCmds=(STRIP STRIP_FOR_TARGET)
|
|
|
|
local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET)
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
# Strip only host paths by default. Leave targets as is.
|
|
|
|
stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
|
|
|
|
stripDebugListTarget=${stripDebugListTarget:-}
|
|
|
|
stripAllList=${stripAllList:-}
|
|
|
|
stripAllListTarget=${stripAllListTarget:-}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
local i
|
|
|
|
for i in ${!stripCmds[@]}; do
|
|
|
|
local -n flag="${flags[$i]}"
|
2022-08-12 12:06:08 +00:00
|
|
|
local -n debugDirList="${debugDirs[$i]}"
|
|
|
|
local -n allDirList="${allDirs[$i]}"
|
2020-04-24 23:36:52 +00:00
|
|
|
local -n stripCmd="${stripCmds[$i]}"
|
2022-08-12 12:06:08 +00:00
|
|
|
local -n ranlibCmd="${ranlibCmds[$i]}"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# `dontStrip` disables them all
|
|
|
|
if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null
|
|
|
|
then continue; fi
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags:--S}"
|
|
|
|
stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags:--s}"
|
2020-04-24 23:36:52 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
stripDirs() {
|
|
|
|
local cmd="$1"
|
2022-08-12 12:06:08 +00:00
|
|
|
local ranlibCmd="$2"
|
2022-09-09 14:08:57 +00:00
|
|
|
local paths="$3"
|
2022-08-12 12:06:08 +00:00
|
|
|
local stripFlags="$4"
|
2022-09-09 14:08:57 +00:00
|
|
|
local pathsNew=
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
local p
|
|
|
|
for p in ${paths}; do
|
|
|
|
if [ -e "$prefix/$p" ]; then
|
|
|
|
pathsNew="${pathsNew} $prefix/$p"
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
|
|
|
done
|
2022-09-09 14:08:57 +00:00
|
|
|
paths=${pathsNew}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
if [ -n "${paths}" ]; then
|
|
|
|
echo "stripping (with command $cmd and flags $stripFlags) in $paths"
|
|
|
|
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
|
|
|
|
find $paths -type f -a '!' -wholename "$prefix/lib/debug/*" -exec $cmd $stripFlags '{}' \; 2>/dev/null
|
2022-08-12 12:06:08 +00:00
|
|
|
# 'strip' does not normally preserve archive index in .a files.
|
|
|
|
# This usually causes linking failures against static libs like:
|
|
|
|
# ld: ...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a:
|
|
|
|
# error adding symbols: archive has no index; run ranlib to add one
|
|
|
|
# Restore the index by running 'ranlib'.
|
2022-09-09 14:08:57 +00:00
|
|
|
find $paths -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
|
|
|
}
|