WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / make / xcodemake
blobf3aa4e6aea785e8222d10ce1a5f84998072bdcd7
1 #!/bin/bash
4 set -e
6 ## This script is initiated by either xcodebuild or Xcode.app.
7 ##
8 ## We must guarantee no jobserver is passed through since file-descriptors are
9 ## clobbered by Xcode. If this is not done then make allows unlimited jobs.
11 MAKEFLAGS=
12 MFLAGS=
14 ## validate environment
15 case "$EXTERNAL_DRIVER" in
16 bootstrap) ;; ## bootstrapping from terminal
17 terminal) ;; ## building from terminal
18 xcode) ;; ## building from Xcode.app
20 echo "ERROR: unexpected value for EXTERNAL_DRIVER: $EXTERNAL_DRIVER"
21 exit 1
23 esac
25 ## validate environment
26 for name in EXTERNAL_BUILD EXTERNAL_JOBS EXTERNAL_SRC; do
27 eval v="\$$name"
28 if [ -z "$v" ]; then
29 echo "ERROR: missing value for $name"
30 exit 1
32 done
34 ## validate environment
35 archcount=`echo $ARCHS | awk '{ print NF }'`
36 if [ "$archcount" -ne 1 ]; then
37 echo "*********************************************************************"
38 echo "***"
39 echo "*** ERROR: multiple architectures: $ARCHS"
40 echo "***"
41 echo "*** This build system does not support more than one (1)"
42 echo "*** simultaneous architecture setting."
43 echo "***"
44 echo "*********************************************************************"
45 exit 1
48 exit_post_log=0
50 ## compute goals; these correlate with TARGET_NAME and ACTION from Xcode
51 spec="$TARGET_NAME:$ACTION"
52 echo "target specification: $spec"
53 case "$spec" in
54 external:clean)
55 if [ "$EXTERNAL_DRIVER" == "xcode" ]; then
56 ## driving build from Xcode.app do pristine clean
57 if [ -z "$EXTERNAL_BUILD" ]; then
58 echo "ERROR: unsafe rm -fr would result because EXTERNAL_BUILD is not defined"
59 exit 1
61 if [ -d "$EXTERNAL_BUILD" ]; then
62 cmd="/bin/rm -fr $EXTERNAL_BUILD/*"
63 echo "$cmd"
64 $cmd
65 [ $? -ne 0 ] && exit 1
66 exit_post_log=1
67 else
68 echo "already clean"
70 else
71 ## driving build from xcodebuild do xclean, preserving configuration
72 goals=xclean
75 external:*)
76 if [ -z "$EXTERNAL_GOALS" ]; then
77 goals=build
78 else
79 goals="$EXTERNAL_GOALS"
83 echo "ERROR: unexpected env specification: $spec"
84 exit 1
86 esac
88 ## compute if re/configure necessary
89 if [ ! -f $EXTERNAL_BUILD/GNUmakefile ]; then
90 reconfigure="no configuration present"
91 elif [ $EXTERNAL_SRC/make/configure.py -nt $EXTERNAL_BUILD/GNUmakefile ]; then
92 reconfigure="configure script was updated"
93 elif [ $EXTERNAL_DRIVER == "bootstrap" ]; then
94 reconfigure="driver bootstrap"
95 else
96 reconfigure=
99 ## perform re/configure
100 if [ -n "$reconfigure" ]; then
101 echo "reconfiguring ($reconfigure)"
103 if [ "$EXTERNAL_DRIVER" == "bootstrap" ]; then
104 driver="--xcode-driver=terminal"
105 else
106 driver="--xcode-driver=$EXTERNAL_DRIVER"
109 ## determine which compiler to use based on Xcode environment (project).
110 case "$GCC_VERSION" in
111 com.apple.compilers.llvmgcc42)
112 gcc="--gcc=`$DEVELOPER_BIN_DIR/xcodebuild -find-executable llvm-gcc-4.2`"
114 com.apple.compilers.llvm.clang.1_0)
115 gcc="--gcc=`$DEVELOPER_BIN_DIR/xcodebuild -find-executable clang`"
118 echo "*********************************************************************"
119 echo "***"
120 echo "*** ERROR: unexpected value for GCC_VERSION: $GCC_VERSION"
121 echo "***"
122 echo "*********************************************************************"
123 exit 1
125 esac
127 if [ -n "$ARCHS" ]; then
128 arch="--arch=$ARCHS"
129 else
130 arch=
133 case "$CONFIGURATION" in
134 debug*)
135 debug="--debug=std --optimize=none"
137 release*|*)
138 debug=
140 esac
142 if [ -n "$SDKROOT" ]; then
143 sysroot="--sysroot=$SDKROOT"
144 else
145 sysroot=
148 if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
149 minver="--minver=$MACOSX_DEPLOYMENT_TARGET"
150 else
151 minver=
154 ## pickup user setting from Xcode IDE and avoid recursion
155 if [ -n "$EXTERNAL_CONFIGURE" ]; then
156 extconf="$EXTERNAL_CONFIGURE"
157 else
158 extconf=
160 EXTERNAL_CONFIGURE=
162 ## invoke configure with (hidden) option which indicates conf performed by xcode
163 (set -ex; $EXTERNAL_SRC/configure --force \
164 $EXTERNAL_CONF_ARGS \
165 --build="$EXTERNAL_BUILD" \
166 $driver \
167 --xcode-symroot="$SYMROOT" \
168 --xcode-config="$EXTERNAL_XCCONFIG" \
169 $gcc $arch $debug $sysroot $minver $extconf)
170 [ $? -ne 0 ] && exit 1
173 ## log environment as provided by Xcode
174 logdir=$EXTERNAL_BUILD/log
175 if [ ! -d $logdir ]; then
176 mkdir -p $logdir
178 env | sort > $logdir/xcodemake.env.txt
180 [ $exit_post_log -ne 0 ] && exit 0
182 ## safeguard against passing blank value which would result in unlimited jobs
183 if [ -z "$EXTERNAL_JOBS" ]; then
184 jobs=
185 elif [ "$EXTERNAL_JOBS" == "auto" ]; then
186 jobs=--jobs=`sysctl -n hw.activecpu`
187 else
188 jobs=--jobs=$EXTERNAL_JOBS
191 ## when driving from terminal; ensure $SYMROOT/external/ exists relative to SYMROOT
192 if [ "$EXTERNAL_DRIVER" == "terminal" -a ! -e "$SYMROOT/external" ]; then
193 ln -s "$EXTERNAL_BUILD" "$SYMROOT/external"
196 ## pull the trigger
197 ## must set XCODE.driver to prevent inifinite recursion
198 set -x
199 exec make -C $EXTERNAL_BUILD XCODE.driver=xcodemake $jobs $goals $EXTERNAL_VARS