]>
git.saurik.com Git - apple/libc.git/blob - xcodescripts/generate_features.pl
3 # Generates the libc-features.h files used to control #ifdef behaviour in Libc
6 use File
::Path
qw(mkpath);
13 if (scalar(@ARGV) > 0) {
14 $unifdef = 1 if $ARGV[0] =~ /--unifdef/;
15 $bash = 1 if $ARGV[0] =~ /--bash/;
18 for my $arch (split(/ /, $ENV{"ARCHS"}))
20 # set ENV{"CURRENT_ARCH"} so we can predicate on it
21 $ENV{"CURRENT_ARCH"} = $arch;
23 my $platformName = $ENV{"VARIANT_PLATFORM_NAME"};
24 $platformName =~ s/simulator/os/;
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";
29 my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc";
31 my $featuresHeaderDir = $ENV{"DERIVED_FILES_DIR"}."/".$arch;
32 my $featuresHeader = $featuresHeaderDir."/libc-features.h";
34 open FEATURESFILE
, "<$platformArchPath" or open FEATURESFILE
, "<$platformPath" or die "Unable to open: $platformArchPath nor $platformPath";
40 while (<FEATURESFILE
>) {
43 if ($_ =~ /^.endif/) {
48 elsif ($_ =~ /^\.if\s+(\S+)\s+(\S+)/) {
49 # an if statement, very rudimentary regex against envvar
54 if (!defined($ENV{$envvar}) || ($ENV{$envvar} !~ /$regex/)) {
59 elsif ($_ =~ /^\s*([^= ]+)\s*=\s*(\d)/) {
63 } elsif (defined($features{$1})) {
73 for my $f (keys %features) {
74 print "$f=$features{$f} ";
80 elsif ($unifdef == 1) {
81 # assume FEATURE_BLOCKS was on by default
82 $unifdefs{"UNIFDEF_BLOCKS"} = 1;
83 $unifdefs{"UNIFDEF_DRIVERKIT"} = defined($ENV{"DRIVERKITSDK"});
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"});
87 $unifdefs{"UNIFDEF_POSIX_ILP32_ALLOW"} = defined($features{"FEATURE_POSIX_ILP32_ALLOW"});
90 for my $d (keys %unifdefs) {
91 $output .= " " . ($unifdefs{$d} == 1 ? "-D" : "-U") . $d;
99 elsif ($unifdef == 0) {
100 # If we touch this file on every build, then every other iterative build in Xcode will rebuild *everything*
101 my $platform_mtime = (stat($platformArchPath))[9];
102 if (!defined($platform_mtime)) {
104 $platform_mtime = (stat($platformPath))[9];
106 my $header_mtime = (stat($featuresHeader))[9];
108 if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) {
112 printf $arch." features:\n";
113 printf Dumper
(\
%features);
116 die "Unbalanced .if/.endif directive";
119 # And the meat, new header options should go under here
120 if (! -d
$featuresHeaderDir) {
121 mkpath
$featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir";
123 open HEADER
, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader";
125 printf HEADER
"#ifndef _LIBC_FEATURES_H_\n";
126 printf HEADER
"#define _LIBC_FEATURES_H_\n\n";
128 my $shortarch = $arch;
129 $shortarch =~ s/armv\d+[a-z]?/arm/g;
131 # map all arm64 subtypes to arm64
132 $shortarch =~ s/arm64[_a-z0-9]*/arm64/g;
134 printf HEADER
"#if !defined(__".$shortarch."__)\n";
135 printf HEADER
"#error Mismatched libc-features.h architecture\n";
136 printf HEADER
"#endif\n\n";
138 if (defined($features{"FEATURE_LEGACY_RUNE_APIS"})) {
139 printf HEADER
"#define UNIFDEF_LEGACY_RUNE_APIS 1\n";
141 printf HEADER
"/* #undef UNIFDEF_LEGACY_RUNE_APIS */\n";
144 if (defined($features{"FEATURE_LEGACY_CRT1_ENVIRON"})) {
145 printf HEADER
"#define LEGACY_CRT1_ENVIRON 1\n";
147 printf HEADER
"/* #undef LEGACY_CRT1_ENVIRON */\n";
150 if (defined($features{"FEATURE_LEGACY_UTMP_APIS"})) {
151 printf HEADER
"#define UNIFDEF_LEGACY_UTMP_APIS 1\n";
153 printf HEADER
"/* #undef UNIFDEF_LEGACY_UTMP_APIS */\n";
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";
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";
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";
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";
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";
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";
186 if (defined($features{"FEATURE_PATCH_3417676"})) {
187 printf HEADER
"#define __APPLE_PR3417676_HACK__ 1\n";
189 printf HEADER
"/* #undef __APPLE_PR3417676_HACK__ */\n";
192 if (defined($features{"FEATURE_PLOCKSTAT"})) {
193 printf HEADER
"#define PLOCKSTAT 1\n";
195 printf HEADER
"/* #undef PLOCKSTAT */\n";
198 if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) {
199 printf HEADER
"#define NOTIFY_TZ 1\n";
201 printf HEADER
"/* #undef NOTIFY_TZ */\n";
204 if (defined($features{"FEATURE_SMALL_STDIOBUF"})) {
205 printf HEADER
"#define FEATURE_SMALL_STDIOBUF 1\n";
207 printf HEADER
"/* #undef FEATURE_SMALL_STDIOBUF */\n";
210 if (defined($features{"FEATURE_XPRINTF_PERF"})) {
211 printf HEADER
"#define XPRINTF_PERF 1\n";
213 printf HEADER
"/* #undef XPRINTF_PERF */\n";
216 if (defined($features{"FEATURE_SIGNAL_RESTRICTION"})) {
217 printf HEADER
"#define FEATURE_SIGNAL_RESTRICTION 1\n";
219 printf HEADER
"/* #undef FEATURE_SIGNAL_RESTRICTION */\n";
222 printf HEADER
"#endif // _LIBC_FEATURES_H_\n";