xref: /xnu-10063.121.3/libsyscall/xcodescripts/compile-syscalls.pl (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions#!/usr/bin/perl
2*2c2f96dcSApple OSS Distributions#
3*2c2f96dcSApple OSS Distributions# Copyright (c) 2010 Apple Inc. All rights reserved.
4*2c2f96dcSApple OSS Distributions#
5*2c2f96dcSApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6*2c2f96dcSApple OSS Distributions#
7*2c2f96dcSApple OSS Distributions# This file contains Original Code and/or Modifications of Original Code
8*2c2f96dcSApple OSS Distributions# as defined in and that are subject to the Apple Public Source License
9*2c2f96dcSApple OSS Distributions# Version 2.0 (the 'License'). You may not use this file except in
10*2c2f96dcSApple OSS Distributions# compliance with the License. The rights granted to you under the License
11*2c2f96dcSApple OSS Distributions# may not be used to create, or enable the creation or redistribution of,
12*2c2f96dcSApple OSS Distributions# unlawful or unlicensed copies of an Apple operating system, or to
13*2c2f96dcSApple OSS Distributions# circumvent, violate, or enable the circumvention or violation of, any
14*2c2f96dcSApple OSS Distributions# terms of an Apple operating system software license agreement.
15*2c2f96dcSApple OSS Distributions#
16*2c2f96dcSApple OSS Distributions# Please obtain a copy of the License at
17*2c2f96dcSApple OSS Distributions# http://www.opensource.apple.com/apsl/ and read it before using this file.
18*2c2f96dcSApple OSS Distributions#
19*2c2f96dcSApple OSS Distributions# The Original Code and all software distributed under the License are
20*2c2f96dcSApple OSS Distributions# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21*2c2f96dcSApple OSS Distributions# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22*2c2f96dcSApple OSS Distributions# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23*2c2f96dcSApple OSS Distributions# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24*2c2f96dcSApple OSS Distributions# Please see the License for the specific language governing rights and
25*2c2f96dcSApple OSS Distributions# limitations under the License.
26*2c2f96dcSApple OSS Distributions#
27*2c2f96dcSApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28*2c2f96dcSApple OSS Distributions#
29*2c2f96dcSApple OSS Distributions
30*2c2f96dcSApple OSS Distributionsuse warnings;
31*2c2f96dcSApple OSS Distributionsuse strict;
32*2c2f96dcSApple OSS Distributions
33*2c2f96dcSApple OSS Distributionsuse Data::Dumper;
34*2c2f96dcSApple OSS Distributionsuse File::Spec;
35*2c2f96dcSApple OSS Distributionsuse IO::File;
36*2c2f96dcSApple OSS Distributionsuse File::Basename ();
37*2c2f96dcSApple OSS Distributions
38*2c2f96dcSApple OSS Distributionsmy $basename = File::Basename::basename($0);
39*2c2f96dcSApple OSS Distributions
40*2c2f96dcSApple OSS Distributionssub usage {
41*2c2f96dcSApple OSS Distributions	print "$basename: <source list> <output archive>";
42*2c2f96dcSApple OSS Distributions	exit 1;
43*2c2f96dcSApple OSS Distributions}
44*2c2f96dcSApple OSS Distributions
45*2c2f96dcSApple OSS Distributionsusage unless scalar(@ARGV) == 2;
46*2c2f96dcSApple OSS Distributions
47*2c2f96dcSApple OSS Distributionsmy $sourceList = $ARGV[0];
48*2c2f96dcSApple OSS Distributionsmy $outputFile = $ARGV[1];
49*2c2f96dcSApple OSS Distributions
50*2c2f96dcSApple OSS Distributionsmy $f = IO::File->new($sourceList, 'r');
51*2c2f96dcSApple OSS Distributionsdie "$basename: $sourceList: $!\n" unless defined($f);
52*2c2f96dcSApple OSS Distributions
53*2c2f96dcSApple OSS Distributionsmy @objects;
54*2c2f96dcSApple OSS Distributionsmy @archs = split / /, $ENV{"ARCHS"};
55*2c2f96dcSApple OSS Distributionsmy @sources = <$f>;
56*2c2f96dcSApple OSS Distributionschomp @sources;
57*2c2f96dcSApple OSS Distributions
58*2c2f96dcSApple OSS Distributionsundef $f;
59*2c2f96dcSApple OSS Distributions
60*2c2f96dcSApple OSS Distributions# compiler options
61*2c2f96dcSApple OSS Distributionschomp(my $CC = `xcrun -sdk "$ENV{'SDKROOT'}" -find cc`);
62*2c2f96dcSApple OSS Distributionsmy @CFLAGS = (
63*2c2f96dcSApple OSS Distributions	"-x assembler-with-cpp",
64*2c2f96dcSApple OSS Distributions	"-c",
65*2c2f96dcSApple OSS Distributions	"-isysroot", $ENV{'SDKROOT'} || "/",
66*2c2f96dcSApple OSS Distributions	"-I".$ENV{"SDKROOT"}."/".$ENV{"SDK_INSTALL_HEADERS_ROOT"}."/usr/include",
67*2c2f96dcSApple OSS Distributions	"-I".$ENV{"SDKROOT"}."/".$ENV{"SDK_INSTALL_HEADERS_ROOT"}."/usr/local/include",
68*2c2f96dcSApple OSS Distributions	"-I".$ENV{"SDKROOT"}."/".$ENV{"SDK_INSTALL_HEADERS_ROOT"}."/System/Library/Frameworks/System.framework/PrivateHeaders",
69*2c2f96dcSApple OSS Distributions);
70*2c2f96dcSApple OSS Distributions
71*2c2f96dcSApple OSS Distributionschomp(my $LIBTOOL = `xcrun -sdk "$ENV{'SDKROOT'}" -find libtool`);
72*2c2f96dcSApple OSS Distributionsmy @LIBTOOLFLAGS = (
73*2c2f96dcSApple OSS Distributions	"-static",
74*2c2f96dcSApple OSS Distributions);
75*2c2f96dcSApple OSS Distributions
76*2c2f96dcSApple OSS Distributions# architectures
77*2c2f96dcSApple OSS Distributionsfor my $arch (@archs) {
78*2c2f96dcSApple OSS Distributions	push(@CFLAGS, "-arch $arch");
79*2c2f96dcSApple OSS Distributions}
80*2c2f96dcSApple OSS Distributions
81*2c2f96dcSApple OSS Distributions# do each compile
82*2c2f96dcSApple OSS Distributionsmy $jobs = `sysctl -n hw.ncpu` + 2;
83*2c2f96dcSApple OSS Distributions
84*2c2f96dcSApple OSS Distributionsfor my $src (@sources) {
85*2c2f96dcSApple OSS Distributions	if ($jobs == 0) {
86*2c2f96dcSApple OSS Distributions		if (wait != -1) {
87*2c2f96dcSApple OSS Distributions			$jobs++;
88*2c2f96dcSApple OSS Distributions		} else {
89*2c2f96dcSApple OSS Distributions			printf "wait exited with -1 (no children) and exhausted allowed jobs. Exiting.\n";
90*2c2f96dcSApple OSS Distributions			exit 1;
91*2c2f96dcSApple OSS Distributions		}
92*2c2f96dcSApple OSS Distributions
93*2c2f96dcSApple OSS Distributions		if ($? != 0) {
94*2c2f96dcSApple OSS Distributions			printf "$CC exited with value %d\n", $? >> 8;
95*2c2f96dcSApple OSS Distributions			exit 1;
96*2c2f96dcSApple OSS Distributions		}
97*2c2f96dcSApple OSS Distributions	}
98*2c2f96dcSApple OSS Distributions
99*2c2f96dcSApple OSS Distributions	(my $o = $src) =~ s/\.s$/\.o/;
100*2c2f96dcSApple OSS Distributions	my $compileCommand = "$CC " . join(' ', @CFLAGS) . " -o $o $src";
101*2c2f96dcSApple OSS Distributions	printf $compileCommand . "\n";
102*2c2f96dcSApple OSS Distributions
103*2c2f96dcSApple OSS Distributions	$jobs--;
104*2c2f96dcSApple OSS Distributions	my $pid = fork();
105*2c2f96dcSApple OSS Distributions	if ($pid == 0) {
106*2c2f96dcSApple OSS Distributions		exec($compileCommand);
107*2c2f96dcSApple OSS Distributions	}
108*2c2f96dcSApple OSS Distributions	push(@objects, $o);
109*2c2f96dcSApple OSS Distributions}
110*2c2f96dcSApple OSS Distributions
111*2c2f96dcSApple OSS Distributionswhile (wait != -1) {
112*2c2f96dcSApple OSS Distributions	if ($? != 0) {
113*2c2f96dcSApple OSS Distributions		printf "$CC exited with value %d\n", $? >> 8;
114*2c2f96dcSApple OSS Distributions		exit 1;
115*2c2f96dcSApple OSS Distributions	}
116*2c2f96dcSApple OSS Distributions}
117*2c2f96dcSApple OSS Distributions
118*2c2f96dcSApple OSS Distributionsprintf "Finished assembly, beginning link.\n";
119*2c2f96dcSApple OSS Distributions
120*2c2f96dcSApple OSS Distributions# final link
121*2c2f96dcSApple OSS Distributions
122*2c2f96dcSApple OSS Distributionsif (-f $outputFile) {
123*2c2f96dcSApple OSS Distributions	unlink($outputFile);
124*2c2f96dcSApple OSS Distributions}
125*2c2f96dcSApple OSS Distributions
126*2c2f96dcSApple OSS Distributionsmy $linkCommand = "$LIBTOOL " . join(' ', @LIBTOOLFLAGS) . " -o $outputFile " . join(' ', @objects);
127*2c2f96dcSApple OSS Distributions
128*2c2f96dcSApple OSS Distributionsprintf $linkCommand . "\n";
129*2c2f96dcSApple OSS Distributionssystem($linkCommand);
130*2c2f96dcSApple OSS Distributionsif ($? != 0) {
131*2c2f96dcSApple OSS Distributions	print "$LIBTOOL exited with value %d\n", $? >> 8;
132*2c2f96dcSApple OSS Distributions	exit 1;
133*2c2f96dcSApple OSS Distributions}
134