nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 73 lines 3.0 kB view raw
1# This setup hook strips libraries and executables in the fixup phase. 2 3fixupOutputHooks+=(_doStrip) 4 5_doStrip() { 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 debugDirs=(stripDebugList stripDebugListTarget) 11 local -ra allDirs=(stripAllList stripAllListTarget) 12 local -ra stripCmds=(STRIP STRIP_FOR_TARGET) 13 local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET) 14 15 # TODO(structured-attrs): This doesn't work correctly if one of 16 # the items in strip*List or strip*Flags contains a space, 17 # even with structured attrs enabled. This is OK for now 18 # because very few packages set any of these, and it doesn't 19 # affect any of them. 20 # 21 # After __structuredAttrs = true is universal, come back and 22 # push arrays all the way through this logic. 23 24 # Strip only host paths by default. Leave targets as is. 25 stripDebugList=${stripDebugList[*]:-lib lib32 lib64 libexec bin sbin} 26 stripDebugListTarget=${stripDebugListTarget[*]:-} 27 stripAllList=${stripAllList[*]:-} 28 stripAllListTarget=${stripAllListTarget[*]:-} 29 30 local i 31 for i in ${!stripCmds[@]}; do 32 local -n flag="${flags[$i]}" 33 local -n debugDirList="${debugDirs[$i]}" 34 local -n allDirList="${allDirs[$i]}" 35 local -n stripCmd="${stripCmds[$i]}" 36 local -n ranlibCmd="${ranlibCmds[$i]}" 37 38 # `dontStrip` disables them all 39 if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null 1>&2 40 then continue; fi 41 42 stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags[*]:--S -p}" 43 stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags[*]:--s -p}" 44 done 45} 46 47stripDirs() { 48 local cmd="$1" 49 local ranlibCmd="$2" 50 local paths="$3" 51 local stripFlags="$4" 52 local pathsNew= 53 54 local p 55 for p in ${paths}; do 56 if [ -e "$prefix/$p" ]; then 57 pathsNew="${pathsNew} $prefix/$p" 58 fi 59 done 60 paths=${pathsNew} 61 62 if [ -n "${paths}" ]; then 63 echo "stripping (with command $cmd and flags $stripFlags) in $paths" 64 # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh. 65 find $paths -type f -a '!' -wholename "$prefix/lib/debug/*" -exec $cmd $stripFlags '{}' \; 2>/dev/null 66 # 'strip' does not normally preserve archive index in .a files. 67 # This usually causes linking failures against static libs like: 68 # ld: ...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a: 69 # error adding symbols: archive has no index; run ranlib to add one 70 # Restore the index by running 'ranlib'. 71 find $paths -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null 72 fi 73}