]>
git.saurik.com Git - apple/libc.git/blob - xcodescripts/generate_features.pl
ac5479559ac3ea2c10a3f8033622be14a12dcfc6
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{"PLATFORM_NAME"};
24 $platformName =~ s/simulator/os/;
26 my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc";
27 my $featuresHeaderDir = $ENV{"DERIVED_FILES_DIR"}."/".$arch;
28 my $featuresHeader = $featuresHeaderDir."/libc-features.h";
30 open FEATURESFILE
, "<$platformPath" or die "Unable to open: $platformPath";
36 while (<FEATURESFILE
>) {
39 if ($_ =~ /^.endif/) {
44 elsif ($_ =~ /^\.if\s+(\S+)\s+(\S+)/) {
45 # an if statement, very rudimentary regex against envvar
50 if (!defined($ENV{$envvar}) || ($ENV{$envvar} !~ /$regex/)) {
55 elsif ($_ =~ /^\s*([^= ]+)\s*=\s*(\d)/) {
59 } elsif (defined($features{$1})) {
69 for my $f (keys %features) {
70 print "$f=$features{$f} ";
76 elsif ($unifdef == 1) {
77 if ($platformName eq "macosx") {
78 $unifdefs{"__OSX_OPEN_SOURCE__"} = 1;
80 # assume FEATURE_BLOCKS was on by default
81 $unifdefs{"UNIFDEF_BLOCKS"} = 1;
82 $unifdefs{"UNIFDEF_LEGACY_64_APIS"} = defined($features{"FEATURE_LEGACY_64_APIS"});
83 $unifdefs{"UNIFDEF_LEGACY_RUNE_APIS"} = defined($features{"FEATURE_LEGACY_RUNE_APIS"});
84 $unifdefs{"UNIFDEF_LEGACY_UTMP_APIS"} = defined($features{"FEATURE_LEGACY_UTMP_APIS"});
85 $unifdefs{"UNIFDEF_MOVE_LOCALTIME"} = defined($features{"FEATURE_MOVE_LOCALTIME"});
86 $unifdefs{"UNIFDEF_TZDIR_SYMLINK"} = defined($features{"FEATURE_TZDIR_SYMLINK"});
89 for my $d (keys %unifdefs) {
90 $output .= " " . ($unifdefs{$d} == 1 ? "-D" : "-U") . $d;
98 elsif ($unifdef == 0) {
99 # If we touch this file on every build, then every other iterative build in Xcode will rebuild *everything*
100 my $platform_mtime = (stat($platformPath))[9];
101 my $header_mtime = (stat($featuresHeader))[9];
103 if (defined($header_mtime) && defined($platform_mtime) && ($header_mtime > $platform_mtime)) {
107 printf $arch." features:\n";
108 printf Dumper
(\
%features);
111 die "Unbalanced .if/.endif directive";
114 # And the meat, new header options should go under here
115 if (! -d
$featuresHeaderDir) {
116 mkpath
$featuresHeaderDir or die "Unable to mkdir: $featuresHeaderDir";
118 open HEADER
, ">$featuresHeader" or die "Unable to open (for writing): $featuresHeader";
120 printf HEADER
"#ifndef _LIBC_FEATURES_H_\n";
121 printf HEADER
"#define _LIBC_FEATURES_H_\n\n";
123 my $shortarch = $arch;
124 $shortarch =~ s/armv\d+[a-z]?/arm/g;
126 printf HEADER
"#if !defined(__".$shortarch."__)\n";
127 printf HEADER
"#error Mismatched libc-features.h architecture\n";
128 printf HEADER
"#endif\n\n";
130 if (defined($features{"FEATURE_LEGACY_RUNE_APIS"})) {
131 printf HEADER
"#define UNIFDEF_LEGACY_RUNE_APIS 1\n";
133 printf HEADER
"/* #undef UNIFDEF_LEGACY_RUNE_APIS */\n";
136 if (defined($features{"FEATURE_LEGACY_CRT1_ENVIRON"})) {
137 printf HEADER
"#define LEGACY_CRT1_ENVIRON 1\n";
139 printf HEADER
"/* #undef LEGACY_CRT1_ENVIRON */\n";
142 if (defined($features{"FEATURE_LEGACY_UTMP_APIS"})) {
143 printf HEADER
"#define UNIFDEF_LEGACY_UTMP_APIS 1\n";
145 printf HEADER
"/* #undef UNIFDEF_LEGACY_UTMP_APIS */\n";
148 if (defined($features{"FEATURE_MOVE_LOCALTIME"})) {
149 printf HEADER
"#define UNIFDEF_MOVE_LOCALTIME 1\n";
151 printf HEADER
"/* #undef UNIFDEF_MOVE_LOCALTIME */\n";
154 if (defined($features{"FEATURE_TZDIR_SYMLINK"})) {
155 printf HEADER
"#define UNIFDEF_TZDIR_SYMLINK 1\n";
157 printf HEADER
"/* #undef UNIFDEF_TZDIR_SYMLINK */\n";
160 if (defined($features{"FEATURE_ONLY_1050_VARIANTS"})) {
161 printf HEADER
"#if !__DARWIN_ONLY_VERS_1050\n";
162 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0\n";
163 printf HEADER
"#endif /* !__DARWIN_ONLY_VERS_1050 */\n";
165 printf HEADER
"#if __DARWIN_ONLY_VERS_1050\n";
166 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1\n";
167 printf HEADER
"#endif /* __DARWIN_ONLY_VERS_1050 */\n";
170 if (defined($features{"FEATURE_ONLY_UNIX_CONFORMANCE"})) {
171 printf HEADER
"#if !__DARWIN_ONLY_UNIX_CONFORMANCE\n";
172 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0\n";
173 printf HEADER
"#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */\n";
175 printf HEADER
"#if __DARWIN_ONLY_UNIX_CONFORMANCE\n";
176 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1\n";
177 printf HEADER
"#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */\n";
180 if (defined($features{"FEATURE_ONLY_64_BIT_INO_T"})) {
181 printf HEADER
"#if !__DARWIN_ONLY_64_BIT_INO_T\n";
182 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0\n";
183 printf HEADER
"#endif /* !__DARWIN_ONLY_64_BIT_INO_T */\n";
185 printf HEADER
"#if __DARWIN_ONLY_64_BIT_INO_T\n";
186 printf HEADER
"# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1\n";
187 printf HEADER
"#endif /* __DARWIN_ONLY_64_BIT_INO_T */\n";
190 if (defined($features{"FEATURE_PATCH_3417676"})) {
191 printf HEADER
"#define __APPLE_PR3417676_HACK__ 1\n";
193 printf HEADER
"/* #undef __APPLE_PR3417676_HACK__ */\n";
196 if (defined($features{"FEATURE_PLOCKSTAT"})) {
197 printf HEADER
"#define PLOCKSTAT 1\n";
199 printf HEADER
"/* #undef PLOCKSTAT */\n";
202 if (defined($features{"FEATURE_TIMEZONE_CHANGE_NOTIFICATION"})) {
203 printf HEADER
"#define NOTIFY_TZ 1\n";
205 printf HEADER
"/* #undef NOTIFY_TZ */\n";
208 if (defined($features{"FEATURE_NO_LIBCRASHREPORTERCLIENT"})) {
209 printf HEADER
"#define LIBC_NO_LIBCRASHREPORTERCLIENT 1\n";
211 printf HEADER
"/* #undef LIBC_NO_LIBCRASHREPORTERCLIENT */\n";
214 if (defined($features{"FEATURE_SMALL_STDIOBUF"})) {
215 printf HEADER
"#define FEATURE_SMALL_STDIOBUF 1\n";
217 printf HEADER
"/* #undef FEATURE_SMALL_STDIOBUF */\n";
220 if (defined($features{"FEATURE_XPRINTF_PERF"})) {
221 printf HEADER
"#define XPRINTF_PERF 1\n";
223 printf HEADER
"/* #undef XPRINTF_PERF */\n";
226 if (defined($features{"FEATURE_SIGNAL_RESTRICTION"})) {
227 printf HEADER
"#define FEATURE_SIGNAL_RESTRICTION 1\n";
229 printf HEADER
"/* #undef FEATURE_SIGNAL_RESTRICTION */\n";
232 printf HEADER
"#endif // _LIBC_FEATURES_H_\n";