eigenmath: 3.33-unstable-2024-11-22 -> 3.35-unstable-2024-12-11 (#364381)
[NixPkgs.git] / pkgs / build-support / bintools-wrapper / setup-hook.sh
blobc146cbea80e4fdc83eaf9a094913021fd133dc99
1 # Binutils Wrapper hygiene
3 # See comments in cc-wrapper's setup hook. This works exactly the same way.
5 # Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
6 # native compile.
8 # TODO(@Ericson2314): No native exception
9 [[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0
11 bintoolsWrapper_addLDVars () {
12 # See ../setup-hooks/role.bash
13 local role_post
14 getHostRoleEnvHook
16 if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
17 export NIX_LDFLAGS${role_post}+=" -L$1/lib64"
20 if [[ -d "$1/lib" ]]; then
21 # Don't add the /lib directory if it actually doesn't contain any libraries. For instance,
22 # Python and Haskell packages often only have directories like $out/lib/ghc-8.4.3/ or
23 # $out/lib/python3.6/, so having them in LDFLAGS just makes the linker search unnecessary
24 # directories and bloats the size of the environment variable space.
25 local -a glob=( $1/lib/lib* )
26 if [ "${#glob[*]}" -gt 0 ]; then
27 export NIX_LDFLAGS${role_post}+=" -L$1/lib"
32 # See ../setup-hooks/role.bash
33 getTargetRole
34 getTargetRoleWrapper
36 addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars
38 # shellcheck disable=SC2157
39 if [ -n "@bintools_bin@" ]; then
40 addToSearchPath _PATH @bintools_bin@/bin
43 # shellcheck disable=SC2157
44 if [ -n "@libc_bin@" ]; then
45 addToSearchPath _PATH @libc_bin@/bin
48 # shellcheck disable=SC2157
49 if [ -n "@coreutils_bin@" ]; then
50 addToSearchPath _PATH @coreutils_bin@/bin
53 # Export tool environment variables so various build systems use the right ones.
55 export NIX_BINTOOLS${role_post}=@out@
57 for cmd in \
58 ar as ld nm objcopy objdump readelf ranlib strip strings size windres
61 PATH=$_PATH type -p "@targetPrefix@${cmd}" > /dev/null
62 then
63 export "${cmd^^}${role_post}=@targetPrefix@${cmd}";
65 done
67 # If unset, assume the default hardening flags.
68 : ${NIX_HARDENING_ENABLE="@default_hardening_flags_str@"}
69 export NIX_HARDENING_ENABLE
71 # No local scope in sourced file
72 unset -v role_post cmd upper_case