Check-in [825c8fd29a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added start of LLVM/Clang support (which as of version 3.1 does not produce any working compilers as far as I can tell)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | llvm
Files: files | file ages | folders
SHA1:825c8fd29a37ebfe334d5f516de506920876388c
User & Date: rkeene 2012-09-03 18:44:27
Context
2013-08-06
19:58
Attempted to update to latest version of LLVM Leaf check-in: 03a0bbd8b0 user: rkeene tags: llvm
2012-09-03
18:44
Added start of LLVM/Clang support (which as of version 3.1 does not produce any working compilers as far as I can tell) check-in: 825c8fd29a user: rkeene tags: llvm
2012-09-02
19:24
Create new branch named "llvm" check-in: e141bd787f user: rkeene tags: llvm
Changes

Changes to build-cc.

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206



207
208
209
210
211
212
213
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358

359
360
361
362


363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421

422
423
424

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
## Load configuration file
if [ -f "build-cc.conf" ]; then
	. "build-cc.conf"
fi

# Tool versions
BINUTILS_VERS='2.22'
GCC_VERS='4.6.3'
GMP_VERS='5.0.2'
MPFR_VERS='3.0.1'
MPC_VERS='0.9'

# Start of script
## Initialize default values
use_multilib='1'
use_gnu_ld='1'
use_gnu_as='1'

................................................................................

## URLs
### Binutils
BINUTILS_URL="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERS}.tar.bz2"
BINUTILS_TARBALL="src/binutils-${BINUTILS_VERS}.tar.bz2"
BINUTILS_DIR="binutils-${BINUTILS_VERS}"

### GCC
GCC_URL="http://mirrors.kernel.org/gnu/gcc/gcc-${GCC_VERS}/gcc-${GCC_VERS}.tar.bz2"
GCC_TARBALL="src/gcc-${GCC_VERS}.tar.bz2"
GCC_DIR="gcc-${GCC_VERS}"

### GMP
GMP_URL="http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERS}.tar.bz2"
GMP_TARBALL="src/gmp-${GMP_VERS}.tar.bz2"
GMP_DIR="gmp-${GMP_VERS}"

### MPFR
MPFR_URL="http://www.mpfr.org/mpfr-${MPFR_VERS}/mpfr-${MPFR_VERS}.tar.bz2"
MPFR_TARBALL="src/mpfr-${MPFR_VERS}.tar.bz2"
MPFR_DIR="mpfr-${MPFR_VERS}"

### MPC
MPC_URL="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERS}.tar.gz"
MPC_TARBALL="src/mpc-${MPC_VERS}.tar.gz"
MPC_DIR="mpc-${MPC_VERS}"

## Clean-up
if [ "$1" = "clean" -o "$1" = "distclean" ]; then
	rm -rf "${BINUTILS_DIR}" "${GCC_DIR}" "${GMP_DIR}" "${MPFR_DIR}" "${MPC_DIR}"

	for platform in "${platforms[@]}"; do
		rm -rf "gcc-${platform}"
		rm -rf "binutils-${platform}"
	done

	for appscript in scripts/* scripts/pre/* scripts/post/*; do
		"${appscript}" "clean" >/dev/null 2>/dev/null
	done

	if [ "$1" = "clean" ]; then
		exit 0
	fi
fi

if [ "$1" = "distclean" ]; then
	rm -f "${BINUTILS_TARBALL}" "${GCC_TARBALL}" "${GMP_TARBALL}" "${MPFR_TARBALL}" "${MPC_TARBALL}"

	for appscript in scripts/* scripts/pre/* scripts/post/*; do
		"${appscript}" "distclean" >/dev/null 2>/dev/null
	done

	rmdir src >/dev/null 2>/dev/null

................................................................................
CCNAME="$1"
CCDIR="${CCROOT}/${CCNAME}"

## Determine attributes for this compiler
### Per CPU
case "${CCNAME}" in
	hppa64-*|hppa1*-)
		BUILD_CC_GCC_CONFIGURE_EXTRA="${BUILD_CC_GCC_CONFIGURE_EXTRA} --disable-libquadmath"
		;;
esac

### Per OS
case "${CCNAME}" in
	*-hpux*)
		#### Default to disabling multilib, will be re-enabled by target if supported
		use_multilib='0'
		;;
	*-freebsd*)
		#### Default to disabling multilib, will be re-enabled by target if supported
		use_multilib='0'
		;;
	*-darwin*)
		use_gnu_ld='0'
		use_gnu_as='0'
		use_ld64='0'

		if echo "${CCNAME}" | egrep '^(x86_64|ppc64)-' >/dev/null; then
			use_ld64='1'
		fi

		if [ "${use_ld64}" = '0' ]; then
			ldcmd='ld'
		else
			ldcmd='ld64'
		fi

		BUILD_CC_GCC_CONFIGURE_EXTRA="${BUILD_CC_GCC_CONFIGURE_EXTRA} --with-ld=${CCDIR}/${CCNAME}/bin/${ldcmd} --with-as=${CCDIR}/${CCNAME}/bin/as"

		unset ldcmd
		;;
esac

if [ "${use_gnu_ld}" = "1" ]; then
	BUILD_CC_GCC_CONFIGURE_EXTRA="${BUILD_CC_GCC_CONFIGURE_EXTRA} --with-gnu-ld"
fi

if [ "${use_gnu_as}" = "1" ]; then
	BUILD_CC_GCC_CONFIGURE_EXTRA="${BUILD_CC_GCC_CONFIGURE_EXTRA} --with-gnu-as"



fi

## Determine platform file tarball
PLATFORM_TARBALL="${BUILD_CC_PLATFORMDIR}/${CCNAME}-platform.tar.bz2"
ADDONS_TARBALL="${BUILD_CC_PLATFORMDIR}/platform/${CCNAME}-addons.tar.bz2"

### Install platform files (needed for libgcc)
................................................................................
### Set use_multilib authoritatively if possible
if [ -f "${CCDIR}/${CCNAME}/multilib" ]; then
	use_multilib="$(cat "${CCDIR}/${CCNAME}/multilib")"
	rm -f "${CCDIR}/${CCNAME}/multilib"
fi

### Set C compiler flags from tarball
if [ -f "${CCDIR}/${CCNAME}/BUILD_CC_GCC_CONFIGURE_EXTRA" ]; then
	add="$(cat "${CCDIR}/${CCNAME}/BUILD_CC_GCC_CONFIGURE_EXTRA")"

	#### Ensure these flags aren't malicious
	##### XXX: TODO: Build the extra flags as an array for safety
	if ! echo "${add}" | grep '[;|<>]' >/dev/null; then
		BUILD_CC_GCC_CONFIGURE_EXTRA="${BUILD_CC_GCC_CONFIGURE_EXTRA} ${add}"
	fi
	
	rm -f "${CCDIR}/${CCNAME}/BUILD_CC_GCC_CONFIGURE_EXTRA"
fi

## Determine stage of build process
STAGE="$2"

### If we have a platform tarball and a stage has not been specified, assume we are at stage 2
if [ -z "${STAGE}" ]; then
................................................................................

	${MAKE} || exit 1

	${MAKE} install || exit 1
) || exit 1
rm -rf "binutils-${CCNAME}"

## Compile C compiler (GCC) if needed
### Prepare GCC fix-ups (stage1)
if [ "${STAGE}" = "stage1" ]; then
	### XXX: GCC produces a broken compiler -- compiles require libgcc_eh.a, which it doesn't emit
	libgcceha="${CCDIR}/lib/gcc/${CCNAME}/${GCC_VERS}/libgcc_eh.a"
	if [ -h "${libgcceha}" ]; then
		rm -f "${libgcceha}"
	fi
fi

### If multilib was not requested, disable it
if [ "${use_multilib}" = "0" ]; then
	BUILD_CC_GCC_CONFIGURE_EXTRA="--disable-multilib ${BUILD_CC_GCC_CONFIGURE_EXTRA}"

fi

## Compile
(
	### Determine if compilation is needed
	if [ -f "${CCDIR}/bin/${CCNAME}-gcc" ]; then
		if find "${CCDIR}/lib/gcc" -type f -name 'libgcc.a' | grep libgcc >/dev/null; then
................................................................................
				if find "${CCDIR}" -type f -name 'libgcc_s.*' | grep libgcc_s >/dev/null; then
					exit 2
				fi
			fi
		fi
	fi

	if [ ! -d "${GCC_DIR}" ]; then
		# Download sources required
		download "${GCC_URL}" "${GCC_TARBALL}"
		download "${GMP_URL}" "${GMP_TARBALL}"
		download "${MPFR_URL}" "${MPFR_TARBALL}"
		download "${MPC_URL}" "${MPC_TARBALL}"

		# Extract sources
		bzip2 -dc "${GCC_TARBALL}" | "${TAR:-tar}" -xf -
		bzip2 -dc "${GMP_TARBALL}" | "${TAR:-tar}" -xf -
		bzip2 -dc "${MPFR_TARBALL}" | "${TAR:-tar}" -xf -
		gzip -dc "${MPC_TARBALL}" | "${TAR:-tar}" -xf -

		# Arroung sources as needed
		rm -rf "${GCC_DIR}/gmp"
		rm -rf "${GCC_DIR}/mpfr"
		rm -rf "${GCC_DIR}/mpc"


		mv "${GMP_DIR}" "${GCC_DIR}/gmp"
		mv "${MPFR_DIR}" "${GCC_DIR}/mpfr"
		mv "${MPC_DIR}" "${GCC_DIR}/mpc"



		# Apply patches
		## Apply patch files
		for patchfile in "$(pwd)/patches/gcc"/*.diff; do
			patchfile_checkscript="$(echo "${patchfile}" | sed 's@\.diff$@.sh@')"
			if [ ! -f "${patchfile}" ]; then
				continue
			fi

			if [ -x "${patchfile_checkscript}" ]; then
				if ! "${patchfile_checkscript}" "${GCC_VERS}"; then
					continue
				fi
			fi

			(
				echo " * Applying patch ${patchfile}"

				cd "${GCC_DIR}" || exit 1

				"${PATCH:-patch}" -p1 < "${patchfile}" || exit 1
			) || exit 1
		done

		## Apply patch scripts
		export GCC_DIR
		for gccscript in scripts/gcc/*; do
			if [ ! -x "${gccscript}" ]; then
				continue
			fi

			sourcefile="${TMPDIR:-/tmp}/build-cc-sourcefile-$$${RANDOM}${RANDOM}${RANDOM}"
			rm -f "${sourcefile}"

			"${gccscript}" "${CCNAME}" "${CCDIR}" "${CCDIR}/${CCNAME}" "${STAGE}" "${sourcefile}" || exit 1

			if [ -f "${sourcefile}" ]; then
				. "${sourcefile}"
				rm -f "${sourcefile}"
			fi
		done
	fi

	# Build GCC with shared object support
	## Create build directory
	rm -rf "gcc-${CCNAME}"
	mkdir "gcc-${CCNAME}"
	cd "gcc-${CCNAME}" || exit -1

	## Unset "CPPFLAGS" since GOMP/OpenMP does not properly sanitize it
	unset CPPFLAGS


	## Build GCC
	if [ "${STAGE}" = "stage1" ]; then
		### Stage 1 -- just GCC and libgcc, no more will build until we get some headers
		"../${GCC_DIR}/configure" --target="${CCNAME}" --prefix="${CCDIR}" --disable-nls --enable-languages='c' --without-headers --disable-threads --disable-shared --with-newlib --with-sysroot="${CCDIR}/${CCNAME}" --with-build-sysroot="${CCDIR}/${CCNAME}" ${BUILD_CC_GCC_CONFIGURE_EXTRA}

		${MAKE} all-gcc all-target-libgcc || exit 1
		${MAKE} install-gcc install-target-libgcc || exit 1

	else
		### Stage 2 -- the full compiler suite
		"../${GCC_DIR}/configure" --target="${CCNAME}" --prefix="${CCDIR}" --with-headers="${CCDIR}/${CCNAME}/include" --disable-nls --enable-languages='c,c++' --with-sysroot="${CCDIR}/${CCNAME}" --with-build-sysroot="${CCDIR}/${CCNAME}" ${BUILD_CC_GCC_CONFIGURE_EXTRA}


		${MAKE} || exit 1
		${MAKE} install || exit 1
	fi
)
retval="$?"

### XXX: Create symlink for libgcc_eh.a since GCC references
### it without building it for static (disable-shared) builds
if [ "${STAGE}" = "stage1" ]; then
	if [ -h "${libgcceha}" ]; then
		rm -f "${libgcceha}"
	fi

	if [ ! -f "${libgcceha}" ]; then
		ln -s libgcc.a "${libgcceha}"
	fi

fi

### If we exited with failure above, abort
if [ "${retval}" != "2" -a "${retval}" != "0" ]; then
	exit 1
fi
rm -rf "gcc-${CCNAME}"

## Install libraries for this platform
for appscript in scripts/* scripts/post/*; do
	if echo "${appscripts}" | grep '/common$' >/dev/null; then
		continue
	fi

	if [ ! -f "${appscript}" -o ! -x "${appscript}" ]; then
		continue
	fi

	(
		PATH="${PATH}:${CCDIR}/bin"
		CC="${CCNAME}-gcc"
		LD="${CCNAME}-ld"
		CXX="${CCNAME}-g++"
		AR="${CCNAME}-ar"
		STRIP="${CCNAME}-strip"
		RANLIB="${CCNAME}-ranlib"
		export PATH CC LD CXX AR STRIP RANLIB

		"${appscript}" "${CCNAME}" "${CCDIR}" "${CCDIR}/${CCNAME}" "${STAGE}" || exit 1
	) || exit 1







|
|
|
<







 







|
|
|
|

|
|
|
|

|
|
|
|
<
<
<
<
<



|


|
<












|







 







|













<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
<
<
<
<
>
>
>







 







|
|




|


|







 







|
|

|
<
<
<
<




|
>







 







|

|
|
|
<


|
|
<
|


|
<
<
>

<
<
<
>
>



|






|







|






|
|
|






|








|

|
|
|

|
|
>

|

<
|
<
<
<
>


<
>

|
|




|
<

<
<
<
<
<
<
<
>






|













|

|







30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112





113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172



















173
174






175
176
177
178
179
180
181
182
183
184
...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
274
275
276
277
278
279
280
281
282
283
284




285
286
287
288
289
290
291
292
293
294
295
296
297
...
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318

319
320
321
322


323
324



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

382



383
384
385

386
387
388
389
390
391
392
393
394

395







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
## Load configuration file
if [ -f "build-cc.conf" ]; then
	. "build-cc.conf"
fi

# Tool versions
BINUTILS_VERS='2.22'
CLANG_VERS='3.1'
LLVM_VERS="${CLANG_VERS}"
CRT_VERS="${CLANG_VERS}"


# Start of script
## Initialize default values
use_multilib='1'
use_gnu_ld='1'
use_gnu_as='1'

................................................................................

## URLs
### Binutils
BINUTILS_URL="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERS}.tar.bz2"
BINUTILS_TARBALL="src/binutils-${BINUTILS_VERS}.tar.bz2"
BINUTILS_DIR="binutils-${BINUTILS_VERS}"

### CLANG
CLANG_URL="http://llvm.org/releases/${CLANG_VERS}/clang-${CLANG_VERS}.src.tar.gz"
CLANG_TARBALL="src/clang-${CLANG_VERS}.tar.gz"
CLANG_DIR="clang-${CLANG_VERS}.src"

### LLVM
LLVM_URL="http://llvm.org/releases/${LLVM_VERS}/llvm-${LLVM_VERS}.src.tar.gz"
LLVM_TARBALL="src/llvm-${LLVM_VERS}.tar.gz"
LLVM_DIR="llvm-${LLVM_VERS}.src"

### Compiler-RT
CRT_URL="http://llvm.org/releases/3.1/compiler-rt-3.1.src.tar.gz"
CRT_TARBALL="src/compiler-rt-${CRT_VERS}.tar.gz"
CRT_DIR="compiler-rt-3.1.src"






## Clean-up
if [ "$1" = "clean" -o "$1" = "distclean" ]; then
	rm -rf "${CLANG_DIR}" "${LLVM_DIR}" "${CRT_DIR}" "${BINUTILS_DIR}"

	for platform in "${platforms[@]}"; do
		rm -rf "llvm-${platform}"

	done

	for appscript in scripts/* scripts/pre/* scripts/post/*; do
		"${appscript}" "clean" >/dev/null 2>/dev/null
	done

	if [ "$1" = "clean" ]; then
		exit 0
	fi
fi

if [ "$1" = "distclean" ]; then
	rm -f "${CLANG_TARBALL}" "${LLVM_TARBALL}" "${CRT_TARBALL}" "${BINUTILS_TARBALL}"

	for appscript in scripts/* scripts/pre/* scripts/post/*; do
		"${appscript}" "distclean" >/dev/null 2>/dev/null
	done

	rmdir src >/dev/null 2>/dev/null

................................................................................
CCNAME="$1"
CCDIR="${CCROOT}/${CCNAME}"

## Determine attributes for this compiler
### Per CPU
case "${CCNAME}" in
	hppa64-*|hppa1*-)
		BUILD_CC_LLVM_CONFIGURE_EXTRA="${BUILD_CC_LLVM_CONFIGURE_EXTRA} --disable-libquadmath"
		;;
esac

### Per OS
case "${CCNAME}" in
	*-hpux*)
		#### Default to disabling multilib, will be re-enabled by target if supported
		use_multilib='0'
		;;
	*-freebsd*)
		#### Default to disabling multilib, will be re-enabled by target if supported
		use_multilib='0'
		;;



















esac







### Disable optimizations if compiling with GCC older than 4.6
if ${CC:-gcc} --version 2>/dev/null | grep 'gcc' >/dev/null; then
	BUILD_CC_LLVM_CONFIGURE_EXTRA="${BUILD_CC_LLVM_CONFIGURE_EXTRA} --with-optimize-option=-O0"
fi

## Determine platform file tarball
PLATFORM_TARBALL="${BUILD_CC_PLATFORMDIR}/${CCNAME}-platform.tar.bz2"
ADDONS_TARBALL="${BUILD_CC_PLATFORMDIR}/platform/${CCNAME}-addons.tar.bz2"

### Install platform files (needed for libgcc)
................................................................................
### Set use_multilib authoritatively if possible
if [ -f "${CCDIR}/${CCNAME}/multilib" ]; then
	use_multilib="$(cat "${CCDIR}/${CCNAME}/multilib")"
	rm -f "${CCDIR}/${CCNAME}/multilib"
fi

### Set C compiler flags from tarball
if [ -f "${CCDIR}/${CCNAME}/BUILD_CC_LLVM_CONFIGURE_EXTRA" ]; then
	add="$(cat "${CCDIR}/${CCNAME}/BUILD_CC_LLVM_CONFIGURE_EXTRA")"

	#### Ensure these flags aren't malicious
	##### XXX: TODO: Build the extra flags as an array for safety
	if ! echo "${add}" | grep '[;|<>]' >/dev/null; then
		BUILD_CC_LLVM_CONFIGURE_EXTRA="${BUILD_CC_LLVM_CONFIGURE_EXTRA} ${add}"
	fi
	
	rm -f "${CCDIR}/${CCNAME}/BUILD_CC_LLVM_CONFIGURE_EXTRA"
fi

## Determine stage of build process
STAGE="$2"

### If we have a platform tarball and a stage has not been specified, assume we are at stage 2
if [ -z "${STAGE}" ]; then
................................................................................

	${MAKE} || exit 1

	${MAKE} install || exit 1
) || exit 1
rm -rf "binutils-${CCNAME}"

## Compile C compiler (CLANG) if needed
### Prepare fix-ups (stage1)
if [ "${STAGE}" = "stage1" ]; then
	true




fi

### If multilib was not requested, disable it
if [ "${use_multilib}" = "0" ]; then
	#BUILD_CC_GCC_CONFIGURE_EXTRA="--disable-multilib ${BUILD_CC_GCC_CONFIGURE_EXTRA}"
	true
fi

## Compile
(
	### Determine if compilation is needed
	if [ -f "${CCDIR}/bin/${CCNAME}-gcc" ]; then
		if find "${CCDIR}/lib/gcc" -type f -name 'libgcc.a' | grep libgcc >/dev/null; then
................................................................................
				if find "${CCDIR}" -type f -name 'libgcc_s.*' | grep libgcc_s >/dev/null; then
					exit 2
				fi
			fi
		fi
	fi

	if [ ! -d "${LLVM_DIR}" ]; then
		# Download sources required
		download "${CLANG_URL}" "${CLANG_TARBALL}"
		download "${LLVM_URL}" "${LLVM_TARBALL}"
		download "${CRT_URL}" "${CRT_TARBALL}"


		# Extract sources
		gzip -dc "${CLANG_TARBALL}" | "${TAR:-tar}" -xf -
		gzip -dc "${LLVM_TARBALL}" | "${TAR:-tar}" -xf -

		gzip -dc "${CRT_TARBALL}" | "${TAR:-tar}" -xf -

		# Arroung sources as needed
		rm -rf "${LLVM_DIR}/tools/clang"


		rm -rf "${LLVM_DIR}/projects/compiler-rt"




		mv "${CLANG_DIR}" "${LLVM_DIR}/tools/clang"
		mv "${CRT_DIR}" "${LLVM_DIR}/projects/compiler-rt"

		# Apply patches
		## Apply patch files
		for patchfile in "$(pwd)/patches/llvm"/*.diff; do
			patchfile_checkscript="$(echo "${patchfile}" | sed 's@\.diff$@.sh@')"
			if [ ! -f "${patchfile}" ]; then
				continue
			fi

			if [ -x "${patchfile_checkscript}" ]; then
				if ! "${patchfile_checkscript}" "${LLVM_VERS}"; then
					continue
				fi
			fi

			(
				echo " * Applying patch ${patchfile}"

				cd "${LLVM_DIR}" || exit 1

				"${PATCH:-patch}" -p1 < "${patchfile}" || exit 1
			) || exit 1
		done

		## Apply patch scripts
		export LLVM_DIR
		for script in scripts/llvm/*; do
			if [ ! -x "${script}" ]; then
				continue
			fi

			sourcefile="${TMPDIR:-/tmp}/build-cc-sourcefile-$$${RANDOM}${RANDOM}${RANDOM}"
			rm -f "${sourcefile}"

			"${script}" "${CCNAME}" "${CCDIR}" "${CCDIR}/${CCNAME}" "${STAGE}" "${sourcefile}" || exit 1

			if [ -f "${sourcefile}" ]; then
				. "${sourcefile}"
				rm -f "${sourcefile}"
			fi
		done
	fi

	# Build CLANG with shared object support
	## Create build directory
	rm -rf "llvm-${CCNAME}"
	mkdir "llvm-${CCNAME}"
	cd "llvm-${CCNAME}" || exit -1

	## Update environment so C compiler's build system can find binutils
	PATH="${PATH}:${CCDIR}/bin"
	export PATH

	## Build Compiler
	if [ "${STAGE}" = "stage1" ]; then

		# XXX: TODO



		true
	else
		### Stage 2 -- the full compiler suite

		"../${LLVM_DIR}/configure" --target="${CCNAME}" --prefix="${CCDIR}" --with-default-sysroot="${CCDIR}/${CCNAME}" ${BUILD_CC_LLVM_CONFIGURE_EXTRA}

		${MAKE} VERBOSE=1 || exit 1
		${MAKE} VERBOSE=1 install || exit 1
	fi
)
retval="$?"

### Post stage1 build fixups

if [ "${STAGE}" = "stage1" ]; then







	true
fi

### If we exited with failure above, abort
if [ "${retval}" != "2" -a "${retval}" != "0" ]; then
	exit 1
fi
rm -rf "llvm-${CCNAME}"

## Install libraries for this platform
for appscript in scripts/* scripts/post/*; do
	if echo "${appscripts}" | grep '/common$' >/dev/null; then
		continue
	fi

	if [ ! -f "${appscript}" -o ! -x "${appscript}" ]; then
		continue
	fi

	(
		PATH="${PATH}:${CCDIR}/bin"
		CC="${CCNAME}-cc"
		LD="${CCNAME}-ld"
		CXX="${CCNAME}-c++"
		AR="${CCNAME}-ar"
		STRIP="${CCNAME}-strip"
		RANLIB="${CCNAME}-ranlib"
		export PATH CC LD CXX AR STRIP RANLIB

		"${appscript}" "${CCNAME}" "${CCDIR}" "${CCDIR}/${CCNAME}" "${STAGE}" || exit 1
	) || exit 1