mknative-gcc revision 1.69
1#!/bin/sh
2#	$NetBSD: mknative-gcc,v 1.69 2013/04/25 16:18:43 skrll Exp $
3#
4# Shell script for generating all the constants needed for a native
5# platform build of gcc.
6#
7
8# initialise
9
10_TMPDIR=$2
11_TOP=$3
12_PLATFORM=$4
13_DESTDIR=$5
14_ABI=$6
15_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
16_GNU_DIST=`cd ${_VPATH}; pwd`
17
18if [ -z "$_DESTDIR" ]; then
19	echo "\$_DESTDIR is empty" 2>&1
20	exit 1
21fi
22
23. $_TOP/tools/gcc/mknative.common
24
25# default to GCC 4.1 for now
26_OUTDIR="$_TOP/gnu"
27_OUTDIRBASE="gnu"
28
29##### gnu/lib/crtstuff #####
30
31get_crtstuff () {
32	_subdir="$1"
33	mkdir -p $_OUTDIR/lib/$_subdir/arch
34
35	getvars gcc/Makefile \
36		INCLUDES CRTSTUFF_CFLAGS CRTSTUFF_T_CFLAGS CRTSTUFF_T_CFLAGS_S \
37		tm_defines xm_file xm_defines \
38		| sed "s,-I$_DESTDIR/usr/include,,g" \
39		| write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH.mk
40}
41
42##### gnu/lib/libg2c #####
43
44get_libg2c () {
45	mkdir -p $_OUTDIR/lib/libg2c3/arch/$MACHINE_ARCH
46
47	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h
48	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h
49
50	{
51		getvars $_PLATFORM/libf2c/Makefile \
52			F2CEXT
53		getvars $_PLATFORM/libf2c/libF77/Makefile \
54			ALL_CFLAGS OBJS
55		getvars $_PLATFORM/libf2c/libI77/Makefile \
56			ALL_CFLAGS OBJS | sed 's,=,+=,'
57		getvars $_PLATFORM/libf2c/libU77/Makefile \
58			ALL_CFLAGS OBJS | sed 's,=,+=,'
59	} | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/defs.mk
60}
61
62##### gnu/lib/libgcc #####
63
64get_libgcc_list_funcs_asm () {
65	{
66		getvars gcc/Makefile LIB1ASMFUNCS | {
67			# print newline separated list
68			sed -e '
69				s,^.*=,,
70				s, *$,,
71				s,  *, ,g
72				s, ,\
73,g'
74		}
75		getvars gcc/Makefile LIB2FUNCS_EXTRA | {
76			# print newline separated list
77			sed -e '
78				s,^.*=,,
79				s, *$,,
80				s,  *, ,g
81				s, ,\
82,g' | \
83			sed -ne '
84				/\.S$/ { s,^.*/,,; s,\.S$,,; p; }
85				/\.asm$/ { s,^.*/,,; s,\.asm$,,; p; }
86			'
87		}
88	} | {
89		# print foo and foo_s
90		sed -ne '
91			/./ {
92				p
93				s,$,_s,
94				p
95			}
96		'
97	} | sort
98}
99
100get_libgcc_list_funcs_lib () {
101	local _lib=$1
102	local _lib_prefix=${_lib%.*}
103	local _lib_suffix=${_lib#*.}
104	local _abi=${2:-'\.'}
105
106	cat build/gcc/libgcc.mk | \
107	grep '/'${_abi}'/' | \
108	sed -ne '
109		/^'${_abi}'\/'${_lib_prefix}'\.'${_lib_suffix}': .*\.o$/ {
110			s,^.*/,,
111			s,\.o$,,
112			p
113		}
114	' | sort
115}
116
117get_libgcc_list_objs_libs () {
118	local _abi=${1:-'\.'}
119
120	cat build/gcc/libgcc.mk | \
121	grep '/'${_abi}'/' | \
122	egrep '^'${_abi}'\/(libgcc_s\.so|libgcc\.a|libgcc_eh\.a|libgcov\.a): (libgcc_s|libgcc|libgcc_eh|libgcov)\/.*\.o$' | \
123	sed -e '
124		s,^'${_abi}'\/,,
125		s,: .*/,	,
126		s,^\(.*\)	\(.*\)$,\2	\1,
127	' | sort
128}
129
130get_libgcc_list_objs_srcs () {
131	local _abi=${1:-'\.'}	# XXX not used
132
133	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
134		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
135		comm -23 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
136		sed -e 's,\(.*\),\1.o	\1.c,'
137
138		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
139		comm -12 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
140		sed -e 's,\(.*\),\1.o	\1.S,'
141	else
142		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
143		sed -e 's,\(.*\),\1.o	\1.c,'
144	fi | sort
145}
146
147get_libgcc_list_objs_tmplsrcs () {
148	local _abi=${1:-'\.'}
149
150	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
151	grep '/'${_abi}'/' | \
152	sed -ne '
153		s,^.* -c \([^ ]*\).* -o .*/\([^ ]*\.o\)$,\2	\1,
154		# basename
155		/\$/ { s,\$.*/,,; }
156		/\// { s,\/.*/,,; }
157		p
158	' | sort -u
159}
160
161get_libgcc_list_objs_xflags () {
162	local _flags=$1
163	local _abi=${2:-'\.'}
164
165	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
166	grep '/'${_abi}'/' | \
167	sed -n '
168		x
169	:loop
170		g
171		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\5	\2/p
172		g
173		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\1 \3 \4\/\5/
174		h
175		t loop
176	' | sort
177}
178
179get_libgcc_list_objs_cppflags () {
180	get_libgcc_list_objs_xflags D $1
181}
182
183get_libgcc_list_objs_copts () {
184	get_libgcc_list_objs_xflags fmx $1
185}
186
187get_libgcc_list_tmplsrcs () {
188	local _lib=$1
189	local _abi=$2	# XXX not used
190	local _tmplallsrcs=$( mktemp /tmp/mknative-gcc._tmplallsrcs.XXXXXX )
191
192	touch $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
193	touch $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
194	touch $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
195
196	# all files
197	local _lib_prefix=${_lib%.*}
198	local _lib_suffix=${_lib#*.}
199	join $_TOP/$libgcc_db_objs_libs $_TOP/$libgcc_db_objs_tmplsrcs | \
200	grep ${_lib_prefix}'\.'${_lib_suffix} | cut -d' ' -f 3 | sort -u > \
201	$_tmplallsrcs
202
203	# TMPLFPSRCS = [fdp]p-bit.c
204	grep '[fdt]p-bit\.c' <$_tmplallsrcs | sort -u | \
205	writefile ${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
206
207	# TMPLASMSRCS = $(LIB1ASMSRC)
208	grep '\$(LIB1ASMSRC)' <$_tmplallsrcs | sort -u | \
209	writefile ${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
210
211	# TMPLSRCS is anything else; exclude TMPLFPSRCS and TMPLASMSRCS
212	cat $_tmplallsrcs | \
213	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*} | \
214	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
215	writefile ${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
216
217	rm -f $_tmplallsrcs
218}
219
220get_libgcc_new_analyze () {
221	local _abi=$1
222
223	mkdir -p $_TOP/${_machine_arch_subdir}
224
225	touch $_TOP/${libgcc_db_funcs}.S
226	get_libgcc_list_funcs_asm | \
227	writefile ${libgcc_db_funcs}.S
228
229	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
230		touch $_TOP/${libgcc_db_funcs}.${_lib%.*}
231		get_libgcc_list_funcs_lib $_lib $_abi | \
232		writefile ${libgcc_db_funcs}.${_lib%.*}
233	done
234
235	get_libgcc_list_objs_libs $_abi | writefile ${libgcc_db_objs_libs}
236	get_libgcc_list_objs_srcs $_abi | writefile ${libgcc_db_objs_srcs}
237	get_libgcc_list_objs_tmplsrcs $_abi | writefile ${libgcc_db_objs_tmplsrcs}
238	get_libgcc_list_objs_cppflags $_abi | writefile ${libgcc_db_objs_cppflags}
239	get_libgcc_list_objs_copts $_abi | writefile ${libgcc_db_objs_copts}
240
241	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
242		get_libgcc_list_tmplsrcs $_lib $_abi
243	done
244}
245
246#####
247
248get_libgcc_gen_tmplsrcs_tmplsrcs () {
249	local _lib=$1
250
251	printf '\n'
252	printf 'TMPLSRCS.%s = \\\n' $_lib
253	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
254}
255
256get_libgcc_gen_tmplsrcs_tmplfpsrcs () {
257	local _lib=$1
258
259	printf '\n'
260	printf 'TMPLFPSRCS.%s = \\\n' $_lib
261	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
262}
263
264get_libgcc_gen_tmplsrcs_tmplasmsrcs () {
265	local _lib=$1
266
267	printf '\n'
268	printf 'TMPLASMSRCS.%s = \\\n' $_lib
269	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
270	sed -e 's,LIB1ASMSRC,G_&,'
271}
272
273get_libgcc_gen_srcs () {
274	local _lib=$1
275
276	printf '\n'
277	printf 'SRCS.%s = \\\n' $_lib
278	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
279		comm -23 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
280		sed -e 's,$,.c,; s,^,tmp_,'
281		comm -12 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
282		sed -e 's,$,.S,; s,^,tmp_,'
283	else
284		cat $_TOP/${libgcc_db_funcs}.${_lib%.*} | \
285		sed -e 's,$,.c,; s,^,tmp_,'
286	fi | sort | \
287	sed -e 's,^,	,; s,$, \\,'
288}
289
290_lookup_objs () {
291	local _obj=$1; local _key=$2
292
293	eval grep \^$_obj\\\	 \$_TOP/\${libgcc_db_objs_${_key}} | cut -f2
294}
295
296get_libgcc_gen_srcs_tmplsrcs () {
297	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
298	while read _obj; do
299		printf 'SRCS.tmp_%s=%s\n' \
300			"$( _lookup_objs $_obj srcs )" \
301			"$( _lookup_objs $_obj tmplsrcs )"
302	done | \
303	sed -e 's,\$(\(.*\)),${G_\1},'
304}
305
306get_libgcc_gen_srcs_cppflags () {
307	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
308	while read _obj; do
309		printf '_CPPFLAGS.tmp_%s=%s\n' \
310			"$( _lookup_objs $_obj srcs )" \
311			"$( _lookup_objs $_obj cppflags | xargs )"
312	done
313}
314
315get_libgcc_gen_srcs_copts () {
316	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
317	while read _obj; do
318		printf 'COPTS.tmp_%s=%s\n' \
319			"$( _lookup_objs $_obj srcs )" \
320			"$( _lookup_objs $_obj copts | xargs )"
321	done
322}
323
324get_libgcc_new_generate () {
325	local _abi=$1
326
327	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
328		for _tmpl in tmplsrcs tmplfpsrcs tmplasmsrcs; do
329			eval get_libgcc_gen_tmplsrcs_${_tmpl} $_lib | \
330			write_mk ${libgcc_libs_mk}.${_lib%.*}.tmplsrcs.${_tmpl}.mk
331		done
332
333		get_libgcc_gen_srcs $_lib | \
334		write_mk ${libgcc_libs_mk}.${_lib%.*}.srcs.mk
335	done
336
337	for _arg in tmplsrcs cppflags copts; do
338		eval get_libgcc_gen_srcs_${_arg} | \
339		eval writefile \$libgcc_srcs_mk_${_arg}
340	done
341}
342
343#####
344
345get_libgcc_new () {
346	_subdir="$1"
347	_abi="$2"
348
349	# List of generated files.
350
351	_machine_arch_subdir=$_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH/$_abi
352
353	libgcc_db_funcs=${_machine_arch_subdir}/funcs
354	libgcc_db_tmplsrcs=${_machine_arch_subdir}/tmplsrcs
355	libgcc_db_objs_libs=${_machine_arch_subdir}/objs.libs
356	libgcc_db_objs_srcs=${_machine_arch_subdir}/objs.srcs
357	libgcc_db_objs_tmplsrcs=${_machine_arch_subdir}/objs.tmplsrcs
358	libgcc_db_objs_cppflags=${_machine_arch_subdir}/objs.cppflags
359	libgcc_db_objs_copts=${_machine_arch_subdir}/objs.copts
360
361	get_libgcc_new_analyze $_abi
362
363	libgcc_libs_mk=${_machine_arch_subdir}/libs
364	libgcc_srcs_mk=${_machine_arch_subdir}/srcs.mk
365	libgcc_srcs_mk_tmplsrcs=${_machine_arch_subdir}/srcs.tmplsrcs.mk
366	libgcc_srcs_mk_cppflags=${_machine_arch_subdir}/srcs.cppflags.mk
367	libgcc_srcs_mk_copts=${_machine_arch_subdir}/srcs.copts.mk
368
369	get_libgcc_new_generate $_abi
370}
371
372get_libgcc () {
373	_subdir="$1"
374	mkdir -p $_OUTDIR/lib/lib$_subdir/arch
375
376	case "$_subdir" in
377	gcc4|gcc)
378		_extravars="COLLECT2 UNWIND_H xm_include_list"
379		_archsubdir=""
380		;;
381	esac
382
383	# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
384	# XXX we should probably grab everything Just In Case for
385	# the future.
386	{
387		getvars gcc/Makefile \
388			INCLUDES LIB2ADD LIB2ADDEH LIB2ADD_ST \
389			LIB1ASMFUNCS LIB1ASMSRC \
390			LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \
391			LIB2FUNCS_EXTRA \
392			LIBGCC2_CFLAGS \
393			SHLIB_MKMAP SHLIB_MKMAP_OPTS \
394			SHLIB_MAPFILES SHLIB_NM_FLAGS \
395			EXTRA_HEADERS xm_defines \
396			tm_defines ${_extravars}
397	} | sed \
398		-e "s,-I$_DESTDIR/usr/include,,g" \
399		-e "s,-I$_TOP/external/lgpl3/mpfr/dist,,g" \
400		-e "s,-I$_TOP/external/lgpl2/mpc/dist/src,,g" \
401		-e "s,-I$_TOP/external/lgpl3/gmp/lib/libgmp/arch/$MACHINE_ARCH,,g" \
402		| write_mk $_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH.mk
403
404	# Generate new style files.
405	if [ -n "${MKNATIVE_LIBGCC_NEW}" ]; then
406		get_libgcc_new $_subdir $_ABI
407	fi
408}
409
410##### gnu/lib/libgcov #####
411
412get_libgcov () {
413	_subdir="$1"
414
415	mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH
416
417	{
418		getvars gcc/Makefile \
419			LIBGCOV
420	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/defs.mk
421
422	write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/gcov-iov.h \
423	   <$_TMPDIR/gcc/gcov-iov.h
424
425}
426
427##### gnu/usr.bin/gcc[34]/libiberty #####
428
429get_gcc_libiberty () {
430	_subdir="$1"
431	case "$_subdir" in
432	gcc4)
433		_libibertydir="usr.bin/$_subdir/libiberty"
434		;;
435	gcc)
436		_libibertydir="lib/libiberty"
437		;;
438	esac
439	mkdir -p $_OUTDIR/$_libibertydir/arch/$MACHINE_ARCH
440
441	getvars libiberty/Makefile \
442		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
443		| write_mk $_OUTDIRBASE/$_libibertydir/defs.mk
444
445	write_c $_OUTDIRBASE/$_libibertydir/arch/$MACHINE_ARCH/config.h \
446		<$_TMPDIR/libiberty/config.h
447}
448
449##### lib/libdecnumber #####
450
451get_libdecnumber () {
452	_subdir="$1"
453
454	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
455	write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/config.h \
456		<$_TMPDIR/libdecnumber/config.h
457}
458
459##### lib/libgomp #####
460
461get_libgomp () {
462	_subdir="$1"
463
464	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
465	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
466		<$_TMPDIR/$_PLATFORM/libgomp/config.h
467	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp_f.h \
468		<$_TMPDIR/$_PLATFORM/libgomp/libgomp_f.h
469	write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp.spec \
470		<$_TMPDIR/$_PLATFORM/libgomp/libgomp.spec
471	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/omp.h \
472		<$_TMPDIR/$_PLATFORM/libgomp/omp.h
473}
474
475##### gnu/lib/libobjc #####
476
477get_libobjc () {
478	_subdir="$1/arch/$MACHINE_ARCH"
479	_options="ALL_OPT_FILES"
480	_unwind="UNWIND_H"
481
482	mkdir -p $_OUTDIR/lib/$_subdir
483
484	{
485		if [ -n "$_options" ]; then
486			getvars gcc/Makefile $_options
487		fi
488		getvars $_PLATFORM/libobjc/Makefile \
489			ALL_CFLAGS INCLUDES OBJS OBJC_H \
490			| sed "s,$_GNU_DIST,\${GNUHOSTDIST},g"
491		if [ -n "$_unwind" ]; then
492			getvars gcc/Makefile $_unwind
493		fi
494	} | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk
495
496	write_c $_OUTDIRBASE/lib/$_subdir/config.h \
497		<$_TMPDIR/$_PLATFORM/libobjc/config.h
498}
499
500##### gnu/lib/libstdc++-v3 #####
501
502get_libstdcxx_v3 () {
503	_subdir="$1"
504	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
505
506	case ${_subdir} in
507	*)
508		_src_CC_files="atomicity_file CCODECVT_CC CCOLLATE_CC CCTYPE_CC CMESSAGES_CC CMONEY_CC CNUMERIC_CC CTIME_CC CLOCALE_CC BASIC_FILE_CC"
509		_headers1="host_headers debug_headers tr1_headers c_compatibility_headers_extra tr1_impl_headers parallel_headers decimal_headers"
510		_headers2="thread_host_headers host_headers_extra"
511		_build_headers="c++allocator.h c++config.h cxxabi_tweaks.h gthr-default.h gthr-posix.h gthr-single.h gthr-tpf.h gthr.h"
512		_unwind="UNWIND_H"
513		;;
514	esac
515
516	# build files
517	for h in $_build_headers; do
518		write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/$h \
519			<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h
520	done
521
522	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
523		<$_TMPDIR/$_PLATFORM/libstdc++-v3/config.h
524	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/gstdint.h \
525		<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h
526
527	{
528		# libsupc++
529		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
530			sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/'
531		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
532			c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/'
533
534		# src
535		getvars $_PLATFORM/libstdc++-v3/src/Makefile \
536			sources $_src_CC_files SECTION_FLAGS | sed 's/^G_sources=/G_SRC_SOURCES=/'
537
538		# include
539		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
540			c_base_headers std_headers | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
541		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
542			bits_headers backward_headers ext_headers c_base_headers_extra \
543			$_headers1 | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
544		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
545			$_headers2 | sed -e 's#\./[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
546
547		if [ -n "$_unwind" ]; then
548			getvars gcc/Makefile $_unwind
549		fi
550	} | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/defs.mk
551}
552
553##### gnu/usr.bin/gcc3 #####
554
555get_gcc_bootstrap () {
556	_subdir="$1"
557	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
558	for f in auto-host tm config gthr-default; do
559		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
560	done
561}
562
563get_gcc () {
564	_subdir="$1"
565	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
566	mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$MACHINE_ARCH
567	case ${_subdir} in
568	gcc4)
569		_buildname="BUILD_"
570		_libcppsubdir=""
571		_extravars="TM_H ALL_OPT_FILES"
572		_hconfig_h=""
573		_extravars2="tm_file_list build_xm_include_list"
574		_extravars3="tm_p_include_list"
575		;;
576		
577	gcc)
578		_buildname="BUILD_"
579		_libcppsubdir=""
580		_extravars="TM_H ALL_OPT_FILES"
581		_hconfig_h=""
582		_extravars2="tm_file_list build_xm_include_list"
583		_extravars3="tm_p_include_list"
584		;;
585	esac
586
587	{
588		getvars gcc/Makefile \
589			${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \
590			${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY | \
591		    sed -e 's#build/errors.o#build-errors.o#g' \
592			-e 's#build/print-rtl.o#build-print-rtl.o#g' \
593			-e 's#build/rtl.o#build-rtl.o#g' \
594			-e 's#build/varray.o#build-varray.o#g' \
595			-e 's#build/ggc-none.o#build-ggc-none.o#g' \
596			-e 's#build/##g'
597		getvars gcc/Makefile \
598			ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
599			GCOV_OBJS PROTO_OBJS ${_extravars1} \
600			INCLUDES md_file OBJC_OBJS OBJS out_file version \
601			BUILD_PREFIX RTL_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \
602			GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \
603			GTFILES GTFILES_LANG_DIR_NAMES \
604			tm_defines host_xm_file host_xm_defines tm_p_file \
605			target_cpu_default ${_extravars} ${_extravars2} \
606			lang_specs_files ${_extravars3} \
607				| sed -e "s,-I$_DESTDIR/usr/include,,g" \
608					-e "s,-I$_TOP/external/lgpl3/mpfr/dist,,g" \
609					-e "s,-I$_TOP/external/lgpl2/mpc/dist/src,,g" \
610					-e "s,-I$_TOP/external/lgpl3/gmp/lib/libgmp/arch/$MACHINE_ARCH,,g"
611		getvars gcc/Makefile \
612			LIB2ADDEHDEP | sed 's/unwind.inc//'
613		getvars gcc/Makefile \
614			CXX_OBJS CXX_C_OBJS | sed 's/cp\///g'
615		getvars gcc/Makefile \
616			F77_OBJS | sed 's/f\///g'
617		case ${_subdir} in
618		gcc4 | gcc)
619			getvars libcpp/Makefile \
620				libcpp_a_OBJS
621			;;
622		gcc3)
623			getvars gcc/Makefile \
624				LIBCPP_OBJS LIBCPP_H
625			;;
626		esac
627		getvars gcc/Makefile \
628			ENABLE_SHARED
629		case ${_subdir} in
630		gcc4 | gcc)
631			echo G_SHLIB_LINK="$CC -shared"
632			echo G_SHLIB_MULTILIB=.
633			;;
634		esac
635	} | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/defs.mk
636
637	case "$_subdir" in
638	gcc4)
639		write_c $_OUTDIRBASE/usr.bin/$_subdir/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
640		hfiles='auto-host gencheck configargs gthr-default tm bconfig config multilib'
641		;;
642	gcc)
643		write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
644		hfiles='auto-host configargs gthr-default tm bconfig config multilib bversion plugin-version'
645		;;
646	esac
647	for f in $hfiles; do
648		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
649		if [ "${MACHINE_ARCH}" = "powerpc" -a "${f}" = "configargs" ]
650		then
651			ex <<__EOF__ $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h
652/configuration_arguments/ s/$//
653ya
654i
655#ifdef _SOFT_FLOAT
656.
657pu
658s/";$/ -with-float=soft";/
659a
660#else
661#endif
662.
663. m +1
664/configure_default_options/ s/{ NULL.*$//
665a
666#ifdef _SOFT_FLOAT
667  { "float", "soft" },
668#endif
669  { NULL, NULL }
670};
671.
672wq
673__EOF__
674		fi
675	done
676
677	# keep identical
678	for f in all-tree.def; do
679		cp $_TMPDIR/gcc/$f $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
680	done
681
682	# special transforms
683	for f in gtyp-input.list; do
684		sed -e 's/^.*external\/gpl3\/gcc\/dist/SRCDIR/' < $_TMPDIR/gcc/$f > $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
685	done
686
687	# special platforms
688	if [ "${MACHINE_ARCH}" = "sh3el" -o "${MACHINE_ARCH}" = "sh3eb" ]; then
689		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/sysroot-suffix.h <$_TMPDIR/gcc/sysroot-suffix.h
690	fi
691}
692
693##### main #####
694
695case "$1" in
696# .mk and .h files for libgcc bootstrap (from host build)
697libgcc)
698	get_libgcc gcc3
699	get_crtstuff crtstuff3
700	exit 0
701	;;
702
703libgcc4)
704	get_libgcc gcc4
705	get_crtstuff crtstuff4
706	exit 0
707	;;
708
709libgcc45)
710	_OUTDIR="$_TOP/external/gpl3/gcc"
711	_OUTDIRBASE="external/gpl3/gcc"
712	get_libgcc gcc
713	get_crtstuff crtstuff
714	get_libgcov gcc
715	get_gcc_bootstrap gcc
716	exit 0
717	;;
718
719# gcc files
720gcc4)
721	get_gcc gcc4
722	get_libgcc gcc4
723	get_libgcov gcc4
724	get_crtstuff crtstuff4
725	get_gcc_libiberty gcc4
726	get_libobjc libobjc4
727	get_libstdcxx_v3 libstdc++-v3_4
728	exit 0
729	;;
730
731gcc45)
732	_OUTDIR="$_TOP/external/gpl3/gcc"
733	_OUTDIRBASE="external/gpl3/gcc"
734	get_gcc gcc
735	get_libgcc gcc
736	get_libgcov gcc
737	get_crtstuff crtstuff
738	get_gcc_libiberty gcc
739	get_libobjc libobjc
740	get_libstdcxx_v3 libstdc++-v3
741	get_libdecnumber libdecnumber
742	get_libgomp libgomp
743	exit 0
744	;;
745
746
747*)	echo invalid arguments; exit 1;;
748esac
749