]>
git.cameronkatri.com Git - apple_cmds.git/blob - bootstrap_cmds/migcom.tproj/mig.sh
3 # Copyright (c) 1999-2008 Apple Inc. All rights reserved.
5 # @APPLE_LICENSE_HEADER_START@
7 # "Portions Copyright (c) 1999, 2008 Apple Inc. All Rights
8 # Reserved. This file contains Original Code and/or Modifications of
9 # Original Code as defined in and that are subject to the Apple Public
10 # Source License Version 1.0 (the 'License'). You may not use this file
11 # except in compliance with the License. Please obtain a copy of the
12 # License at http://www.apple.com/publicsource and read it before using
15 # The Original Code and all software distributed under the License are
16 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
20 # License for the specific language governing rights and limitations
23 # @APPLE_LICENSE_HEADER_END@
25 # Mach Operating System
26 # Copyright (c) 1991,1990 Carnegie Mellon University
27 # All Rights Reserved.
29 # Permission to use, copy, modify and distribute this software and its
30 # documentation is hereby granted, provided that both the copyright
31 # notice and this permission notice appear in all copies of the
32 # software, derivative works or modified versions, and any portions
33 # thereof, and that both notices appear in supporting documentation.
35 # CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
36 # CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
37 # ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 # Carnegie Mellon requests users of this software to return to
41 # Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
42 # School of Computer Science
43 # Carnegie Mellon University
44 # Pittsburgh PA 15213-3890
46 # any improvements or extensions that they make and grant Carnegie Mellon
47 # the rights to redistribute these changes.
53 local PARENT
=$(dirname "$FILE")
54 local BASE
=$(basename "$FILE")
55 pushd "$PARENT" >/dev
/null
2>&1 || return 0
58 if [ "$DIR" == "/" ]; then
66 scriptPath
=$(realpath "$0")
67 scriptRoot
=$(dirname "$scriptPath")
68 migcomPath
=$(realpath "${scriptRoot}/../libexec/migcom")
70 if [ -n "${SDKROOT}" ]; then
74 if [ -z "${MIGCC}" ]; then
75 xcrunPath
="/usr/bin/xcrun"
76 if [ -x "${xcrunPath}" ]; then
77 MIGCC
=`"${xcrunPath}" -sdk "$sdkRoot" -find cc`
79 MIGCC
=$(realpath "${scriptRoot}/cc")
84 M
=${MIGCOM-${migcomPath}}
86 if [ $# -eq 1 ] && [ "$1" = "-version" ] ; then
91 cppflags
="-D__MACH30__"
96 WORKTMP
=`/usr/bin/mktemp -d "${TMPDIR:-/tmp}/mig.XXXXXX"`
98 echo "Failure creating temporary work directory: ${WORKTMP}"
103 # parse out the arguments until we hit plain file name(s)
108 -[dtqkKQvVtTrRsSlLxXnN
] ) migflags
=( "${migflags[@]}" "$1" ); shift;;
109 -i ) sawI
=1; migflags
=( "${migflags[@]}" "$1" "$2" ); shift; shift;;
110 -user ) user
="$2"; if [ ! "${sawI-}" ]; then migflags
=( "${migflags[@]}" "$1" "$2" ); fi; shift; shift;;
111 -server ) server
="$2"; migflags
=( "${migflags[@]}" "$1" "$2" ); shift; shift;;
112 -header ) header
="$2"; migflags
=( "${migflags[@]}" "$1" "$2"); shift; shift;;
113 -sheader ) sheader
="$2"; migflags
=( "${migflags[@]}" "$1" "$2"); shift; shift;;
114 -iheader ) iheader
="$2"; migflags
=( "${migflags[@]}" "$1" "$2"); shift; shift;;
115 -dheader ) dheader
="$2"; migflags
=( "${migflags[@]}" "$1" "$2"); shift; shift;;
116 -arch ) arch
="$2"; shift; shift;;
117 -target ) target
=( "$1" "$2"); shift; shift;;
118 -maxonstack ) migflags
=( "${migflags[@]}" "$1" "$2"); shift; shift;;
119 -split ) migflags
=( "${migflags[@]}" "$1" ); shift;;
120 -novouchers ) migflags
=( "${migflags[@]}" "$1" ); shift;;
121 -MD ) sawMD
=1; cppflags
=( "${cppflags[@]}" "$1"); shift;;
123 -cc) C
="$2"; shift; shift;;
124 -migcom) M
="$2"; shift; shift;;
125 -isysroot) sdkRoot
=$(realpath "$2"); shift; shift;;
126 -* ) cppflags
=( "${cppflags[@]}" "$1"); shift;;
131 # process the rest as files
135 -[dtqkKQvVtTrRsSlLxXnN
] ) echo "warning: option \"$1\" after filename(s) ignored"; shift; continue;;
136 -i ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
137 -user ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
138 -server ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
139 -header ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
140 -sheader ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
141 -iheader ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
142 -dheader ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
143 -arch ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift ; shift; continue;;
144 -target ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift ; shift; continue;;
145 -maxonstack ) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
146 -split ) echo "warning: option \"$1\" after filename(s) ignored"; shift; continue;;
147 -novouchers ) echo "warning: option \"$1\" after filename(s) ignored"; shift; continue;;
148 -MD ) echo "warning: option \"$1\" after filename(s) ignored"; shift; continue;;
149 -cpp) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
150 -cc) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
151 -migcom) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
152 -isysroot) echo "warning: option \"$1 $2\" after filename(s) ignored"; shift; shift; continue;;
153 -* ) echo "warning: option \"$1\" after filename(s) ignored"; shift; continue;;
154 * ) file="$1"; shift;;
156 base
="$(basename "${file}" .defs)"
157 temp
="${WORKTMP}/${base}.$$"
158 sourcedir
="$(dirname "${file}")"
159 if [ -n "${sdkRoot}" ]
161 iSysRootParm
=( "-isysroot" "${sdkRoot}" )
163 if [ ! -r "${file}" ]
165 echo "error: cannot read file ${file}"
169 rm -f "${temp}.c" "${temp}.d"
170 (echo '#line 1 '\"${file}\" ; cat "${file}" ) > "${temp}.c"
171 "$C" -E -arch ${arch} "${target[@]}" "${cppflags[@]}" -I "${sourcedir}" "${iSysRootParm[@]}" "${temp}.c" | "$M" "${migflags[@]}"
174 rm -rf "${temp}.c" "${temp}.d" "${WORKTMP}"
177 if [ "${sawMD}" -a -f "${temp}.d" ]
181 rheader
="${header-${base}.h}"
182 if [ "${rheader}" != /dev
/null
]; then
183 deps
="${deps}${s}${rheader}"; s
=" "
185 ruser
="${user-${base}User.c}"
186 if [ "${ruser}" != /dev
/null
]; then
187 deps
="${deps}${s}${ruser}"; s
=" "
189 rserver
="${server-${base}Server.c}"
190 if [ "${rserver}" != /dev
/null
]; then
191 deps
="${deps}${s}${rserver}"; s
=" "
193 rsheader
="${sheader-/dev/null}"
194 if [ "${rsheader}" != /dev
/null
]; then
195 deps
="${deps}${s}${rsheader}"; s
=" "
197 riheader
="${iheader-/dev/null}"
198 if [ "${riheader}" != /dev
/null
]; then
199 deps
="${deps}${s}${riheader}"; s
=" "
201 rdheader
="${dheader-/dev/null}"
202 if [ "${rdheader}" != /dev
/null
]; then
203 deps
="${deps}${s}${rdheader}"; s
=" "
205 for target
in "${deps}"
207 sed -e 's;^'"${temp}"'.o[ ]*:;'"${target}"':;' \
208 -e 's;: '"${temp}"'.c;: '"$file"';' \
209 < "${temp}.d" > "${target}.d"
216 /bin
/rmdir "${WORKTMP}"