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