]>
git.saurik.com Git - apple/libsystem.git/blob - libsys/build-libc.pl
ff11e1d8df248f1b7707a3f0e5e5ae20583f4dd1
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 ##########################################################################
26 # % build-libc.pl usr-local-lib-system out-directory
28 # This script takes the directory full of the contents libc-partial*.a and
29 # libsyscall*.a, and makes the necessary symbol aliases for those syscalls
30 # that aren't being wrapped in Libc. The usr-local-lib-system is the
31 # /usr/local/lib/system or equivalent directory where the necessary symbol
32 # files from Libc and Libsyscall reside.
34 # A Makefile is created that will build libc*.a from the contents of the
35 # out-directory after symbol aliasing has been added.
37 # The out-directory path must be of the form ".../arch/form", where arch is
38 # the architecture being built and form is one of debug, dynamic and profile.
40 ##########################################################################
44 use File
::Basename
();
49 my $MyName = File
::Basename
::basename
($0);
54 my $StubFile = 'libsyscall.list';
56 debug
=> ['do', '_debug'],,
57 dynamic
=> ['So', ''],,
58 profile
=> ['po', '_profile'],,
60 my $SyscallBase = 'libc.syscall';
62 ##########################################################################
63 # Scan the archive for existing wrappers, and remove them from the stub
65 ##########################################################################
67 my($arch, $dir, $sufname) = @_;
69 my $file = File
::Spec-
>join($dir, "libc-partial$sufname.a");
70 my $f = IO
::File-
>new("nm -g -arch $arch $file |");
71 die "$MyName: nm -g -arch $arch $file: $!\n" unless defined($f);
73 next unless s/^.* T //;
79 ##########################################################################
80 # Read the libc.syscall and any libc.syscall.arch file for additional aliases
81 # for the double underbar syscalls.
82 ##########################################################################
83 sub readLibcSyscalls
{
86 my @files = (File
::Spec-
>join($dir, $SyscallBase));
87 my $archfile = File
::Spec-
>join($dir, "$SyscallBase.$arch");
89 push(@files, $archfile);
90 } elsif($arch =~ s/^armv.*/arm/) {
91 $archfile = File
::Spec-
>join($dir, "$SyscallBase.$arch");
92 push(@files, $archfile) if -r
$archfile;
94 foreach my $file (@files) {
95 my $f = IO
::File-
>new($file, 'r');
96 die "$MyName: $file: $!\n" unless defined($f);
110 ##########################################################################
111 # Read the libsyscall.list file for the system call names and number
112 # of arguments and store in %StubArgs. Also, make an entry for a syscall
114 ##########################################################################
118 my $file = File
::Spec-
>join($dir, $StubFile);
119 my $f = IO
::File-
>new($file, 'r');
120 die "$MyName: $file: $!\n" unless defined($f);
124 if(!($k =~ s/^#//)) {
134 die "Usage: $MyName usr-local-lib-system out-directory\n";
137 usage
() unless scalar(@ARGV) == 2;
138 my($usr_local_lib_system);
139 ($usr_local_lib_system, $OutDir) = @ARGV;
140 die "$MyName: $usr_local_lib_system: No such directory\n" unless -d
$usr_local_lib_system;
141 die "$MyName: $OutDir: No such directory\n" unless -d
$OutDir;
142 my @pieces = File
::Spec-
>splitdir($OutDir);
143 my $form = pop(@pieces);
144 my $arch = pop(@pieces);
145 my $suf = $Suffix{$form};
146 die "$MyName: $form: Unknown form\n" unless defined($suf);
147 my($suffix, $sufname) = @$suf;
148 readStub
($usr_local_lib_system);
149 readLibcSyscalls
($arch, $usr_local_lib_system);
150 processLibc
($arch, $usr_local_lib_system, $sufname);
152 ##########################################################################
153 # Invert the Stub hash, so the key will correspond to the file to process.
154 # The value will be an array ref containing all aliases.
155 ##########################################################################
157 while(my($k, $v) = each(%Stub)) {
159 $a = $Inv{$v} = [] if !defined($a);
163 ##########################################################################
164 # Create the Makefile file
165 ##########################################################################
166 my $path = File
::Spec-
>join($OutDir, 'Makefile');
167 my $f = IO
::File-
>new($path, 'w');
168 die "$MyName: $path: $!\n" unless defined($f);
170 ##########################################################################
171 # List all the object files
172 ##########################################################################
173 my $dir = DirHandle-
>new($OutDir);
174 die "$MyName: can't open $dir\n" unless defined($dir);
175 print $f "OBJS = libsystem.o \\\n";
177 while(defined($_ = $dir->read())) {
178 next unless s/\.$suffix$/.o/;
182 printf $f "\t%s\n", join(" \\\n\t", @objs);
184 ##########################################################################
185 # Add the build logic
186 ##########################################################################
194 ar cq \$(.TARGET) `lorder \$(OBJS) | tsort -q`
199 mv \$(.IMPSRC) \$(.TARGET)
203 ##########################################################################
204 # Special case each binary that needs aliasing
205 ##########################################################################
206 foreach my $k (sort(keys(%Inv))) {
209 print $f "$n.o: $n.$suffix\n";
210 print $f "\tld -arch $arch -r -keep_private_externs";
211 foreach my $i (@{$Inv{$k}}) {
214 printf $f " -alias '$k' '$_'";
216 printf $f " -o \$(.TARGET) \$(.IMPSRC)\n";