]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/update-headers
configd-395.11.tar.gz
[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/(__IPHONE)_\w+\/\*SPI\*\//\1_NA/g;
28
29 return $api_new;
30 }
31
32 sub clean_SPI {
33 my ($spi) = @_;
34 my ($spi_new);
35
36 $spi_new = clean_INC($spi);
37 $spi_new =~ s/(__MAC_\w+)\/\*SPI\*\//\1/g;
38 $spi_new =~ s/(__IPHONE_\w+)\/\*SPI\*\//\1/g;
39
40 return $spi_new;
41 }
42
43 #
44 # Update .../PrivateHeaders
45 #
46
47 opendir(HEADERS, $SPI_BASE);
48 @headers = readdir(HEADERS);
49 closedir(HEADERS);
50
51 undef $/;
52 for (@headers) {
53 next if ($_ eq '.');
54 next if ($_ eq '..');
55
56 $spi_header = $_;
57 $spi_path = $SPI_BASE . "/" . $spi_header;
58 next if (! -f $spi_path);
59
60 open(SPI, "<", $spi_path);
61 $spi = <SPI>;
62 close(SPI);
63
64 $spi_new = clean_SPI($spi);
65 if ($spi ne $spi_new) {
66 printf "cleaning .../PrivateHeaders/%s\n", $spi_header;
67 open(SPI, ">", $spi_path);
68 print SPI $spi_new;
69 close(SPI);
70 }
71 }
72 $/ = "\n";
73
74 #
75 # Update .../Headers
76 #
77
78 opendir(HEADERS, $API_BASE);
79 @headers = readdir(HEADERS);
80 closedir(HEADERS);
81
82 undef $/;
83 for (@headers) {
84 next if ($_ eq '.');
85 next if ($_ eq '..');
86
87 $api_header = $_;
88 $api_path = $API_BASE . "/" . $api_header;
89 next if (! -f $api_path);
90
91 open(API, "<", $api_path);
92 $api = <API>;
93 close(API);
94
95 $api_new = clean_API($api);
96 if ($api ne $api_new) {
97 printf "cleaning .../Headers/%s\n", $api_header;
98 open(API, ">", $api_path);
99 print API $api_new;
100 close(API);
101
102 if ($DO_SPLIT) {
103 $spi_new = clean_SPI($api);
104 if ($api_new ne $spi_new) {
105 if ((($spi_header) = ($api =~ /#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/(.*?\.h)>\s*.*?\n/))) {
106 if ($api_header eq $spi_header) {
107 die "API & SPI header not unique: $api_header\n";
108 }
109 } else {
110 die "Header missing #ifdef/#else/#endif: $api_header\n";
111 # $spi_header = $api_header;
112 # $spi_header =~ s/\.h$/PRIVATE.h/;
113 }
114
115 printf " adding .../PrivateHeaders/%s\n", $spi_header;
116 $spi_path = $SPI_BASE . "/" . $spi_header;
117 open(SPI, ">", $spi_path);
118 print SPI $spi_new;
119 close(SPI);
120 }
121 }
122 }
123 }
124 $/ = "\n";
125
126 exit 0;