Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1# Unconditionally adding in platform version flags will result in warnings that
2# will be treated as errors by some packages. Add any missing flags here.
3
4# There are two things to be configured: the "platform version" (oldest
5# supported version of macos, ios, etc), and the "sdk version".
6#
7# The modern way of configuring these is to use:
8# -platform_version $platform $platform_version $sdk_version"
9#
10# The old way is still supported, and uses flags like:
11# -${platform}_version_min $platform_version
12# -sdk_version $sdk_version
13#
14# If both styles are specified ld will combine them. If multiple versions are
15# specified for the same platform, ld will emit an error.
16#
17# The following adds flags for whichever properties have not already been
18# provided.
19
20havePlatformVersionFlag=
21haveDarwinSDKVersion=
22haveDarwinPlatformVersion=
23
24# Roles will set by add-flags.sh, but add-flags.sh can be skipped when the
25# cc-wrapper has added the linker flags. Both the cc-wrapper and the binutils
26# wrapper mangle the same variable (MACOSX_DEPLOYMENT_TARGET), so if roles are
27# empty due to being run through the cc-wrapper then the mangle here is a no-op
28# and we still do the right thing.
29#
30# To be robust, make sure we always have the correct set of roles.
31accumulateRoles
32
33mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
34
35n=0
36nParams=${#params[@]}
37while (( n < nParams )); do
38 p=${params[n]}
39 case "$p" in
40 # the current platform
41 -@darwinPlatform@_version_min)
42 haveDarwinPlatformVersion=1
43 ;;
44
45 # legacy aliases
46 -macosx_version_min|-iphoneos_version_min|-iosmac_version_min|-uikitformac_version_min)
47 haveDarwinPlatformVersion=1
48 ;;
49
50 -sdk_version)
51 haveDarwinSDKVersion=1
52 ;;
53
54 -platform_version)
55 havePlatformVersionFlag=1
56
57 # If clang can't determine the sdk version it will pass 0.0.0. This
58 # has runtime effects so we override this to use the known sdk
59 # version.
60 if [ "${params[n+3]-}" = 0.0.0 ]; then
61 params[n+3]=@darwinSdkVersion@
62 fi
63 ;;
64 esac
65 n=$((n + 1))
66done
67
68# If the caller has set -platform_version, trust they're doing the right thing.
69# This will be the typical case for clang in nixpkgs.
70if [ ! "$havePlatformVersionFlag" ]; then
71 if [ ! "$haveDarwinSDKVersion" ] && [ ! "$haveDarwinPlatformVersion" ]; then
72 # Nothing provided. Use the modern "-platform_version" to set both.
73 extraBefore+=(-platform_version @darwinPlatform@ "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}" @darwinSdkVersion@)
74 elif [ ! "$haveDarwinSDKVersion" ]; then
75 # Add missing sdk version
76 extraBefore+=(-sdk_version @darwinSdkVersion@)
77 elif [ ! "$haveDarwinPlatformVersion" ]; then
78 # Add missing platform version
79 extraBefore+=(-@darwinPlatform@_version_min "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}")
80 fi
81fi