]>
Commit | Line | Data |
---|---|---|
ad3c9f2a A |
1 | #!/usr/bin/perl |
2 | ||
ad3c9f2a A |
3 | # Generates the libc-features.h files used to control #ifdef behaviour in Libc |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | use File::Path qw(mkpath); | |
7 | ||
8 | #printf Dumper(\%ENV); | |
9 | ||
10 | my $unifdef = 0; | |
11 | my %unifdefs = (); | |
12 | my $bash = 0; | |
13 | if (scalar(@ARGV) > 0) { | |
14 | $unifdef = 1 if $ARGV[0] =~ /--unifdef/; | |
15 | $bash = 1 if $ARGV[0] =~ /--bash/; | |
16 | } | |
17 | ||
18 | for my $arch (split(/ /, $ENV{"ARCHS"})) | |
19 | { | |
20 | # set ENV{"CURRENT_ARCH"} so we can predicate on it | |
21 | $ENV{"CURRENT_ARCH"} = $arch; | |
974e3884 | 22 | |
70ad1dc8 | 23 | my $platformName = $ENV{"VARIANT_PLATFORM_NAME"}; |
23e20b00 | 24 | $platformName =~ s/simulator/os/; |
ad3c9f2a | 25 | |
a9aaacca A |
26 | # Try to find a platform+arch config file. If not found, try just |
27 | # a platform config file. | |
28 | my $platformArchPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile." . $arch . ".inc"; | |
ad3c9f2a | 29 | my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc"; |
a9aaacca | 30 | |
ad3c9f2a A |
31 | my $featuresHeaderDir = $ENV{"DERIVED_FILES_DIR"}."/".$arch; |
32 | my $featuresHeader = $featuresHeaderDir."/libc-features.h"; | |
33 | ||
a9aaacca | 34 | open FEATURESFILE, "<$platformArchPath" or open FEATURESFILE, "<$platformPath" or die "Unable to open: $platformArchPath nor $platformPath"; |
ad3c9f2a A |
35 | |
36 | my %features = (); | |
37 | my $skip = 0; | |
38 | my $nested = 0; | |
39 | ||
40 | while (<FEATURESFILE>) { | |
41 | next if $_ =~ /\s*#/; | |
42 | ||
43 | if ($_ =~ /^.endif/) { | |
44 | $skip-- if $skip > 0; | |
45 | $nested--; | |
46 | } | |
47 | ||
48 | elsif ($_ =~ /^\.if\s+(\S+)\s+(\S+)/) { | |
49 | # an if statement, very rudimentary regex against envvar | |
50 | my $envvar = $1; | |
51 | my $regex = $2; | |
52 | ||
53 | $nested++; | |
6465356a | 54 | if (!defined($ENV{$envvar}) || ($ENV{$envvar} !~ /$regex/)) { |
ad3c9f2a A |
55 | $skip += 1; |
56 | } | |
57 | } | |
58 | ||
59 | elsif ($_ =~ /^\s*([^= ]+)\s*=\s*(\d)/) { | |
60 | if ($skip == 0) { | |
61 | if ($2 == 1) { | |
62 | $features{$1} = $2; | |
63 | } elsif (defined($features{$1})) { | |
64 | delete $features{$1}; | |
65 | } | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | close FEATURESFILE; | |
71 | ||
72 | if ($bash == 1) { | |
73 | for my $f (keys %features) { | |
74 | print "$f=$features{$f} "; | |
75 | } | |
76 | printf "\n"; | |
77 | exit 0; | |
78 | } | |
79 | ||
80 | elsif ($unifdef == 1) { | |
81 | # assume FEATURE_BLOCKS was on by default | |
82 | $unifdefs{"UNIFDEF_BLOCKS"} = 1; | |
507116e3 | 83 | $unifdefs{"UNIFDEF_DRIVERKIT"} = defined($ENV{"DRIVERKITSDK"}); |
ad3c9f2a A |
84 | $unifdefs{"UNIFDEF_LEGACY_64_APIS"} = defined($features{"FEATURE_LEGACY_64_APIS"}); |
85 | $unifdefs{"UNIFDEF_LEGACY_RUNE_APIS"} = defined($features{"FEATURE_LEGACY_RUNE_APIS"}); | |
86 | $unifdefs{"UNIFDEF_LEGACY_UTMP_APIS"} = defined($features{"FEATURE_LEGACY_UTMP_APIS"}); | |
507116e3 | 87 | $unifdefs{"UNIFDEF_POSIX_ILP32_ALLOW"} = defined($features{"FEATURE_POSIX_ILP32_ALLOW"}); |
ad3c9f2a A |
88 | |
89 | my $output = ""; | |
90 | for my $d (keys %unifdefs) { | |
91 | $output .= " " . ($unifdefs{$d} == 1 ? "-D" : "-U") . $d; | |
92 | } | |
93 | ||
94 | chomp $output; | |
95 | print "$output\n"; | |
96 | exit 0; | |
97 | } | |
98 | ||
99 | elsif ($unifdef == 0) { | |
100 | # If we touch this file on every build, then every other iterative build in Xcode will rebuild *everything* | |
a9aaacca A |
101 | my $platform_mtime = (stat($platformArchPath))[9]; |
102 | if (!defined($platform_mtime)) { | |
103 | # try the other one | |
104 | $platform_mtime = (stat($platformPath))[9]; | |
105 | } | |
ad3c9f2a A |
106 | my $header_mtime = (stat($featuresHeader))[9]; |
107 | ||
6465356a | 108 | if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) { |
ad3c9f2a A |
109 | exit 0; |
110 | } | |
111 | ||
112 | printf $arch." features:\n"; | |
113 | printf Dumper(\%features); | |
114 | ||
115 | if ($nested != 0) { | |
116 | die "Unbalanced .if/.endif directive"; | |
117 | } | |
118 | ||
119 | # And the meat, new header options should go under here | |
120 | if (! -d $featuresHeaderDir) { | |
121 | mkpath $featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir"; | |
122 | } | |
123 | open HEADER, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader"; | |
124 | ||
125 | printf HEADER "#ifndef _LIBC_FEATURES_H_\n"; | |
126 | printf HEADER "#define _LIBC_FEATURES_H_\n\n"; | |
127 | ||
128 | my $shortarch = $arch; | |
129 | $shortarch =~ s/armv\d+[a-z]?/arm/g; | |
b061a43b A |
130 | |
131 | # map all arm64 subtypes to arm64 | |
70ad1dc8 | 132 | $shortarch =~ s/arm64[_a-z0-9]*/arm64/g; |
ad3c9f2a A |
133 | |
134 | printf HEADER "#if !defined(__".$shortarch."__)\n"; | |
135 | printf HEADER "#error Mismatched libc-features.h architecture\n"; | |
136 | printf HEADER "#endif\n\n"; | |
137 | ||
138 | if (defined($features{"FEATURE_LEGACY_RUNE_APIS"})) { | |
139 | printf HEADER "#define UNIFDEF_LEGACY_RUNE_APIS 1\n"; | |
140 | } else { | |
141 | printf HEADER "/* #undef UNIFDEF_LEGACY_RUNE_APIS */\n"; | |
142 | } | |
143 | ||
144 | if (defined($features{"FEATURE_LEGACY_CRT1_ENVIRON"})) { | |
145 | printf HEADER "#define LEGACY_CRT1_ENVIRON 1\n"; | |
146 | } else { | |
147 | printf HEADER "/* #undef LEGACY_CRT1_ENVIRON */\n"; | |
148 | } | |
149 | ||
150 | if (defined($features{"FEATURE_LEGACY_UTMP_APIS"})) { | |
151 | printf HEADER "#define UNIFDEF_LEGACY_UTMP_APIS 1\n"; | |
152 | } else { | |
153 | printf HEADER "/* #undef UNIFDEF_LEGACY_UTMP_APIS */\n"; | |
154 | } | |
155 | ||
ad3c9f2a A |
156 | if (defined($features{"FEATURE_ONLY_1050_VARIANTS"})) { |
157 | printf HEADER "#if !__DARWIN_ONLY_VERS_1050\n"; | |
158 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0\n"; | |
159 | printf HEADER "#endif /* !__DARWIN_ONLY_VERS_1050 */\n"; | |
160 | } else { | |
161 | printf HEADER "#if __DARWIN_ONLY_VERS_1050\n"; | |
162 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1\n"; | |
163 | printf HEADER "#endif /* __DARWIN_ONLY_VERS_1050 */\n"; | |
164 | } | |
165 | ||
166 | if (defined($features{"FEATURE_ONLY_UNIX_CONFORMANCE"})) { | |
167 | printf HEADER "#if !__DARWIN_ONLY_UNIX_CONFORMANCE\n"; | |
168 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0\n"; | |
169 | printf HEADER "#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */\n"; | |
170 | } else { | |
171 | printf HEADER "#if __DARWIN_ONLY_UNIX_CONFORMANCE\n"; | |
172 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1\n"; | |
173 | printf HEADER "#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */\n"; | |
174 | } | |
175 | ||
176 | if (defined($features{"FEATURE_ONLY_64_BIT_INO_T"})) { | |
177 | printf HEADER "#if !__DARWIN_ONLY_64_BIT_INO_T\n"; | |
178 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0\n"; | |
179 | printf HEADER "#endif /* !__DARWIN_ONLY_64_BIT_INO_T */\n"; | |
180 | } else { | |
181 | printf HEADER "#if __DARWIN_ONLY_64_BIT_INO_T\n"; | |
182 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1\n"; | |
183 | printf HEADER "#endif /* __DARWIN_ONLY_64_BIT_INO_T */\n"; | |
184 | } | |
185 | ||
186 | if (defined($features{"FEATURE_PATCH_3417676"})) { | |
187 | printf HEADER "#define __APPLE_PR3417676_HACK__ 1\n"; | |
188 | } else { | |
189 | printf HEADER "/* #undef __APPLE_PR3417676_HACK__ */\n"; | |
190 | } | |
191 | ||
ad3c9f2a A |
192 | if (defined($features{"FEATURE_PLOCKSTAT"})) { |
193 | printf HEADER "#define PLOCKSTAT 1\n"; | |
194 | } else { | |
195 | printf HEADER "/* #undef PLOCKSTAT */\n"; | |
196 | } | |
197 | ||
198 | if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) { | |
199 | printf HEADER "#define NOTIFY_TZ 1\n"; | |
200 | } else { | |
201 | printf HEADER "/* #undef NOTIFY_TZ */\n"; | |
202 | } | |
203 | ||
6465356a A |
204 | if (defined($features{"FEATURE_SMALL_STDIOBUF"})) { |
205 | printf HEADER "#define FEATURE_SMALL_STDIOBUF 1\n"; | |
206 | } else { | |
207 | printf HEADER "/* #undef FEATURE_SMALL_STDIOBUF */\n"; | |
208 | } | |
209 | ||
210 | if (defined($features{"FEATURE_XPRINTF_PERF"})) { | |
211 | printf HEADER "#define XPRINTF_PERF 1\n"; | |
ad3c9f2a | 212 | } else { |
6465356a | 213 | printf HEADER "/* #undef XPRINTF_PERF */\n"; |
ad3c9f2a A |
214 | } |
215 | ||
5f125488 A |
216 | if (defined($features{"FEATURE_SIGNAL_RESTRICTION"})) { |
217 | printf HEADER "#define FEATURE_SIGNAL_RESTRICTION 1\n"; | |
218 | } else { | |
219 | printf HEADER "/* #undef FEATURE_SIGNAL_RESTRICTION */\n"; | |
220 | } | |
221 | ||
ad3c9f2a A |
222 | printf HEADER "#endif // _LIBC_FEATURES_H_\n"; |
223 | close HEADER; | |
224 | } | |
225 | } | |
226 | ||
227 | exit 0; |