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