]> git.cameronkatri.com Git - apple_cmds.git/blob - bootstrap_cmds/migcom.tproj/mig.sh
text_cmds: All done
[apple_cmds.git] / bootstrap_cmds / migcom.tproj / mig.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 1999-2008 Apple Inc. All rights reserved.
4 #
5 # @APPLE_LICENSE_HEADER_START@
6 #
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
13 # this file.
14 #
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
21 # under the License."
22 #
23 # @APPLE_LICENSE_HEADER_END@
24 #
25 # Mach Operating System
26 # Copyright (c) 1991,1990 Carnegie Mellon University
27 # All Rights Reserved.
28 #
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.
34 #
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.
38 #
39 # Carnegie Mellon requests users of this software to return to
40 #
41 # Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
42 # School of Computer Science
43 # Carnegie Mellon University
44 # Pittsburgh PA 15213-3890
45 #
46 # any improvements or extensions that they make and grant Carnegie Mellon
47 # the rights to redistribute these changes.
48 #
49
50 realpath()
51 {
52 local FILE="$1"
53 local PARENT=$(dirname "$FILE")
54 local BASE=$(basename "$FILE")
55 pushd "$PARENT" >/dev/null 2>&1 || return 0
56 local DIR=$(pwd -P)
57 popd >/dev/null
58 if [ "$DIR" == "/" ]; then
59 echo "/$BASE"
60 else
61 echo "$DIR/$BASE"
62 fi
63 return 1
64 }
65
66 scriptPath=$(realpath "$0")
67 scriptRoot=$(dirname "$scriptPath")
68 migcomPath=$(realpath "${scriptRoot}/../libexec/migcom")
69
70 if [ -n "${SDKROOT}" ]; then
71 sdkRoot="${SDKROOT}";
72 fi
73
74 if [ -z "${MIGCC}" ]; then
75 xcrunPath="/usr/bin/xcrun"
76 if [ -x "${xcrunPath}" ]; then
77 MIGCC=`"${xcrunPath}" -sdk "$sdkRoot" -find cc`
78 else
79 MIGCC=$(realpath "${scriptRoot}/cc")
80 fi
81 fi
82
83 C=${MIGCC}
84 M=${MIGCOM-${migcomPath}}
85
86 if [ $# -eq 1 ] && [ "$1" = "-version" ] ; then
87 "$M" "$@"
88 exit $?
89 fi
90
91 cppflags="-D__MACH30__"
92
93 files=
94 arch=`/usr/bin/arch`
95
96 WORKTMP=`/usr/bin/mktemp -d "${TMPDIR:-/tmp}/mig.XXXXXX"`
97 if [ $? -ne 0 ]; then
98 echo "Failure creating temporary work directory: ${WORKTMP}"
99 echo "Exiting..."
100 exit 1
101 fi
102
103 # parse out the arguments until we hit plain file name(s)
104
105 until [ $# -eq 0 ]
106 do
107 case "$1" in
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;;
122 -cpp) shift; 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;;
127 * ) break;;
128 esac
129 done
130
131 # process the rest as files
132 until [ $# -eq 0 ]
133 do
134 case "$1" in
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;;
155 esac
156 base="$(basename "${file}" .defs)"
157 temp="${WORKTMP}/${base}.$$"
158 sourcedir="$(dirname "${file}")"
159 if [ -n "${sdkRoot}" ]
160 then
161 iSysRootParm=( "-isysroot" "${sdkRoot}" )
162 fi
163 if [ ! -r "${file}" ]
164 then
165 echo "error: cannot read file ${file}"
166 rm -rf ${WORKTMP}
167 exit 1
168 fi
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[@]}"
172 if [ $? -ne 0 ]
173 then
174 rm -rf "${temp}.c" "${temp}.d" "${WORKTMP}"
175 exit 1
176 fi
177 if [ "${sawMD}" -a -f "${temp}.d" ]
178 then
179 deps=
180 s=
181 rheader="${header-${base}.h}"
182 if [ "${rheader}" != /dev/null ]; then
183 deps="${deps}${s}${rheader}"; s=" "
184 fi
185 ruser="${user-${base}User.c}"
186 if [ "${ruser}" != /dev/null ]; then
187 deps="${deps}${s}${ruser}"; s=" "
188 fi
189 rserver="${server-${base}Server.c}"
190 if [ "${rserver}" != /dev/null ]; then
191 deps="${deps}${s}${rserver}"; s=" "
192 fi
193 rsheader="${sheader-/dev/null}"
194 if [ "${rsheader}" != /dev/null ]; then
195 deps="${deps}${s}${rsheader}"; s=" "
196 fi
197 riheader="${iheader-/dev/null}"
198 if [ "${riheader}" != /dev/null ]; then
199 deps="${deps}${s}${riheader}"; s=" "
200 fi
201 rdheader="${dheader-/dev/null}"
202 if [ "${rdheader}" != /dev/null ]; then
203 deps="${deps}${s}${rdheader}"; s=" "
204 fi
205 for target in "${deps}"
206 do
207 sed -e 's;^'"${temp}"'.o[ ]*:;'"${target}"':;' \
208 -e 's;: '"${temp}"'.c;: '"$file"';' \
209 < "${temp}.d" > "${target}.d"
210 done
211 rm -f "${temp}.d"
212 fi
213 rm -f "${temp}.c"
214 done
215
216 /bin/rmdir "${WORKTMP}"
217 exit 0
218