]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | # | |
3 | # Copyright (c) 2006, 2007 Apple Inc. All rights reserved. | |
4 | # | |
5 | # @APPLE_LICENSE_HEADER_START@ | |
6 | # | |
7 | # This file contains Original Code and/or Modifications of Original Code | |
8 | # as defined in and that are subject to the Apple Public Source License | |
9 | # Version 2.0 (the 'License'). You may not use this file except in | |
10 | # compliance with the License. Please obtain a copy of the License at | |
11 | # http://www.opensource.apple.com/apsl/ and read it before using this | |
12 | # file. | |
13 | # | |
14 | # The Original Code and all software distributed under the License are | |
15 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
19 | # Please see the License for the specific language governing rights and | |
20 | # limitations under the License. | |
21 | # | |
22 | # @APPLE_LICENSE_HEADER_END@ | |
23 | # | |
24 | # patchheaders srcdir destdir | |
25 | # | |
26 | # The last path component of srcdir is replicated in destdir, with the | |
27 | # __DARWIN_ALIAS* and __DARWIN_EXTSN macro wrapped so that Libc can set | |
28 | # the symbol decoration independently: | |
29 | # | |
30 | # #ifndef LIBC_ALIAS_FOO | |
31 | # int foo(int) __DARWIN_ALIAS(foo); | |
32 | # #else /* LIBC_ALIAS_FOO */ | |
33 | # int foo(int) LIBC_ALIAS(foo); | |
34 | # #endif /* !LIBC_ALIAS_FOO */ | |
35 | ||
36 | use strict; | |
37 | use IO::File; | |
38 | use File::Basename (); | |
39 | use File::Find (); | |
40 | use File::Path (); | |
41 | use File::Spec; | |
42 | ||
43 | my $MyName = File::Basename::basename($0); | |
44 | my $dest; | |
45 | ||
46 | sub process { | |
47 | my($path, $file) = @_; | |
48 | local $_; | |
49 | my $p = IO::File->new($path, 'r'); | |
50 | die "$MyName: Can't open $path: $!\n" unless defined($p); | |
51 | my $f = IO::File->new($file, 'w'); | |
52 | die "$MyName: Can't open $file: $!\n" unless defined($f); | |
53 | my @save; | |
54 | while(<$p>) { | |
55 | if(/^\S/ or /^\s*$/) { | |
56 | my $n = scalar(@save); | |
57 | my $sym; | |
58 | if($n > 0) { | |
59 | my($sym) = ($save[$n - 1] =~ /__DARWIN_(?:10\d+|ALIAS|EXTSN|INODE64)[^(]*\(([^)]*)\)/); | |
60 | if(defined($sym)) { | |
61 | if(defined($path)) { | |
62 | print " $path\n"; | |
63 | undef($path); | |
64 | } | |
65 | $sym =~ s/^\s+//; | |
66 | $sym =~ s/\s+$//; | |
67 | $sym =~ tr/a-z/A-Z/; | |
68 | $f->print("#ifndef LIBC_ALIAS_$sym\n"); | |
69 | } | |
70 | $f->print(@save); | |
71 | if(defined($sym)) { | |
72 | $save[$n - 1] =~ s/__DARWIN_(10\d+|ALIAS|EXTSN|INODE64)/LIBC_$1/; | |
73 | $f->print("#else /* LIBC_ALIAS_$sym */\n"); | |
74 | $f->print(@save); | |
75 | $f->print("#endif /* !LIBC_ALIAS_$sym */\n"); | |
76 | } | |
77 | } | |
78 | if(/^#/) { | |
79 | $f->print($_); | |
80 | @save = (); | |
81 | } else { | |
82 | @save = ($_); | |
83 | } | |
84 | } else { | |
85 | push(@save, $_); | |
86 | } | |
87 | } | |
88 | $f->print(@save); | |
89 | } | |
90 | ||
91 | sub usage { | |
92 | die "Usage: $MyName srcdir dstdir\n"; | |
93 | } | |
94 | ||
95 | sub wanted { | |
96 | if(-d $File::Find::name) { | |
97 | #print "DIR: $File::Find::name\n"; | |
98 | my $dir = File::Spec->join($dest, $File::Find::name); | |
99 | File::Path::mkpath($dir, 0, 0755); | |
100 | } else { | |
101 | #print "FIL: $File::Find::name\n"; | |
102 | my $file = File::Spec->join($dest, $File::Find::name); | |
103 | process($File::Find::name, $file); | |
104 | } | |
105 | } | |
106 | ||
107 | usage() unless scalar(@ARGV) == 2; | |
108 | my $start = File::Basename::dirname($ARGV[0]); | |
109 | chdir($start) || die "$MyName: chdir($start): $!\n"; | |
110 | $dest = $ARGV[1]; | |
111 | File::Path::mkpath($dest, 0, 0755); | |
112 | File::Find::find({wanted => \&wanted, no_chdir => 1}, File::Basename::basename($ARGV[0])); |