]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/update-headers
62838ac2df2436a70c2543f2123f162468282cd9
[apple/configd.git] / SystemConfiguration.fproj / update-headers
1 #!/usr/bin/perl
2
3 if (!$ENV{"INSTALL_DIR"} or !$ENV{"PUBLIC_HEADERS_FOLDER_PATH"} or !$ENV{"PRIVATE_HEADERS_FOLDER_PATH"}) {
4 die "Cannot update headers, missing ENV vars\n";
5 }
6
7 $DO_SPLIT = ($#ARGV >= 0 and $ARGV[0] eq "split");
8
9 $API_BASE = $ENV{"INSTALL_DIR"} . "/" . $ENV{"PUBLIC_HEADERS_FOLDER_PATH"};
10 $SPI_BASE = $ENV{"INSTALL_DIR"} . "/" . $ENV{"PRIVATE_HEADERS_FOLDER_PATH"};
11
12 sub clean_INC {
13 my ($inc) = @_;
14
15 $inc =~ s/#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/.*?>.*?\n#else.*?\n//;
16 $inc =~ s/#endif\s+.*?USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS.*?\n//;
17
18 return $inc;
19 }
20
21 sub clean_API {
22 my ($api) = @_;
23 my ($api_new);
24
25 $api_new = $DO_SPLIT ? $api : clean_INC($api);
26 $api_new =~ s/(__MAC)_\w+\/\*SPI\*\//\1_NA/g;
27 $api_new =~ s/(\(__MAC_OS_X_VERSION_MIN_REQUIRED >= \d+\)\/\*SPI\*\/ \|\| )//g;
28 $api_new =~ s/(__IPHONE)_\w+\/\*SPI\*\//\1_NA/g;
29 $api_new =~ s/( \|\| \(__IPHONE_OS_VERSION_MIN_REQUIRED >= \d+\))\/\*SPI\*\///g;
30
31 return $api_new;
32 }
33
34 sub clean_SPI {
35 my ($spi) = @_;
36 my ($spi_new);
37
38 $spi_new = clean_INC($spi);
39 $spi_new =~ s/(__MAC_\w+)\/\*SPI\*\//\1/g;
40 $api_new =~ s/(\(__MAC_OS_X_VERSION_MIN_REQUIRED >= \d+\))\/\*SPI\*\/( \|\| )/\1\2/g;
41 $spi_new =~ s/(__IPHONE_\w+)\/\*SPI\*\//\1/g;
42 $spi_new =~ s/( \|\| )(\(__IPHONE_OS_VERSION_MIN_REQUIRED >= \d+\))\/\*SPI\*\//\1\2/g;
43
44 return $spi_new;
45 }
46
47 #
48 # Update .../PrivateHeaders
49 #
50
51 opendir(HEADERS, $SPI_BASE);
52 @headers = readdir(HEADERS);
53 closedir(HEADERS);
54
55 undef $/;
56 for (@headers) {
57 next if ($_ eq '.');
58 next if ($_ eq '..');
59
60 $spi_header = $_;
61 $spi_path = $SPI_BASE . "/" . $spi_header;
62 next if (! -f $spi_path);
63
64 open(SPI, "<", $spi_path);
65 $spi = <SPI>;
66 close(SPI);
67
68 $spi_new = clean_SPI($spi);
69 if ($spi ne $spi_new) {
70 # printf "cleaning .../PrivateHeaders/%s\n", $spi_header;
71 open(SPI, ">", $spi_path);
72 print SPI $spi_new;
73 close(SPI);
74 }
75 }
76 $/ = "\n";
77
78 #
79 # Update .../Headers
80 #
81
82 opendir(HEADERS, $API_BASE);
83 @headers = readdir(HEADERS);
84 closedir(HEADERS);
85
86 undef $/;
87 for (@headers) {
88 next if ($_ eq '.');
89 next if ($_ eq '..');
90
91 $api_header = $_;
92 $api_path = $API_BASE . "/" . $api_header;
93 next if (! -f $api_path);
94
95 open(API, "<", $api_path);
96 $api = <API>;
97 close(API);
98
99 $api_new = clean_API($api);
100 if ($api ne $api_new) {
101 # printf "cleaning .../Headers/%s\n", $api_header;
102 open(API, ">", $api_path);
103 print API $api_new;
104 close(API);
105
106 if ($DO_SPLIT) {
107 $spi_new = clean_SPI($api);
108 if ($api_new ne $spi_new) {
109 if ((($spi_header) = ($api =~ /#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/(.*?\.h)>\s*.*?\n/))) {
110 if ($api_header eq $spi_header) {
111 die "API & SPI header not unique: $api_header\n";
112 }
113 } else {
114 die "Header missing #ifdef/#else/#endif: $api_header\n";
115 # $spi_header = $api_header;
116 # $spi_header =~ s/\.h$/PRIVATE.h/;
117 }
118
119 # printf " adding .../PrivateHeaders/%s\n", $spi_header;
120 $spi_path = $SPI_BASE . "/" . $spi_header;
121 open(SPI, ">", $spi_path);
122 print SPI $spi_new;
123 close(SPI);
124 }
125 }
126 }
127 }
128 $/ = "\n";
129
130 exit 0;