1# N.B. It may be a surprise that the derivation-specific variables are exported,
2# since this is just sourced by the wrapped binaries---the end consumers. This
3# is because one wrapper binary may invoke another (e.g. cc invoking ld). In
4# that case, it is cheaper/better to not repeat this step and let the forked
5# wrapped binary just inherit the work of the forker's wrapper script.
6
7var_templates_list=(
8 NIX_CFLAGS_COMPILE
9 NIX_CFLAGS_COMPILE_BEFORE
10 NIX_CFLAGS_LINK
11 NIX_CXXSTDLIB_COMPILE
12 NIX_CXXSTDLIB_LINK
13 NIX_GNATFLAGS_COMPILE
14)
15var_templates_bool=(
16 NIX_ENFORCE_NO_NATIVE
17)
18
19accumulateRoles
20
21# We need to mangle names for hygiene, but also take parameters/overrides
22# from the environment.
23for var in "${var_templates_list[@]}"; do
24 mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
25done
26for var in "${var_templates_bool[@]}"; do
27 mangleVarBool "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
28done
29
30# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
31NIX_CFLAGS_COMPILE_@suffixSalt@="-B@out@/bin/ $NIX_CFLAGS_COMPILE_@suffixSalt@"
32
33# Export and assign separately in order that a failing $(..) will fail
34# the script.
35
36# Currently bootstrap-tools does not split glibc, and gcc files into
37# separate directories. As a workaround we want resulting cflags to be
38# ordered as: crt1-cflags libc-cflags cc-cflags. Otherwise we mix crt/libc.so
39# from different libc as seen in
40# https://github.com/NixOS/nixpkgs/issues/158042
41#
42# Note that below has reverse ordering as we prepend flags one-by-one.
43# Once bootstrap-tools is split into different directories we can stop
44# relying on flag ordering below.
45
46if [ -e @out@/nix-support/cc-cflags ]; then
47 NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
48fi
49
50if [[ "$cInclude" = 1 ]] && [ -e @out@/nix-support/libc-cflags ]; then
51 NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
52fi
53
54if [ -e @out@/nix-support/libc-crt1-cflags ]; then
55 NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/libc-crt1-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
56fi
57
58if [ -e @out@/nix-support/libcxx-cxxflags ]; then
59 NIX_CXXSTDLIB_COMPILE_@suffixSalt@+=" $(< @out@/nix-support/libcxx-cxxflags)"
60fi
61
62if [ -e @out@/nix-support/libcxx-ldflags ]; then
63 NIX_CXXSTDLIB_LINK_@suffixSalt@+=" $(< @out@/nix-support/libcxx-ldflags)"
64fi
65
66if [ -e @out@/nix-support/gnat-cflags ]; then
67 NIX_GNATFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE_@suffixSalt@"
68fi
69
70if [ -e @out@/nix-support/cc-ldflags ]; then
71 NIX_LDFLAGS_@suffixSalt@+=" $(< @out@/nix-support/cc-ldflags)"
72fi
73
74if [ -e @out@/nix-support/cc-cflags-before ]; then
75 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="$(< @out@/nix-support/cc-cflags-before) $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
76fi
77
78# Only add darwin min version flag if a default darwin min version is set,
79# which is a signal that we're targetting darwin.
80if [ "@darwinMinVersion@" ]; then
81 mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
82
83 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@} $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
84fi
85
86# That way forked processes will not extend these environment variables again.
87export NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@=1