1# Copyright (c) 2006, 2009 Apple Inc. All rights reserved.
2#
3# @APPLE_LICENSE_HEADER_START@
4# 
5# This file contains Original Code and/or Modifications of Original Code
6# as defined in and that are subject to the Apple Public Source License
7# Version 2.0 (the 'License'). You may not use this file except in
8# compliance with the License. Please obtain a copy of the License at
9# http://www.opensource.apple.com/apsl/ and read it before using this
10# file.
11# 
12# The Original Code and all software distributed under the License are
13# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
17# Please see the License for the specific language governing rights and
18# limitations under the License.
19# 
20# @APPLE_LICENSE_HEADER_END@
21
22# This script is run from the shell script build phases in the DeviceMIG target
23
24MIGCC=`xcodebuild -sdk "${SDKROOT}" -find cc`
25MIG=`xcodebuild -sdk "${SDKROOT}" -find mig`
26
27if [ install == "$1" ]
28then
29    if [ $SCRIPT_INPUT_FILE_0 -nt $SCRIPT_OUTPUT_FILE_0 ]
30    then
31		echo Creating 32 bit Mig header for backward compatibility
32		cat > $SCRIPT_OUTPUT_FILE_0 <<- EOI_iokitmig
33			#if !defined(__LP64__)
34
35			`cat $SCRIPT_INPUT_FILE_0`
36
37			#endif /* !__LP64__ */
38		EOI_iokitmig
39    fi
40    exit
41fi
42
43# This script generates the device.defs mig interface for the IOKit.framework to the kernel
44runMig()
45{
46    local input=$1 head=$2 user=$3; shift 3
47	migargs=$@
48	set -- $ARCHS
49	MIGARCH=$1; shift
50	cmd="$MIG -cc $MIGCC -arch $MIGARCH ${migargs} -novouchers -server /dev/null -header $head -user $user $input";
51    echo $cmd
52    eval $cmd
53}
54
55# which input files is newest.
56if [ $SCRIPT_INPUT_FILE_0 -nt $SCRIPT_INPUT_FILE_1 ]
57then
58    testFile=$SCRIPT_INPUT_FILE_0
59else
60    testFile=$SCRIPT_INPUT_FILE_1
61fi
62
63ARCHS32=""
64ARCHS64=""
65for a in $ARCHS; do
66    case $a in
67	*64)
68	    ARCHS64="$ARCHS64 $a"
69	    ;;
70	*)
71	    ARCHS32="$ARCHS32 $a"
72	    ;;
73    esac
74done
75
76echo "Inferred 32-bit architectures: $ARCHS32"
77echo "Inferred 64-bit architectures: $ARCHS64"
78
79if [ $testFile -nt $SCRIPT_OUTPUT_FILE_0 -o $testFile -nt $SCRIPT_OUTPUT_FILE_1 \
80  -o $testFile -nt $SCRIPT_OUTPUT_FILE_2 -o $testFile -nt $SCRIPT_OUTPUT_FILE_3 ]
81then
82	ARCHS=${ARCHS32}
83    runMig $SCRIPT_INPUT_FILE_0 $SCRIPT_OUTPUT_FILE_0 $SCRIPT_OUTPUT_FILE_1 $OTHER_CFLAGS
84	if [ -n "${ARCHS64}" ]
85	then
86		ARCHS=${ARCHS64}
87		OTHER_CFLAGS="$OTHER_CFLAGS -D__LP64__"
88		runMig $SCRIPT_INPUT_FILE_0 $SCRIPT_OUTPUT_FILE_2 $SCRIPT_OUTPUT_FILE_3 $OTHER_CFLAGS
89	fi
90fi
91