strip setup hook: Learn about only stripping host/target binaries alone

`dontStrip` is still a catch-all, but `dontStripHost` and
`dontStripTarget` are also now available for finer-grained disabling.

+29 -8
+29 -8
pkgs/build-support/setup-hooks/strip.sh
··· 3 3 fixupOutputHooks+=(_doStrip) 4 4 5 5 _doStrip() { 6 - if [ -z "$dontStrip" ]; then 6 + # We don't bother to strip build platform code because it shouldn't make it 7 + # to $out anyways---if it does, that's a bigger problem that a lack of 8 + # stripping will help catch. 9 + local -ra flags=(dontStripHost dontStripTarget) 10 + local -ra stripCmds=(STRIP TARGET_STRIP) 11 + 12 + # Optimization 13 + if [[ "$STRIP" == "$TARGET_STRIP" ]]; then 14 + dontStripTarget+=1 15 + fi 16 + 17 + local i 18 + for i in ${!stripCmds[@]}; do 19 + local -n flag="${flags[$i]}" 20 + local -n stripCmd="${stripCmds[$i]}" 21 + 22 + # `dontStrip` disables them all 23 + if [[ "$dontStrip" || "$flag" ]] || ! type -f "$stripCmd" 2>/dev/null 24 + then continue; fi 25 + 7 26 stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} 8 27 if [ -n "$stripDebugList" ]; then 9 - stripDirs "$stripDebugList" "${stripDebugFlags:--S}" 28 + stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}" 10 29 fi 11 30 12 31 stripAllList=${stripAllList:-} 13 32 if [ -n "$stripAllList" ]; then 14 - stripDirs "$stripAllList" "${stripAllFlags:--s}" 33 + stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}" 15 34 fi 16 - fi 35 + done 17 36 } 18 37 19 38 stripDirs() { 20 - local dirs="$1" 21 - local stripFlags="$2" 39 + local cmd="$1" 40 + local dirs="$2" 41 + local stripFlags="$3" 22 42 local dirsNew= 23 43 44 + local d 24 45 for d in ${dirs}; do 25 46 if [ -d "$prefix/$d" ]; then 26 47 dirsNew="${dirsNew} $prefix/$d " ··· 29 50 dirs=${dirsNew} 30 51 31 52 if [ -n "${dirs}" ]; then 32 - header "stripping (with flags $stripFlags) in$dirs" 33 - find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $STRIP $commonStripFlags $stripFlags 2>/dev/null || true 53 + header "stripping (with command $cmd and flags $stripFlags) in$dirs" 54 + find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $cmd $commonStripFlags $stripFlags 2>/dev/null || true 34 55 stopNest 35 56 fi 36 57 }