2014-06-27 11:33:05 +00:00
|
|
|
# This setup hook strips libraries and executables in the fixup phase.
|
|
|
|
|
2014-07-08 11:47:09 +00:00
|
|
|
fixupOutputHooks+=(_doStrip)
|
2014-06-27 11:33:05 +00:00
|
|
|
|
|
|
|
_doStrip() {
|
2017-07-07 19:57:01 +00:00
|
|
|
# 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-07-22 20:22:50 +00:00
|
|
|
local -ra debugDirs=(stripDebugList stripDebugListTarget)
|
|
|
|
local -ra allDirs=(stripAllList stripAllListTarget)
|
2022-07-22 17:38:02 +00:00
|
|
|
local -ra stripCmds=(STRIP STRIP_FOR_TARGET)
|
2022-07-23 09:02:51 +00:00
|
|
|
local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET)
|
2017-07-07 19:57:01 +00:00
|
|
|
|
2022-07-22 20:22:50 +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:-}
|
2017-07-07 19:57:01 +00:00
|
|
|
|
|
|
|
local i
|
|
|
|
for i in ${!stripCmds[@]}; do
|
|
|
|
local -n flag="${flags[$i]}"
|
2022-07-22 20:22:50 +00:00
|
|
|
local -n debugDirList="${debugDirs[$i]}"
|
|
|
|
local -n allDirList="${allDirs[$i]}"
|
2017-07-07 19:57:01 +00:00
|
|
|
local -n stripCmd="${stripCmds[$i]}"
|
2022-07-23 09:02:51 +00:00
|
|
|
local -n ranlibCmd="${ranlibCmds[$i]}"
|
2017-07-07 19:57:01 +00:00
|
|
|
|
|
|
|
# `dontStrip` disables them all
|
2019-10-29 23:42:31 +00:00
|
|
|
if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null
|
2017-07-07 19:57:01 +00:00
|
|
|
then continue; fi
|
|
|
|
|
2022-07-23 09:02:51 +00:00
|
|
|
stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags:--S}"
|
|
|
|
stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags:--s}"
|
2017-07-07 19:57:01 +00:00
|
|
|
done
|
2014-06-27 11:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stripDirs() {
|
2017-07-07 19:57:01 +00:00
|
|
|
local cmd="$1"
|
2022-07-23 09:02:51 +00:00
|
|
|
local ranlibCmd="$2"
|
|
|
|
local dirs="$3"
|
|
|
|
local stripFlags="$4"
|
2014-06-27 11:33:05 +00:00
|
|
|
local dirsNew=
|
|
|
|
|
2017-07-07 19:57:01 +00:00
|
|
|
local d
|
2014-06-27 11:33:05 +00:00
|
|
|
for d in ${dirs}; do
|
|
|
|
if [ -d "$prefix/$d" ]; then
|
|
|
|
dirsNew="${dirsNew} $prefix/$d "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
dirs=${dirsNew}
|
|
|
|
|
|
|
|
if [ -n "${dirs}" ]; then
|
2022-07-22 20:22:50 +00:00
|
|
|
echo "stripping (with command $cmd and flags $stripFlags) in$dirs"
|
2021-09-17 14:59:12 +00:00
|
|
|
find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null
|
2022-07-23 09:02:51 +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'.
|
|
|
|
find $dirs -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null
|
2014-06-27 11:33:05 +00:00
|
|
|
fi
|
|
|
|
}
|