]>
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 # BridgeOS shares the same platform name than the watch so
24 # we need to fix it and pick the right configuration.
25 my $platformName = $ENV{"PLATFORM_NAME"};
26 if ($ENV{"RC_BRIDGE"} eq "YES") {
27 $platformName = "bridgeos";
30 $platformName =~ s/simulator/os/;
32 my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc";
33 my $featuresHeaderDir = $ENV{"DERIVED_FILES_DIR"}."/".$arch;
34 my $featuresHeader = $featuresHeaderDir."/libc-features.h";
36 open FEATURESFILE
, "<$platformPath" or die "Unable to open: $platformPath";
42 while (<FEATURESFILE
>) {
45 if ($_ =~ /^.endif/) {
50 elsif ($_ =~ /^\.if\s+(\S+)\s+(\S+)/) {
51 # an if statement, very rudimentary regex against envvar
56 if (!defined($ENV{$envvar}) || ($ENV{$envvar} !~ /$regex/)) {
61 elsif ($_ =~ /^\s*([^= ]+)\s*=\s*(\d)/) {
65 } elsif (defined($features{$1})) {
75 for my $f (keys %features) {
76 print "$f=$features{$f} ";
82 elsif ($unifdef == 1) {
83 # assume FEATURE_BLOCKS was on by default
84 $unifdefs{"UNIFDEF_BLOCKS"} = 1;
85 $unifdefs{"UNIFDEF_LEGACY_64_APIS"} = defined($features{"FEATURE_LEGACY_64_APIS"});
86 $unifdefs{"UNIFDEF_LEGACY_RUNE_APIS"} = defined($features{"FEATURE_LEGACY_RUNE_APIS"});
87 $unifdefs{"UNIFDEF_LEGACY_UTMP_APIS"} = defined($features{"FEATURE_LEGACY_UTMP_APIS"});
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($platformPath))[9];
102 my $header_mtime = (stat($featuresHeader))[9];
104 if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) {
108 printf $arch." features:\n";
109 printf Dumper
(\
%features);
112 die "Unbalanced .if/.endif directive";
115 # And the meat, new header options should go under here
116 if (! -d
$featuresHeaderDir) {
117 mkpath
$featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir";
119 open HEADER
, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader";
121 printf HEADER
"#ifndef _LIBC_FEATURES_H_\n";
122 printf HEADER
"#define _LIBC_FEATURES_H_\n\n";
124 my $shortarch = $arch;
125 $shortarch =~ s/armv\d+[a-z]?/arm/g;
127 # map all arm64 subtypes to arm64
128 $shortarch =~ s/arm64[_a-z0-9]?/arm64/g;
130 printf HEADER
"#if !defined(__".$shortarch."__)\n";
131 printf HEADER
"#error Mismatched libc-features.h architecture\n";
132 printf HEADER
"#endif\n\n";
134 if (defined($features{"FEATURE_LEGACY_RUNE_APIS"})) {
135 printf HEADER
"#define UNIFDEF_LEGACY_RUNE_APIS 1\n";
137 printf HEADER
"/* #undef UNIFDEF_LEGACY_RUNE_APIS */\n";
140 if (defined($features{"FEATURE_LEGACY_CRT1_ENVIRON"})) {
141 printf HEADER
"#define LEGACY_CRT1_ENVIRON 1\n";
143 printf HEADER
"/* #undef LEGACY_CRT1_ENVIRON */\n";
146 if (defined($features{"FEATURE_LEGACY_UTMP_APIS"})) {
147 printf HEADER
"#define UNIFDEF_LEGACY_UTMP_APIS 1\n";
149 printf HEADER
"/* #undef UNIFDEF_LEGACY_UTMP_APIS */\n";
152 if (defined($features{"FEATURE_ONLY_1050_VARIANTS"})) {
153 printf HEADER
"#if !__DARWIN_ONLY_VERS_1050\n";
154 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0\n";
155 printf HEADER
"#endif /* !__DARWIN_ONLY_VERS_1050 */\n";
157 printf HEADER
"#if __DARWIN_ONLY_VERS_1050\n";
158 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1\n";
159 printf HEADER
"#endif /* __DARWIN_ONLY_VERS_1050 */\n";
162 if (defined($features{"FEATURE_ONLY_UNIX_CONFORMANCE"})) {
163 printf HEADER
"#if !__DARWIN_ONLY_UNIX_CONFORMANCE\n";
164 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0\n";
165 printf HEADER
"#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */\n";
167 printf HEADER
"#if __DARWIN_ONLY_UNIX_CONFORMANCE\n";
168 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1\n";
169 printf HEADER
"#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */\n";
172 if (defined($features{"FEATURE_ONLY_64_BIT_INO_T"})) {
173 printf HEADER
"#if !__DARWIN_ONLY_64_BIT_INO_T\n";
174 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0\n";
175 printf HEADER
"#endif /* !__DARWIN_ONLY_64_BIT_INO_T */\n";
177 printf HEADER
"#if __DARWIN_ONLY_64_BIT_INO_T\n";
178 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1\n";
179 printf HEADER
"#endif /* __DARWIN_ONLY_64_BIT_INO_T */\n";
182 if (defined($features{"FEATURE_PATCH_3417676"})) {
183 printf HEADER
"#define __APPLE_PR3417676_HACK__ 1\n";
185 printf HEADER
"/* #undef __APPLE_PR3417676_HACK__ */\n";
188 if (defined($features{"FEATURE_PLOCKSTAT"})) {
189 printf HEADER
"#define PLOCKSTAT 1\n";
191 printf HEADER
"/* #undef PLOCKSTAT */\n";
194 if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) {
195 printf HEADER
"#define NOTIFY_TZ 1\n";
197 printf HEADER
"/* #undef NOTIFY_TZ */\n";
200 if (defined($features{"FEATURE_SMALL_STDIOBUF"})) {
201 printf HEADER
"#define FEATURE_SMALL_STDIOBUF 1\n";
203 printf HEADER
"/* #undef FEATURE_SMALL_STDIOBUF */\n";
206 if (defined($features{"FEATURE_XPRINTF_PERF"})) {
207 printf HEADER
"#define XPRINTF_PERF 1\n";
209 printf HEADER
"/* #undef XPRINTF_PERF */\n";
212 if (defined($features{"FEATURE_SIGNAL_RESTRICTION"})) {
213 printf HEADER
"#define FEATURE_SIGNAL_RESTRICTION 1\n";
215 printf HEADER
"/* #undef FEATURE_SIGNAL_RESTRICTION */\n";
218 printf HEADER
"#endif // _LIBC_FEATURES_H_\n";