]>
git.saurik.com Git - apple/libc.git/blob - xcodescripts/patch_headers_variants.pl
3 # Copyright (c) 2006, 2007 Apple Inc. All rights reserved.
5 # @APPLE_LICENSE_HEADER_START@
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
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.
22 # @APPLE_LICENSE_HEADER_END@
24 # patchheaders srcdir destdir
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:
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 */
38 use File
::Basename
();
43 my $MyName = File
::Basename
::basename
($0);
47 my($path, $file) = @_;
50 my $dest_mtime = (stat($file))[9];
51 my $src_mtime = (stat($path))[9];
53 if ($dest_mtime > $src_mtime) {
58 my($fname, $dirs, $suffix) = File
::Basename
::fileparse
($file, ".h");
59 if ($suffix ne ".h") {
63 my $p = IO
::File-
>new($path, 'r');
64 die "$MyName: Can't open $path: $!\n" unless defined($p);
65 my $f = IO
::File-
>new($file, 'w');
66 die "$MyName: Can't open $file: $!\n" unless defined($f);
69 if(/^\S/ or /^\s*$/) {
70 my $n = scalar(@save);
73 my($sym) = ($save[$n - 1] =~ /__DARWIN_(?:10\d+|ALIAS|EXTSN|INODE64)[^(]*\(([^)]*)\)/);
74 if($save[$n - 1] =~ /__DARWIN_ALIAS_STARTING/) {
85 $f->print("#ifndef LIBC_ALIAS_$sym\n");
89 $save[$n - 1] =~ s/__DARWIN_(10\d+|ALIAS|EXTSN|INODE64)/LIBC_$1/;
90 $f->print("#else /* LIBC_ALIAS_$sym */\n");
92 $f->print("#endif /* !LIBC_ALIAS_$sym */\n");
109 die "Usage: $MyName srcdir dstdir\n";
113 if(-d
$File::Find
::name
) {
114 #print "DIR: $File::Find::name\n";
115 my $dir = File
::Spec-
>join($dest, $File::Find
::name
);
116 File
::Path
::mkpath
($dir, 0, 0755);
118 #print "FIL: $File::Find::name\n";
119 my $file = File
::Spec-
>join($dest, $File::Find
::name
);
120 process
($File::Find
::name
, $file);
124 usage
() unless scalar(@ARGV) == 2;
125 my $start = File
::Basename
::dirname
($ARGV[0]);
126 chdir($start) || die "$MyName: chdir($start): $!\n";
128 File
::Path
::mkpath
($dest, 0, 0755);
129 File
::Find
::find
({wanted
=> \
&wanted
, no_chdir
=> 1}, File
::Basename
::basename
($ARGV[0]));