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