summary refs log tree commit diff
path: root/pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh
blob: 75d9484846a8cb544de5dccb6e248f5877f57972 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Unconditionally adding in platform version flags will result in warnings that
# will be treated as errors by some packages. Add any missing flags here.

# There are two things to be configured: the "platform version" (oldest
# supported version of macos, ios, etc), and the "sdk version".
#
# The modern way of configuring these is to use:
#    -platform_version $platform $platform_version $sdk_version"
#
# The old way is still supported, and uses flags like:
#    -${platform}_version_min $platform_version
#    -sdk_version $sdk_version
#
# If both styles are specified ld will combine them. If multiple versions are
# specified for the same platform, ld will emit an error.
#
# The following adds flags for whichever properties have not already been
# provided.

havePlatformVersionFlag=
haveDarwinSDKVersion=
haveDarwinPlatformVersion=

# Roles will set by add-flags.sh, but add-flags.sh can be skipped when the
# cc-wrapper has added the linker flags. Both the cc-wrapper and the binutils
# wrapper mangle the same variable (MACOSX_DEPLOYMENT_TARGET), so if roles are
# empty due to being run through the cc-wrapper then the mangle here is a no-op
# and we still do the right thing.
#
# To be robust, make sure we always have the correct set of roles.
accumulateRoles

mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}

n=0
nParams=${#params[@]}
while (( n < nParams )); do
    p=${params[n]}
    case "$p" in
        # the current platform
        -@darwinPlatform@_version_min)
            haveDarwinPlatformVersion=1
            ;;

        # legacy aliases
        -macosx_version_min|-iphoneos_version_min|-iosmac_version_min|-uikitformac_version_min)
            haveDarwinPlatformVersion=1
            ;;

        -sdk_version)
            haveDarwinSDKVersion=1
            ;;

        -platform_version)
            havePlatformVersionFlag=1

            # If clang can't determine the sdk version it will pass 0.0.0. This
            # has runtime effects so we override this to use the known sdk
            # version.
            if [ "${params[n+3]-}" = 0.0.0 ]; then
                params[n+3]=@darwinSdkVersion@
            fi
            ;;
    esac
    n=$((n + 1))
done

# If the caller has set -platform_version, trust they're doing the right thing.
# This will be the typical case for clang in nixpkgs.
if [ ! "$havePlatformVersionFlag" ]; then
    if [ ! "$haveDarwinSDKVersion" ] && [ ! "$haveDarwinPlatformVersion" ]; then
        # Nothing provided. Use the modern "-platform_version" to set both.
        extraBefore+=(-platform_version @darwinPlatform@ "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}" @darwinSdkVersion@)
    elif [ ! "$haveDarwinSDKVersion" ]; then
        # Add missing sdk version
        extraBefore+=(-sdk_version @darwinSdkVersion@)
    elif [ ! "$haveDarwinPlatformVersion" ]; then
        # Add missing platform version
        extraBefore+=(-@darwinPlatform@_version_min "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}")
    fi
fi