]>
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 A |
22 | |
23 | # BridgeOS shares the same platform name than the watch so | |
24 | # we need to fix it and pick the right configuration. | |
ad3c9f2a | 25 | my $platformName = $ENV{"PLATFORM_NAME"}; |
974e3884 A |
26 | if ($ENV{"RC_BRIDGE"} eq "YES") { |
27 | $platformName = "bridgeos"; | |
28 | } | |
29 | ||
23e20b00 | 30 | $platformName =~ s/simulator/os/; |
ad3c9f2a A |
31 | |
32 | my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc"; | |
33 | my $featuresHeaderDir = $ENV{"DERIVED_FILES_DIR"}."/".$arch; | |
34 | my $featuresHeader = $featuresHeaderDir."/libc-features.h"; | |
35 | ||
36 | open FEATURESFILE, "<$platformPath" or die "Unable to open: $platformPath"; | |
37 | ||
38 | my %features = (); | |
39 | my $skip = 0; | |
40 | my $nested = 0; | |
41 | ||
42 | while (<FEATURESFILE>) { | |
43 | next if $_ =~ /\s*#/; | |
44 | ||
45 | if ($_ =~ /^.endif/) { | |
46 | $skip-- if $skip > 0; | |
47 | $nested--; | |
48 | } | |
49 | ||
50 | elsif ($_ =~ /^\.if\s+(\S+)\s+(\S+)/) { | |
51 | # an if statement, very rudimentary regex against envvar | |
52 | my $envvar = $1; | |
53 | my $regex = $2; | |
54 | ||
55 | $nested++; | |
6465356a | 56 | if (!defined($ENV{$envvar}) || ($ENV{$envvar} !~ /$regex/)) { |
ad3c9f2a A |
57 | $skip += 1; |
58 | } | |
59 | } | |
60 | ||
61 | elsif ($_ =~ /^\s*([^= ]+)\s*=\s*(\d)/) { | |
62 | if ($skip == 0) { | |
63 | if ($2 == 1) { | |
64 | $features{$1} = $2; | |
65 | } elsif (defined($features{$1})) { | |
66 | delete $features{$1}; | |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | close FEATURESFILE; | |
73 | ||
74 | if ($bash == 1) { | |
75 | for my $f (keys %features) { | |
76 | print "$f=$features{$f} "; | |
77 | } | |
78 | printf "\n"; | |
79 | exit 0; | |
80 | } | |
81 | ||
82 | elsif ($unifdef == 1) { | |
6465356a A |
83 | if ($platformName eq "macosx") { |
84 | $unifdefs{"__OSX_OPEN_SOURCE__"} = 1; | |
85 | } | |
ad3c9f2a A |
86 | # assume FEATURE_BLOCKS was on by default |
87 | $unifdefs{"UNIFDEF_BLOCKS"} = 1; | |
88 | $unifdefs{"UNIFDEF_LEGACY_64_APIS"} = defined($features{"FEATURE_LEGACY_64_APIS"}); | |
89 | $unifdefs{"UNIFDEF_LEGACY_RUNE_APIS"} = defined($features{"FEATURE_LEGACY_RUNE_APIS"}); | |
90 | $unifdefs{"UNIFDEF_LEGACY_UTMP_APIS"} = defined($features{"FEATURE_LEGACY_UTMP_APIS"}); | |
91 | $unifdefs{"UNIFDEF_MOVE_LOCALTIME"} = defined($features{"FEATURE_MOVE_LOCALTIME"}); | |
6465356a | 92 | $unifdefs{"UNIFDEF_TZDIR_SYMLINK"} = defined($features{"FEATURE_TZDIR_SYMLINK"}); |
ad3c9f2a A |
93 | |
94 | my $output = ""; | |
95 | for my $d (keys %unifdefs) { | |
96 | $output .= " " . ($unifdefs{$d} == 1 ? "-D" : "-U") . $d; | |
97 | } | |
98 | ||
99 | chomp $output; | |
100 | print "$output\n"; | |
101 | exit 0; | |
102 | } | |
103 | ||
104 | elsif ($unifdef == 0) { | |
105 | # If we touch this file on every build, then every other iterative build in Xcode will rebuild *everything* | |
106 | my $platform_mtime = (stat($platformPath))[9]; | |
107 | my $header_mtime = (stat($featuresHeader))[9]; | |
108 | ||
6465356a | 109 | if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) { |
ad3c9f2a A |
110 | exit 0; |
111 | } | |
112 | ||
113 | printf $arch." features:\n"; | |
114 | printf Dumper(\%features); | |
115 | ||
116 | if ($nested != 0) { | |
117 | die "Unbalanced .if/.endif directive"; | |
118 | } | |
119 | ||
120 | # And the meat, new header options should go under here | |
121 | if (! -d $featuresHeaderDir) { | |
122 | mkpath $featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir"; | |
123 | } | |
124 | open HEADER, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader"; | |
125 | ||
126 | printf HEADER "#ifndef _LIBC_FEATURES_H_\n"; | |
127 | printf HEADER "#define _LIBC_FEATURES_H_\n\n"; | |
128 | ||
129 | my $shortarch = $arch; | |
130 | $shortarch =~ s/armv\d+[a-z]?/arm/g; | |
974e3884 | 131 | $shortarch =~ s/arm64_32/arm64/g; |
ad3c9f2a A |
132 | |
133 | printf HEADER "#if !defined(__".$shortarch."__)\n"; | |
134 | printf HEADER "#error Mismatched libc-features.h architecture\n"; | |
135 | printf HEADER "#endif\n\n"; | |
136 | ||
137 | if (defined($features{"FEATURE_LEGACY_RUNE_APIS"})) { | |
138 | printf HEADER "#define UNIFDEF_LEGACY_RUNE_APIS 1\n"; | |
139 | } else { | |
140 | printf HEADER "/* #undef UNIFDEF_LEGACY_RUNE_APIS */\n"; | |
141 | } | |
142 | ||
143 | if (defined($features{"FEATURE_LEGACY_CRT1_ENVIRON"})) { | |
144 | printf HEADER "#define LEGACY_CRT1_ENVIRON 1\n"; | |
145 | } else { | |
146 | printf HEADER "/* #undef LEGACY_CRT1_ENVIRON */\n"; | |
147 | } | |
148 | ||
149 | if (defined($features{"FEATURE_LEGACY_UTMP_APIS"})) { | |
150 | printf HEADER "#define UNIFDEF_LEGACY_UTMP_APIS 1\n"; | |
151 | } else { | |
152 | printf HEADER "/* #undef UNIFDEF_LEGACY_UTMP_APIS */\n"; | |
153 | } | |
154 | ||
155 | if (defined($features{"FEATURE_MOVE_LOCALTIME"})) { | |
156 | printf HEADER "#define UNIFDEF_MOVE_LOCALTIME 1\n"; | |
157 | } else { | |
158 | printf HEADER "/* #undef UNIFDEF_MOVE_LOCALTIME */\n"; | |
159 | } | |
160 | ||
6465356a A |
161 | if (defined($features{"FEATURE_TZDIR_SYMLINK"})) { |
162 | printf HEADER "#define UNIFDEF_TZDIR_SYMLINK 1\n"; | |
163 | } else { | |
164 | printf HEADER "/* #undef UNIFDEF_TZDIR_SYMLINK */\n"; | |
165 | } | |
166 | ||
ad3c9f2a A |
167 | if (defined($features{"FEATURE_ONLY_1050_VARIANTS"})) { |
168 | printf HEADER "#if !__DARWIN_ONLY_VERS_1050\n"; | |
169 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0\n"; | |
170 | printf HEADER "#endif /* !__DARWIN_ONLY_VERS_1050 */\n"; | |
171 | } else { | |
172 | printf HEADER "#if __DARWIN_ONLY_VERS_1050\n"; | |
173 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1\n"; | |
174 | printf HEADER "#endif /* __DARWIN_ONLY_VERS_1050 */\n"; | |
175 | } | |
176 | ||
177 | if (defined($features{"FEATURE_ONLY_UNIX_CONFORMANCE"})) { | |
178 | printf HEADER "#if !__DARWIN_ONLY_UNIX_CONFORMANCE\n"; | |
179 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0\n"; | |
180 | printf HEADER "#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */\n"; | |
181 | } else { | |
182 | printf HEADER "#if __DARWIN_ONLY_UNIX_CONFORMANCE\n"; | |
183 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1\n"; | |
184 | printf HEADER "#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */\n"; | |
185 | } | |
186 | ||
187 | if (defined($features{"FEATURE_ONLY_64_BIT_INO_T"})) { | |
188 | printf HEADER "#if !__DARWIN_ONLY_64_BIT_INO_T\n"; | |
189 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0\n"; | |
190 | printf HEADER "#endif /* !__DARWIN_ONLY_64_BIT_INO_T */\n"; | |
191 | } else { | |
192 | printf HEADER "#if __DARWIN_ONLY_64_BIT_INO_T\n"; | |
193 | printf HEADER "# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1\n"; | |
194 | printf HEADER "#endif /* __DARWIN_ONLY_64_BIT_INO_T */\n"; | |
195 | } | |
196 | ||
197 | if (defined($features{"FEATURE_PATCH_3417676"})) { | |
198 | printf HEADER "#define __APPLE_PR3417676_HACK__ 1\n"; | |
199 | } else { | |
200 | printf HEADER "/* #undef __APPLE_PR3417676_HACK__ */\n"; | |
201 | } | |
202 | ||
ad3c9f2a A |
203 | if (defined($features{"FEATURE_PLOCKSTAT"})) { |
204 | printf HEADER "#define PLOCKSTAT 1\n"; | |
205 | } else { | |
206 | printf HEADER "/* #undef PLOCKSTAT */\n"; | |
207 | } | |
208 | ||
209 | if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) { | |
210 | printf HEADER "#define NOTIFY_TZ 1\n"; | |
211 | } else { | |
212 | printf HEADER "/* #undef NOTIFY_TZ */\n"; | |
213 | } | |
214 | ||
215 | if (defined($features{"FEATURE_NO_LIBCRASHREPORTERCLIENT"})) { | |
216 | printf HEADER "#define LIBC_NO_LIBCRASHREPORTERCLIENT 1\n"; | |
217 | } else { | |
218 | printf HEADER "/* #undef LIBC_NO_LIBCRASHREPORTERCLIENT */\n"; | |
219 | } | |
220 | ||
6465356a A |
221 | if (defined($features{"FEATURE_SMALL_STDIOBUF"})) { |
222 | printf HEADER "#define FEATURE_SMALL_STDIOBUF 1\n"; | |
223 | } else { | |
224 | printf HEADER "/* #undef FEATURE_SMALL_STDIOBUF */\n"; | |
225 | } | |
226 | ||
227 | if (defined($features{"FEATURE_XPRINTF_PERF"})) { | |
228 | printf HEADER "#define XPRINTF_PERF 1\n"; | |
ad3c9f2a | 229 | } else { |
6465356a | 230 | printf HEADER "/* #undef XPRINTF_PERF */\n"; |
ad3c9f2a A |
231 | } |
232 | ||
5f125488 A |
233 | if (defined($features{"FEATURE_SIGNAL_RESTRICTION"})) { |
234 | printf HEADER "#define FEATURE_SIGNAL_RESTRICTION 1\n"; | |
235 | } else { | |
236 | printf HEADER "/* #undef FEATURE_SIGNAL_RESTRICTION */\n"; | |
237 | } | |
238 | ||
ad3c9f2a A |
239 | printf HEADER "#endif // _LIBC_FEATURES_H_\n"; |
240 | close HEADER; | |
241 | } | |
242 | } | |
243 | ||
244 | exit 0; |