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