xref: /xnu-8020.140.41/libsyscall/xcodescripts/mach_install_mig.sh (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1*27b03b36SApple OSS Distributions#!/bin/sh -xe
2*27b03b36SApple OSS Distributions#
3*27b03b36SApple OSS Distributions# Copyright (c) 2010 Apple Inc. All rights reserved.
4*27b03b36SApple OSS Distributions#
5*27b03b36SApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6*27b03b36SApple OSS Distributions#
7*27b03b36SApple OSS Distributions# This file contains Original Code and/or Modifications of Original Code
8*27b03b36SApple OSS Distributions# as defined in and that are subject to the Apple Public Source License
9*27b03b36SApple OSS Distributions# Version 2.0 (the 'License'). You may not use this file except in
10*27b03b36SApple OSS Distributions# compliance with the License. The rights granted to you under the License
11*27b03b36SApple OSS Distributions# may not be used to create, or enable the creation or redistribution of,
12*27b03b36SApple OSS Distributions# unlawful or unlicensed copies of an Apple operating system, or to
13*27b03b36SApple OSS Distributions# circumvent, violate, or enable the circumvention or violation of, any
14*27b03b36SApple OSS Distributions# terms of an Apple operating system software license agreement.
15*27b03b36SApple OSS Distributions#
16*27b03b36SApple OSS Distributions# Please obtain a copy of the License at
17*27b03b36SApple OSS Distributions# http://www.opensource.apple.com/apsl/ and read it before using this file.
18*27b03b36SApple OSS Distributions#
19*27b03b36SApple OSS Distributions# The Original Code and all software distributed under the License are
20*27b03b36SApple OSS Distributions# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21*27b03b36SApple OSS Distributions# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22*27b03b36SApple OSS Distributions# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23*27b03b36SApple OSS Distributions# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24*27b03b36SApple OSS Distributions# Please see the License for the specific language governing rights and
25*27b03b36SApple OSS Distributions# limitations under the License.
26*27b03b36SApple OSS Distributions#
27*27b03b36SApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28*27b03b36SApple OSS Distributions#
29*27b03b36SApple OSS Distributions
30*27b03b36SApple OSS Distributions# build inside OBJROOT
31*27b03b36SApple OSS Distributionscd $OBJROOT
32*27b03b36SApple OSS Distributions
33*27b03b36SApple OSS DistributionsMIG=`xcrun -sdk "$SDKROOT" -find mig`
34*27b03b36SApple OSS DistributionsMIGCC=`xcrun -sdk "$SDKROOT" -find cc`
35*27b03b36SApple OSS Distributionsexport MIGCC
36*27b03b36SApple OSS Distributions[ -n "$DRIVERKITROOT" ] && MIG_DRIVERKIT_DEFINES="-DDRIVERKIT"
37*27b03b36SApple OSS DistributionsMIG_DEFINES="-DLIBSYSCALL_INTERFACE $MIG_DRIVERKIT_DEFINES"
38*27b03b36SApple OSS DistributionsMIG_PRIVATE_DEFINES="-DPRIVATE"
39*27b03b36SApple OSS DistributionsMIG_HEADER_OBJ="$OBJROOT/mig_hdr/include/mach"
40*27b03b36SApple OSS DistributionsMIG_HEADER_DST="$BUILT_PRODUCTS_DIR/mig_hdr/include/mach"
41*27b03b36SApple OSS DistributionsMIG_PRIVATE_HEADER_DST="$BUILT_PRODUCTS_DIR/mig_hdr/local/include/mach"
42*27b03b36SApple OSS DistributionsSERVER_HEADER_DST="$BUILT_PRODUCTS_DIR/mig_hdr/include/servers"
43*27b03b36SApple OSS DistributionsMACH_HEADER_DST="$BUILT_PRODUCTS_DIR/mig_hdr/include/mach"
44*27b03b36SApple OSS DistributionsMACH_PRIVATE_HEADER_DST="$BUILT_PRODUCTS_DIR/mig_hdr/local/include/mach"
45*27b03b36SApple OSS DistributionsMIG_INTERNAL_HEADER_DST="$BUILT_PRODUCTS_DIR/internal_hdr/include/mach"
46*27b03b36SApple OSS DistributionsMIG_INCFLAGS="-I${SRCROOT}/../osfmk"
47*27b03b36SApple OSS DistributionsSRC="$SRCROOT/mach"
48*27b03b36SApple OSS DistributionsFILTER_MIG="$SRCROOT/xcodescripts/filter_mig.awk"
49*27b03b36SApple OSS Distributions
50*27b03b36SApple OSS Distributions# MACHINE_ARCH *really* needs to be a 32-bit arch to generate vm_map_internal.h correctly, even if there are no 32-bit targets.
51*27b03b36SApple OSS Distributions# thread_state_t *really* needs to pick up arm64 over intel because it has a larger struct type.
52*27b03b36SApple OSS Distributionscase "$ARCHS" in
53*27b03b36SApple OSS Distributions*arm64*)
54*27b03b36SApple OSS Distributions    MACHINE_ARCH=armv7
55*27b03b36SApple OSS Distributions    ;;
56*27b03b36SApple OSS Distributions*x86_64*)
57*27b03b36SApple OSS Distributions    MACHINE_ARCH=i386
58*27b03b36SApple OSS Distributions    ;;
59*27b03b36SApple OSS Distributions*)
60*27b03b36SApple OSS Distributions    MACHINE_ARCH=`echo $ARCHS | cut -d' ' -f 1`
61*27b03b36SApple OSS Distributions    ;;
62*27b03b36SApple OSS Distributionsesac
63*27b03b36SApple OSS Distributions
64*27b03b36SApple OSS DistributionsASROOT=""
65*27b03b36SApple OSS Distributionsif [ `whoami` = "root" ]; then
66*27b03b36SApple OSS Distributions	ASROOT="-o 0"
67*27b03b36SApple OSS Distributionsfi
68*27b03b36SApple OSS Distributions
69*27b03b36SApple OSS Distributions# These are covered by ../../osfmk/mach/mach.modulemap.
70*27b03b36SApple OSS DistributionsMIGS="clock.defs
71*27b03b36SApple OSS Distributions	clock_priv.defs
72*27b03b36SApple OSS Distributions	clock_reply.defs
73*27b03b36SApple OSS Distributions	exc.defs
74*27b03b36SApple OSS Distributions	host_priv.defs
75*27b03b36SApple OSS Distributions	host_security.defs
76*27b03b36SApple OSS Distributions	lock_set.defs
77*27b03b36SApple OSS Distributions	mach_eventlink.defs
78*27b03b36SApple OSS Distributions	mach_host.defs
79*27b03b36SApple OSS Distributions	mach_port.defs
80*27b03b36SApple OSS Distributions	mach_voucher.defs
81*27b03b36SApple OSS Distributions	memory_entry.defs
82*27b03b36SApple OSS Distributions	processor.defs
83*27b03b36SApple OSS Distributions	processor_set.defs
84*27b03b36SApple OSS Distributions	task.defs
85*27b03b36SApple OSS Distributions	thread_act.defs
86*27b03b36SApple OSS Distributions	vm_map.defs"
87*27b03b36SApple OSS Distributions
88*27b03b36SApple OSS Distributions# These are covered by ../../osfmk/mach/mach_private.modulemap.
89*27b03b36SApple OSS DistributionsMIGS_PRIVATE=""
90*27b03b36SApple OSS Distributions
91*27b03b36SApple OSS DistributionsMIGS_DUAL_PUBLIC_PRIVATE=""
92*27b03b36SApple OSS Distributions
93*27b03b36SApple OSS DistributionsMIGS_PRIVATE_PLATFORMS="iphoneos iphonesimulator tvos tvsimulator appletvos appletvsimulator watchos watchsimulator bridgeos bridgesimulator iphoneosnano iphonenanosimulator"
94*27b03b36SApple OSS Distributions
95*27b03b36SApple OSS Distributionsif ( echo $MIGS_PRIVATE_PLATFORMS | grep -wFq "${PLATFORM_NAME}" )
96*27b03b36SApple OSS Distributionsthen
97*27b03b36SApple OSS Distributions	MIGS_PRIVATE="mach_vm.defs"
98*27b03b36SApple OSS Distributionselse
99*27b03b36SApple OSS Distributions	MIGS="$MIGS mach_vm.defs"
100*27b03b36SApple OSS Distributionsfi
101*27b03b36SApple OSS Distributions
102*27b03b36SApple OSS DistributionsMIGS_INTERNAL="mach_port.defs
103*27b03b36SApple OSS Distributions	mach_vm.defs
104*27b03b36SApple OSS Distributions	task.defs
105*27b03b36SApple OSS Distributions	thread_act.defs
106*27b03b36SApple OSS Distributions	vm_map.defs"
107*27b03b36SApple OSS Distributions
108*27b03b36SApple OSS DistributionsSERVER_HDRS="key_defs.h
109*27b03b36SApple OSS Distributions	ls_defs.h
110*27b03b36SApple OSS Distributions	netname_defs.h
111*27b03b36SApple OSS Distributions	nm_defs.h"
112*27b03b36SApple OSS Distributions
113*27b03b36SApple OSS Distributions# These are covered by ../../osfmk/mach/mach.modulemap.
114*27b03b36SApple OSS DistributionsMACH_HDRS="mach.h
115*27b03b36SApple OSS Distributions	mach_error.h
116*27b03b36SApple OSS Distributions	mach_init.h
117*27b03b36SApple OSS Distributions	mach_interface.h
118*27b03b36SApple OSS Distributions	mach_right.h
119*27b03b36SApple OSS Distributions	port_obj.h
120*27b03b36SApple OSS Distributions	sync.h
121*27b03b36SApple OSS Distributions	vm_task.h
122*27b03b36SApple OSS Distributions	vm_page_size.h
123*27b03b36SApple OSS Distributions	thread_state.h"
124*27b03b36SApple OSS Distributions
125*27b03b36SApple OSS Distributions# These are covered by ../../osfmk/mach/mach_private.modulemap.
126*27b03b36SApple OSS DistributionsMACH_PRIVATE_HDRS="port_descriptions.h
127*27b03b36SApple OSS Distributions	mach_right_private.h
128*27b03b36SApple OSS Distributions	mach_sync_ipc.h"
129*27b03b36SApple OSS Distributions
130*27b03b36SApple OSS DistributionsMIG_FILTER_TEMPLATE="add_attributes_to_mig.txt"
131*27b03b36SApple OSS Distributions
132*27b03b36SApple OSS Distributions# install /usr/include/server headers
133*27b03b36SApple OSS Distributionsmkdir -p $SERVER_HEADER_DST
134*27b03b36SApple OSS Distributionsfor hdr in $SERVER_HDRS; do
135*27b03b36SApple OSS Distributions	install $ASROOT -c -m 444 $SRC/servers/$hdr $SERVER_HEADER_DST
136*27b03b36SApple OSS Distributionsdone
137*27b03b36SApple OSS Distributions
138*27b03b36SApple OSS Distributions# install /usr/include/mach headers
139*27b03b36SApple OSS Distributionsmkdir -p $MACH_HEADER_DST
140*27b03b36SApple OSS Distributionsfor hdr in $MACH_HDRS; do
141*27b03b36SApple OSS Distributions	install $ASROOT -c -m 444 $SRC/mach/$hdr $MACH_HEADER_DST
142*27b03b36SApple OSS Distributionsdone
143*27b03b36SApple OSS Distributions
144*27b03b36SApple OSS Distributions# install /usr/local/include/mach headers
145*27b03b36SApple OSS Distributionsmkdir -p $MACH_PRIVATE_HEADER_DST
146*27b03b36SApple OSS Distributionsfor hdr in $MACH_PRIVATE_HDRS; do
147*27b03b36SApple OSS Distributions	install $ASROOT -c -m 444 $SRC/mach/$hdr $MACH_PRIVATE_HEADER_DST
148*27b03b36SApple OSS Distributionsdone
149*27b03b36SApple OSS Distributions
150*27b03b36SApple OSS Distributions# special case because we only have one to do here
151*27b03b36SApple OSS Distributions$MIG -novouchers -arch $MACHINE_ARCH -cc $MIGCC -header "$SERVER_HEADER_DST/netname.h" $MIG_INCFLAGS $SRC/servers/netname.defs
152*27b03b36SApple OSS Distributions
153*27b03b36SApple OSS Distributions# install /usr/include/mach mig headers
154*27b03b36SApple OSS Distributions
155*27b03b36SApple OSS Distributionsmkdir -p $MIG_HEADER_DST
156*27b03b36SApple OSS Distributionsmkdir -p $MIG_HEADER_OBJ
157*27b03b36SApple OSS Distributions
158*27b03b36SApple OSS Distributionsfor mig in $MIGS $MIGS_DUAL_PUBLIC_PRIVATE; do
159*27b03b36SApple OSS Distributions	MIG_NAME=`basename $mig .defs`
160*27b03b36SApple OSS Distributions	$MIG -novouchers -arch $MACHINE_ARCH -cc $MIGCC -header "$MIG_HEADER_OBJ/$MIG_NAME.h" $MIG_DEFINES $MIG_INCFLAGS $SRC/$mig
161*27b03b36SApple OSS Distributions        $FILTER_MIG $SRC/$MIG_FILTER_TEMPLATE $MIG_HEADER_OBJ/$MIG_NAME.h > $MIG_HEADER_OBJ/$MIG_NAME.tmp.h
162*27b03b36SApple OSS Distributions        mv $MIG_HEADER_OBJ/$MIG_NAME.tmp.h $MIG_HEADER_OBJ/$MIG_NAME.h
163*27b03b36SApple OSS Distributions	install $ASROOT -c -m 444 $MIG_HEADER_OBJ/$MIG_NAME.h $MIG_HEADER_DST/$MIG_NAME.h
164*27b03b36SApple OSS Distributionsdone
165*27b03b36SApple OSS Distributions
166*27b03b36SApple OSS Distributionsmkdir -p $MIG_PRIVATE_HEADER_DST
167*27b03b36SApple OSS Distributions
168*27b03b36SApple OSS Distributionsfor mig in $MIGS_PRIVATE $MIGS_DUAL_PUBLIC_PRIVATE; do
169*27b03b36SApple OSS Distributions	MIG_NAME=`basename $mig .defs`
170*27b03b36SApple OSS Distributions	$MIG -novouchers -arch $MACHINE_ARCH -cc $MIGCC -header "$MIG_PRIVATE_HEADER_DST/$MIG_NAME.h" $MIG_DEFINES $MIG_PRIVATE_DEFINES $MIG_INCFLAGS $SRC/$mig
171*27b03b36SApple OSS Distributions	if [ ! -e "$MIG_HEADER_DST/$MIG_NAME.h" ]; then
172*27b03b36SApple OSS Distributions		echo "#error $MIG_NAME.h unsupported." > "$MIG_HEADER_DST/$MIG_NAME.h"
173*27b03b36SApple OSS Distributions	fi
174*27b03b36SApple OSS Distributionsdone
175*27b03b36SApple OSS Distributions
176*27b03b36SApple OSS Distributions
177*27b03b36SApple OSS Distributions# special headers used just for building Libsyscall
178*27b03b36SApple OSS Distributions# Note: not including -DLIBSYSCALL_INTERFACE to mig so we'll get the proper
179*27b03b36SApple OSS Distributions#  'internal' version of the headers being built
180*27b03b36SApple OSS Distributions
181*27b03b36SApple OSS Distributionsmkdir -p $MIG_INTERNAL_HEADER_DST
182*27b03b36SApple OSS Distributions
183*27b03b36SApple OSS Distributionsfor mig in $MIGS_INTERNAL; do
184*27b03b36SApple OSS Distributions	MIG_NAME=`basename $mig .defs`
185*27b03b36SApple OSS Distributions	$MIG -novouchers -arch $MACHINE_ARCH -cc $MIGCC -header "$MIG_INTERNAL_HEADER_DST/${MIG_NAME}_internal.h" $MIG_INCFLAGS $SRC/$mig
186*27b03b36SApple OSS Distributionsdone
187*27b03b36SApple OSS Distributions
188