]> git.saurik.com Git - apple/dyld.git/blob - bin/expand.rb
dyld-732.8.tar.gz
[apple/dyld.git] / bin / expand.rb
1 #!/usr/bin/env ruby
2
3 require 'yaml'
4
5 if ENV["DRIVERKITROOT"]
6 $availCmd = ENV["SDKROOT"] + ENV["DRIVERKITROOT"] + "/usr/local/libexec/availability.pl";
7 else
8 $availCmd = ENV["SDKROOT"] + "/usr/local/libexec/availability.pl";
9 end
10
11 def versionString(vers)
12 uvers = ""
13 if vers =~ /^(\d+)$/
14 uvers = "#{$1}_0"
15 elsif vers =~ /^(\d+).(\d+)$/
16 uvers = "#{$1}_#{$2}"
17 elsif vers =~ /^(\d+).(\d+).(\d+)$/
18 if $3 == 0
19 uvers = "#{$1}_#{$2}"
20 else
21 uvers = "#{$1}_#{$2}_#{$3}"
22 end
23 end
24 uvers
25 end
26
27 def versionHex(vers)
28 major = 0;
29 minor = 0;
30 revision = 0;
31
32 if vers =~ /^(\d+)$/
33 major = $1.to_i;
34 elsif vers =~ /^(\d+).(\d+)$/
35 major = $1.to_i;
36 minor = $2.to_i;
37 elsif vers =~ /^(\d+).(\d+).(\d+)$/
38 major = $1.to_i;
39 minor = $2.to_i;
40 revision = $3.to_i;
41 end
42 "0x00#{major.to_s(16).rjust(2, '0')}#{minor.to_s(16).rjust(2, '0')}#{revision.to_s(16).rjust(2, '0')}"
43 end
44
45 def expandVersions(prefix, arg)
46 versionList = `#{$availCmd} #{arg}`.gsub(/\s+/m, ' ').strip.split(" ")
47 versionList.each { |version|
48 puts "#define #{prefix}#{versionString(version)}".ljust(48, ' ') + versionHex(version)
49 }
50 end
51
52 def expandPlatformVersions(prefix, platform, arg)
53 versionList = `#{$availCmd} #{arg}`.gsub(/\s+/m, ' ').strip.split(" ")
54 versionList.each { |version|
55 puts "static dyld_build_version_t dyld_platform_version_#{prefix}_#{versionString(version)}".ljust(72, ' ') + "= { .platform = #{platform}, .version = #{versionHex(version)} };"
56 }
57 end
58
59 def versionSetsForOSes(versionSets, key, platform, target)
60 puts "#if #{target}"
61 versionSets.each { |k,v|
62 puts "#define dyld_#{k}_os_versions dyld_platform_version_#{platform}_#{versionString(v[key].to_s)}"
63 }
64 puts "#endif /* #{target} */"
65 end
66
67 def expandVersionSets()
68 versionSets = YAML.load(`#{$availCmd} --sets`)
69 versionSetsForOSes(versionSets, "macos", "macOS", "TARGET_OS_OSX")
70 versionSetsForOSes(versionSets, "ios", "iOS", "TARGET_OS_IOS")
71 versionSetsForOSes(versionSets, "tvos", "tvOS", "TARGET_OS_TV")
72 versionSetsForOSes(versionSets, "watchos", "watchOS", "TARGET_OS_WATCH")
73 versionSetsForOSes(versionSets, "bridgeos", "bridgeOS", "TARGET_OS_BRIDGE")
74 end
75
76 ARGF.each do |line|
77 if line =~ /^\/\/\@MAC_VERSION_DEFS\@$/
78 expandVersions("DYLD_MACOSX_VERSION_", "--macosx")
79 elsif line =~ /^\/\/\@IOS_VERSION_DEFS\@$/
80 expandVersions("DYLD_IOS_VERSION_", "--ios")
81 elsif line =~ /^\/\/\@WATCHOS_VERSION_DEFS\@$/
82 expandVersions("DYLD_WATCHOS_VERSION_", "--watchos")
83 elsif line =~ /^\/\/\@TVOS_VERSION_DEFS\@$/
84 expandVersions("DYLD_TVOS_VERSION_", "--appletvos")
85 elsif line =~ /^\/\/\@BRIDGEOS_VERSION_DEFS\@$/
86 expandVersions("DYLD_BRIDGEOS_VERSION_", "--bridgeos")
87 elsif line =~ /^\/\/\@MACOS_PLATFORM_VERSION_DEFS\@$/
88 expandPlatformVersions("macOS", "PLATFORM_MACOS", "--macosx")
89 elsif line =~ /^\/\/\@IOS_PLATFORM_VERSION_DEFS\@$/
90 expandPlatformVersions("iOS", "PLATFORM_IOS", "--ios")
91 elsif line =~ /^\/\/\@WATCHOS_PLATFORM_VERSION_DEFS\@$/
92 expandPlatformVersions("watchOS", "PLATFORM_WATCHOS", "--watchos")
93 elsif line =~ /^\/\/\@TVOS_PLATFORM_VERSION_DEFS\@$/
94 expandPlatformVersions("tvOS", "PLATFORM_TVOS", "--appletvos")
95 elsif line =~ /^\/\/\@BRIDGEOS_PLATFORM_VERSION_DEFS\@$/
96 expandPlatformVersions("bridgeOS", "PLATFORM_BRIDGEOS", "--bridgeos")
97 elsif line =~ /^\/\/\@VERSION_SET_DEFS\@$/
98 expandVersionSets()
99 else
100 puts line
101 end
102 end