diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index 5f7f45dc4437..958747d34046 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -731,6 +731,10 @@ If set, files in `$out/sbin` are not moved to `$out/bin`. By default, they are. List of directories to search for libraries and executables from which *all* symbols should be stripped. By default, it’s empty. Stripping all symbols is risky, since it may remove not just debug symbols but also ELF information necessary for normal execution. +##### `stripAllListTarget` {#var-stdenv-stripAllListTarget} + +Like `stripAllList`, but only applies to packages’ target platform. By default, it’s empty. Useful when supporting cross compilation. + ##### `stripAllFlags` {#var-stdenv-stripAllFlags} Flags passed to the `strip` command applied to the files in the directories listed in `stripAllList`. Defaults to `-s` (i.e. `--strip-all`). @@ -739,6 +743,10 @@ Flags passed to the `strip` command applied to the files in the directories list List of directories to search for libraries and executables from which only debugging-related symbols should be stripped. It defaults to `lib lib32 lib64 libexec bin sbin`. +##### `stripDebugListTarget` {#var-stdenv-stripDebugListTarget} + +Like `stripDebugList`, but only applies to packages’ target platform. By default, it’s empty. Useful when supporting cross compilation. + ##### `stripDebugFlags` {#var-stdenv-stripDebugFlags} Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`). diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index a23b203aff56..9d0b163f4c46 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -7,31 +7,29 @@ _doStrip() { # to $out anyways---if it does, that's a bigger problem that a lack of # stripping will help catch. local -ra flags=(dontStripHost dontStripTarget) + local -ra debugDirs=(stripDebugList stripDebugListTarget) + local -ra allDirs=(stripAllList stripAllListTarget) local -ra stripCmds=(STRIP STRIP_FOR_TARGET) - # Optimization - if [[ "${STRIP-}" == "${STRIP_FOR_TARGET-}" ]]; then - dontStripTarget+=1 - fi + # Strip only host paths by default. Leave targets as is. + stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} + stripDebugListTarget=${stripDebugListTarget:-} + stripAllList=${stripAllList:-} + stripAllListTarget=${stripAllListTarget:-} local i for i in ${!stripCmds[@]}; do local -n flag="${flags[$i]}" + local -n debugDirList="${debugDirs[$i]}" + local -n allDirList="${allDirs[$i]}" local -n stripCmd="${stripCmds[$i]}" # `dontStrip` disables them all if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null then continue; fi - stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} - if [ -n "$stripDebugList" ]; then - stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}" - fi - - stripAllList=${stripAllList:-} - if [ -n "$stripAllList" ]; then - stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}" - fi + stripDirs "$stripCmd" "$debugDirList" "${stripDebugFlags:--S}" + stripDirs "$stripCmd" "$allDirList" "${stripAllFlags:--s}" done } @@ -50,8 +48,7 @@ stripDirs() { dirs=${dirsNew} if [ -n "${dirs}" ]; then - header "stripping (with command $cmd and flags $stripFlags) in$dirs" + echo "stripping (with command $cmd and flags $stripFlags) in$dirs" find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null - stopNest fi }