]> git.saurik.com Git - apple/configd.git/blame - SystemConfiguration.fproj/update-headers
configd-963.50.8.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / update-headers
CommitLineData
a40a14f8
A
1#!/usr/bin/perl
2
3if (!$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
9de8ab86
A
9$USING_PRIVATE_SYSTEMCONFIGURATION_FRAMEWORK = $ENV{"USING_PRIVATE_SYSTEMCONFIGURATION_FRAMEWORK"} eq "YES";
10
a40a14f8
A
11$API_BASE = $ENV{"INSTALL_DIR"} . "/" . $ENV{"PUBLIC_HEADERS_FOLDER_PATH"};
12$SPI_BASE = $ENV{"INSTALL_DIR"} . "/" . $ENV{"PRIVATE_HEADERS_FOLDER_PATH"};
13
14sub clean_INC {
15 my ($inc) = @_;
16
17 $inc =~ s/#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/.*?>.*?\n#else.*?\n//;
18 $inc =~ s/#endif\s+.*?USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS.*?\n//;
6bb65964 19
a40a14f8
A
20 return $inc;
21}
22
23sub clean_API {
24 my ($api) = @_;
25 my ($api_new);
26
27 $api_new = $DO_SPLIT ? $api : clean_INC($api);
28 $api_new =~ s/(__MAC)_\w+\/\*SPI\*\//\1_NA/g;
5e9ce69e 29 $api_new =~ s/#define\t__AVAILABILITY_INTERNAL__.*FUTURE.*\/\*SPI\*\/\n//;
a40a14f8 30 $api_new =~ s/(__IPHONE)_\w+\/\*SPI\*\//\1_NA/g;
a40a14f8
A
31
32 return $api_new;
33}
34
35sub clean_SPI {
36 my ($spi) = @_;
37 my ($spi_new);
38
39 $spi_new = clean_INC($spi);
40 $spi_new =~ s/(__MAC_\w+)\/\*SPI\*\//\1/g;
5e9ce69e 41 $spi_new =~ s/(#define\t__AVAILABILITY_INTERNAL__.*FUTURE.*)\/\*SPI\*\//\1/;
a40a14f8 42 $spi_new =~ s/(__IPHONE_\w+)\/\*SPI\*\//\1/g;
a40a14f8
A
43
44 return $spi_new;
45}
46
9de8ab86
A
47sub create_STUB {
48 my ($api_header) = @_;
49 my ($stub_new);
50
51 $stub_new = "
52#warning \"Please #include <SystemConfiguration/PUBLIC.h> instead of this file directly.\"
53#include <SystemConfiguration/PUBLIC.h>
54";
55 $stub_new =~ s/PUBLIC.h/$api_header/g;
56
57 return $stub_new;
58}
59
a40a14f8
A
60#
61# Update .../PrivateHeaders
62#
63
64opendir(HEADERS, $SPI_BASE);
65@headers = readdir(HEADERS);
66closedir(HEADERS);
67
68undef $/;
69for (@headers) {
70 next if ($_ eq '.');
71 next if ($_ eq '..');
72
73 $spi_header = $_;
74 $spi_path = $SPI_BASE . "/" . $spi_header;
75 next if (! -f $spi_path);
76
77 open(SPI, "<", $spi_path);
78 $spi = <SPI>;
79 close(SPI);
80
81 $spi_new = clean_SPI($spi);
82 if ($spi ne $spi_new) {
6bb65964 83 printf "cleaning .../PrivateHeaders/%s\n", $spi_header;
a40a14f8
A
84 open(SPI, ">", $spi_path);
85 print SPI $spi_new;
86 close(SPI);
87 }
88}
89$/ = "\n";
90
91#
92# Update .../Headers
93#
94
95opendir(HEADERS, $API_BASE);
96@headers = readdir(HEADERS);
97closedir(HEADERS);
98
99undef $/;
100for (@headers) {
101 next if ($_ eq '.');
102 next if ($_ eq '..');
103
104 $api_header = $_;
105 $api_path = $API_BASE . "/" . $api_header;
106 next if (! -f $api_path);
107
108 open(API, "<", $api_path);
109 $api = <API>;
110 close(API);
111
112 $api_new = clean_API($api);
9de8ab86
A
113 next if ($api eq $api_new); # if no tweaks needed
114
115 if (!$USING_PRIVATE_SYSTEMCONFIGURATION_FRAMEWORK) {
6bb65964 116 printf "cleaning .../Headers/%s\n", $api_header;
a40a14f8
A
117 open(API, ">", $api_path);
118 print API $api_new;
119 close(API);
120
121 if ($DO_SPLIT) {
122 $spi_new = clean_SPI($api);
123 if ($api_new ne $spi_new) {
124 if ((($spi_header) = ($api =~ /#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/(.*?\.h)>\s*.*?\n/))) {
125 if ($api_header eq $spi_header) {
126 die "API & SPI header not unique: $api_header\n";
127 }
128 } else {
129 die "Header missing #ifdef/#else/#endif: $api_header\n";
130# $spi_header = $api_header;
131# $spi_header =~ s/\.h$/PRIVATE.h/;
132 }
133
6bb65964 134 printf " adding .../PrivateHeaders/%s\n", $spi_header;
a40a14f8
A
135 $spi_path = $SPI_BASE . "/" . $spi_header;
136 open(SPI, ">", $spi_path);
137 print SPI $spi_new;
138 close(SPI);
139 }
140 }
9de8ab86
A
141 } else {
142 $spi_new = clean_SPI($api);
143 if ($api_new ne $spi_new) {
144 if ((($stub_header) = ($api =~ /#ifdef\s+USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS\s*.*?\n#include\s+<SystemConfiguration\/(.*?\.h)>\s*.*?\n/))) {
145 if ($api_header eq $stub_header) {
146 die "API & STUB header not unique: $api_header\n";
147 }
148 } else {
149 die "Header missing #ifdef/#else/#endif: $api_header\n";
150 }
151
152 printf "updating .../Headers/%s\n", $api_header;
153 open(API, ">", $api_path);
154 print API $spi_new;
155 close(API);
156
157 printf " adding .../PrivateHeaders/%s (stub)\n", $stub_header;
158 $stub_path = $SPI_BASE . "/" . $stub_header;
159 $stub_new = create_STUB($api_header);
160 open(STUB, ">", $stub_path);
161 print STUB $stub_new;
162 close(STUB);
163 }
a40a14f8
A
164 }
165}
166$/ = "\n";
167
168exit 0;