]>
git.saurik.com Git - apple/libc.git/blob - xcodescripts/generate_features.pl
3 if ($ENV{"ACTION"} eq "installhdrs") {
7 # Generates the libc-features.h files used to control #ifdef behaviour in Libc
10 use File
::Path
qw(mkpath);
12 #printf Dumper(\%ENV);
17 if (scalar(@ARGV) > 0) {
18 $unifdef = 1 if $ARGV[0] =~ /--unifdef/;
19 $bash = 1 if $ARGV[0] =~ /--bash/;
22 for my $arch (split(/ /, $ENV{"ARCHS"}))
24 # set ENV{"CURRENT_ARCH"} so we can predicate on it
25 $ENV{"CURRENT_ARCH"} = $arch;
27 my $platformName = $ENV{"PLATFORM_NAME"};
28 $platformName = "iphoneos" if ($platformName eq "iphonesimulator");
30 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
, "<$platformPath" or die "Unable to open: $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 if ($platformName eq "macosx") {
82 $unifdefs{"__OSX_OPEN_SOURCE__"} = 1;
84 # assume FEATURE_BLOCKS was on by default
85 $unifdefs{"UNIFDEF_BLOCKS"} = 1;
86 $unifdefs{"UNIFDEF_LEGACY_64_APIS"} = defined($features{"FEATURE_LEGACY_64_APIS"});
87 $unifdefs{"UNIFDEF_LEGACY_RUNE_APIS"} = defined($features{"FEATURE_LEGACY_RUNE_APIS"});
88 $unifdefs{"UNIFDEF_LEGACY_UTMP_APIS"} = defined($features{"FEATURE_LEGACY_UTMP_APIS"});
89 $unifdefs{"UNIFDEF_MOVE_LOCALTIME"} = defined($features{"FEATURE_MOVE_LOCALTIME"});
90 $unifdefs{"UNIFDEF_TZDIR_SYMLINK"} = defined($features{"FEATURE_TZDIR_SYMLINK"});
93 for my $d (keys %unifdefs) {
94 $output .= " " . ($unifdefs{$d} == 1 ? "-D" : "-U") . $d;
102 elsif ($unifdef == 0) {
103 # If we touch this file on every build, then every other iterative build in Xcode will rebuild *everything*
104 my $platform_mtime = (stat($platformPath))[9];
105 my $header_mtime = (stat($featuresHeader))[9];
107 if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) {
111 printf $arch." features:\n";
112 printf Dumper
(\
%features);
115 die "Unbalanced .if/.endif directive";
118 # And the meat, new header options should go under here
119 if (! -d
$featuresHeaderDir) {
120 mkpath
$featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir";
122 open HEADER
, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader";
124 printf HEADER
"#ifndef _LIBC_FEATURES_H_\n";
125 printf HEADER
"#define _LIBC_FEATURES_H_\n\n";
127 my $shortarch = $arch;
128 $shortarch =~ s/armv\d+[a-z]?/arm/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_MOVE_LOCALTIME"})) {
153 printf HEADER
"#define UNIFDEF_MOVE_LOCALTIME 1\n";
155 printf HEADER
"/* #undef UNIFDEF_MOVE_LOCALTIME */\n";
158 if (defined($features{"FEATURE_TZDIR_SYMLINK"})) {
159 printf HEADER
"#define UNIFDEF_TZDIR_SYMLINK 1\n";
161 printf HEADER
"/* #undef UNIFDEF_TZDIR_SYMLINK */\n";
164 if (defined($features{"FEATURE_ONLY_1050_VARIANTS"})) {
165 printf HEADER
"#if !__DARWIN_ONLY_VERS_1050\n";
166 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0\n";
167 printf HEADER
"#endif /* !__DARWIN_ONLY_VERS_1050 */\n";
169 printf HEADER
"#if __DARWIN_ONLY_VERS_1050\n";
170 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1\n";
171 printf HEADER
"#endif /* __DARWIN_ONLY_VERS_1050 */\n";
174 if (defined($features{"FEATURE_ONLY_UNIX_CONFORMANCE"})) {
175 printf HEADER
"#if !__DARWIN_ONLY_UNIX_CONFORMANCE\n";
176 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0\n";
177 printf HEADER
"#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */\n";
179 printf HEADER
"#if __DARWIN_ONLY_UNIX_CONFORMANCE\n";
180 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1\n";
181 printf HEADER
"#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */\n";
184 if (defined($features{"FEATURE_ONLY_64_BIT_INO_T"})) {
185 printf HEADER
"#if !__DARWIN_ONLY_64_BIT_INO_T\n";
186 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0\n";
187 printf HEADER
"#endif /* !__DARWIN_ONLY_64_BIT_INO_T */\n";
189 printf HEADER
"#if __DARWIN_ONLY_64_BIT_INO_T\n";
190 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1\n";
191 printf HEADER
"#endif /* __DARWIN_ONLY_64_BIT_INO_T */\n";
194 if (defined($features{"FEATURE_PATCH_3417676"})) {
195 printf HEADER
"#define __APPLE_PR3417676_HACK__ 1\n";
197 printf HEADER
"/* #undef __APPLE_PR3417676_HACK__ */\n";
200 if (defined($features{"FEATURE_PLOCKSTAT"})) {
201 printf HEADER
"#define PLOCKSTAT 1\n";
203 printf HEADER
"/* #undef PLOCKSTAT */\n";
206 if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) {
207 printf HEADER
"#define NOTIFY_TZ 1\n";
209 printf HEADER
"/* #undef NOTIFY_TZ */\n";
212 if (defined($features{"FEATURE_NO_LIBCRASHREPORTERCLIENT"})) {
213 printf HEADER
"#define LIBC_NO_LIBCRASHREPORTERCLIENT 1\n";
215 printf HEADER
"/* #undef LIBC_NO_LIBCRASHREPORTERCLIENT */\n";
218 if (defined($features{"FEATURE_SMALL_STDIOBUF"})) {
219 printf HEADER
"#define FEATURE_SMALL_STDIOBUF 1\n";
221 printf HEADER
"/* #undef FEATURE_SMALL_STDIOBUF */\n";
224 if (defined($features{"FEATURE_XPRINTF_PERF"})) {
225 printf HEADER
"#define XPRINTF_PERF 1\n";
227 printf HEADER
"/* #undef XPRINTF_PERF */\n";
230 printf HEADER
"#endif // _LIBC_FEATURES_H_\n";