mknative-gcc revision 1.51
11.1Smrg#!/bin/sh
21.51Smrg#	$NetBSD: mknative-gcc,v 1.51 2011/06/29 02:02:38 mrg Exp $
31.1Smrg#
41.1Smrg# Shell script for generating all the constants needed for a native
51.10Smrg# platform build of src/gnu/dist/gcc.
61.1Smrg#
71.1Smrg
81.9Smrg# initialise
91.9Smrg
101.9Smrg_TMPDIR=$2
111.9Smrg_TOP=$3
121.9Smrg_PLATFORM=$4
131.44Suebayasi_ABI=$5
141.15Smrg_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
151.9Smrg_GNU_DIST=`cd ${_VPATH}; pwd`
161.9Smrg
171.9Smrg. $_TOP/tools/gcc/mknative.common
181.1Smrg
191.46Smrg# default to GCC 4.1 for now
201.46Smrg_OUTDIR="$_TOP/gnu"
211.46Smrg_OUTDIRBASE="gnu"
221.46Smrg
231.14Sthorpej##### gnu/lib/crtstuff #####
241.14Sthorpej
251.14Sthorpejget_crtstuff () {
261.16Smrg	_subdir="$1"
271.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir/arch
281.14Sthorpej
291.14Sthorpej	getvars gcc/Makefile \
301.14Sthorpej		INCLUDES CRTSTUFF_CFLAGS CRTSTUFF_T_CFLAGS \
311.14Sthorpej		tm_defines xm_file xm_defines \
321.46Smrg		| write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH.mk
331.14Sthorpej}
341.14Sthorpej
351.1Smrg##### gnu/lib/libg2c #####
361.1Smrg
371.1Smrgget_libg2c () {
381.46Smrg	mkdir -p $_OUTDIR/lib/libg2c3/arch/$MACHINE_ARCH
391.1Smrg
401.46Smrg	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h
411.46Smrg	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h
421.1Smrg
431.1Smrg	{
441.1Smrg		getvars $_PLATFORM/libf2c/Makefile \
451.1Smrg			F2CEXT
461.1Smrg		getvars $_PLATFORM/libf2c/libF77/Makefile \
471.1Smrg			ALL_CFLAGS OBJS
481.1Smrg		getvars $_PLATFORM/libf2c/libI77/Makefile \
491.1Smrg			ALL_CFLAGS OBJS | sed 's,=,+=,'
501.1Smrg		getvars $_PLATFORM/libf2c/libU77/Makefile \
511.1Smrg			ALL_CFLAGS OBJS | sed 's,=,+=,'
521.46Smrg	} | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/defs.mk
531.1Smrg}
541.1Smrg
551.1Smrg##### gnu/lib/libgcc #####
561.1Smrg
571.28Suebayasiget_libgcc_list_funcs_asm () {
581.42Suebayasi	{
591.42Suebayasi		getvars gcc/Makefile LIB1ASMFUNCS | {
601.42Suebayasi			# print newline separated list
611.42Suebayasi			sed -e '
621.42Suebayasi				s,^.*=,,
631.42Suebayasi				s, *$,,
641.42Suebayasi				s,  *, ,g
651.42Suebayasi				s, ,\
661.28Suebayasi,g'
671.42Suebayasi		}
681.42Suebayasi		getvars gcc/Makefile LIB2FUNCS_EXTRA | {
691.42Suebayasi			# print newline separated list
701.42Suebayasi			sed -e '
711.42Suebayasi				s,^.*=,,
721.42Suebayasi				s, *$,,
731.42Suebayasi				s,  *, ,g
741.42Suebayasi				s, ,\
751.42Suebayasi,g' | \
761.42Suebayasi			sed -ne '
771.42Suebayasi				/\.S$/ { s,^.*/,,; s,\.S$,,; p; }
781.42Suebayasi				/\.asm$/ { s,^.*/,,; s,\.asm$,,; p; }
791.42Suebayasi			'
801.42Suebayasi		}
811.28Suebayasi	} | {
821.28Suebayasi		# print foo and foo_s
831.28Suebayasi		sed -ne '
841.28Suebayasi			/./ {
851.28Suebayasi				p
861.28Suebayasi				s,$,_s,
871.28Suebayasi				p
881.28Suebayasi			}
891.28Suebayasi		'
901.28Suebayasi	} | sort
911.28Suebayasi}
921.28Suebayasi
931.29Suebayasiget_libgcc_list_funcs_lib () {
941.29Suebayasi	local _lib=$1
951.29Suebayasi	local _lib_prefix=${_lib%.*}
961.29Suebayasi	local _lib_suffix=${_lib#*.}
971.44Suebayasi	local _abi=${2:-'\.'}
981.29Suebayasi
991.43Suebayasi	cat build/gcc/libgcc.mk | \
1001.44Suebayasi	grep '/'${_abi}'/' | \
1011.29Suebayasi	sed -ne '
1021.45Suebayasi		/^'${_abi}'\/'${_lib_prefix}'\.'${_lib_suffix}': .*\.o$/ {
1031.29Suebayasi			s,^.*/,,
1041.29Suebayasi			s,\.o$,,
1051.29Suebayasi			p
1061.29Suebayasi		}
1071.43Suebayasi	' | sort
1081.29Suebayasi}
1091.29Suebayasi
1101.30Suebayasiget_libgcc_list_objs_libs () {
1111.44Suebayasi	local _abi=${1:-'\.'}
1121.44Suebayasi
1131.30Suebayasi	cat build/gcc/libgcc.mk | \
1141.44Suebayasi	grep '/'${_abi}'/' | \
1151.45Suebayasi	egrep '^'${_abi}'\/(libgcc_s\.so|libgcc\.a|libgcc_eh\.a|libgcov\.a): (libgcc_s|libgcc|libgcc_eh|libgcov)\/.*\.o$' | \
1161.30Suebayasi	sed -e '
1171.44Suebayasi		s,^'${_abi}'\/,,
1181.30Suebayasi		s,: .*/,	,
1191.30Suebayasi		s,^\(.*\)	\(.*\)$,\2	\1,
1201.30Suebayasi	' | sort
1211.30Suebayasi}
1221.30Suebayasi
1231.30Suebayasiget_libgcc_list_objs_srcs () {
1241.44Suebayasi	local _abi=${1:-'\.'}	# XXX not used
1251.44Suebayasi
1261.41Suebayasi	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
1271.30Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1281.30Suebayasi		comm -23 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
1291.30Suebayasi		sed -e 's,\(.*\),\1.o	\1.c,'
1301.30Suebayasi
1311.30Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1321.30Suebayasi		comm -12 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
1331.30Suebayasi		sed -e 's,\(.*\),\1.o	\1.S,'
1341.41Suebayasi	else
1351.41Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1361.41Suebayasi		sed -e 's,\(.*\),\1.o	\1.c,'
1371.41Suebayasi	fi | sort
1381.30Suebayasi}
1391.30Suebayasi
1401.40Suebayasiget_libgcc_list_objs_tmplsrcs () {
1411.44Suebayasi	local _abi=${1:-'\.'}
1421.44Suebayasi
1431.32Suebayasi	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
1441.44Suebayasi	grep '/'${_abi}'/' | \
1451.32Suebayasi	sed -ne '
1461.32Suebayasi		s,^.* -c \([^ ]*\).* -o .*/\([^ ]*\.o\)$,\2	\1,
1471.32Suebayasi		# basename
1481.32Suebayasi		/\$/ { s,\$.*/,,; }
1491.32Suebayasi		/\// { s,\/.*/,,; }
1501.32Suebayasi		p
1511.43Suebayasi	' | sort -u
1521.32Suebayasi}
1531.32Suebayasi
1541.31Suebayasiget_libgcc_list_objs_xflags () {
1551.31Suebayasi	local _flags=$1
1561.44Suebayasi	local _abi=${2:-'\.'}
1571.31Suebayasi
1581.31Suebayasi	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
1591.44Suebayasi	grep '/'${_abi}'/' | \
1601.31Suebayasi	sed -n '
1611.31Suebayasi		x
1621.31Suebayasi	:loop
1631.31Suebayasi		g
1641.31Suebayasi		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\5	\2/p
1651.31Suebayasi		g
1661.31Suebayasi		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\1 \3 \4\/\5/
1671.31Suebayasi		h
1681.31Suebayasi		t loop
1691.31Suebayasi	' | sort
1701.31Suebayasi}
1711.31Suebayasi
1721.31Suebayasiget_libgcc_list_objs_cppflags () {
1731.44Suebayasi	get_libgcc_list_objs_xflags D $1
1741.31Suebayasi}
1751.31Suebayasi
1761.31Suebayasiget_libgcc_list_objs_copts () {
1771.44Suebayasi	get_libgcc_list_objs_xflags fmx $1
1781.31Suebayasi}
1791.31Suebayasi
1801.40Suebayasiget_libgcc_list_tmplsrcs () {
1811.33Suebayasi	local _lib=$1
1821.44Suebayasi	local _abi=$2	# XXX not used
1831.40Suebayasi	local _tmplallsrcs=$( mktemp /tmp/mknative-gcc._tmplallsrcs.XXXXXX )
1841.33Suebayasi
1851.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
1861.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
1871.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
1881.33Suebayasi
1891.33Suebayasi	# all files
1901.33Suebayasi	local _lib_prefix=${_lib%.*}
1911.33Suebayasi	local _lib_suffix=${_lib#*.}
1921.40Suebayasi	join $_TOP/$libgcc_db_objs_libs $_TOP/$libgcc_db_objs_tmplsrcs | \
1931.33Suebayasi	grep ${_lib_prefix}'\.'${_lib_suffix} | cut -d' ' -f 3 | sort -u > \
1941.40Suebayasi	$_tmplallsrcs
1951.33Suebayasi
1961.40Suebayasi	# TMPLFPSRCS = [fdp]p-bit.c
1971.40Suebayasi	grep '[fdt]p-bit\.c' <$_tmplallsrcs | sort -u | \
1981.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
1991.40Suebayasi
2001.40Suebayasi	# TMPLASMSRCS = $(LIB1ASMSRC)
2011.40Suebayasi	grep '\$(LIB1ASMSRC)' <$_tmplallsrcs | sort -u | \
2021.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
2031.40Suebayasi
2041.40Suebayasi	# TMPLSRCS is anything else; exclude TMPLFPSRCS and TMPLASMSRCS
2051.40Suebayasi	cat $_tmplallsrcs | \
2061.40Suebayasi	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*} | \
2071.40Suebayasi	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
2081.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
2091.33Suebayasi
2101.40Suebayasi	rm -f $_tmplallsrcs
2111.33Suebayasi}
2121.33Suebayasi
2131.35Suebayasiget_libgcc_new_analyze () {
2141.44Suebayasi	local _abi=$1
2151.44Suebayasi
2161.35Suebayasi	mkdir -p $_TOP/${_machine_arch_subdir}
2171.35Suebayasi
2181.41Suebayasi	touch $_TOP/${libgcc_db_funcs}.S
2191.35Suebayasi	get_libgcc_list_funcs_asm | \
2201.35Suebayasi	writefile ${libgcc_db_funcs}.S
2211.35Suebayasi
2221.35Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
2231.41Suebayasi		touch $_TOP/${libgcc_db_funcs}.${_lib%.*}
2241.44Suebayasi		get_libgcc_list_funcs_lib $_lib $_abi | \
2251.35Suebayasi		writefile ${libgcc_db_funcs}.${_lib%.*}
2261.35Suebayasi	done
2271.35Suebayasi
2281.44Suebayasi	get_libgcc_list_objs_libs $_abi | writefile ${libgcc_db_objs_libs}
2291.44Suebayasi	get_libgcc_list_objs_srcs $_abi | writefile ${libgcc_db_objs_srcs}
2301.44Suebayasi	get_libgcc_list_objs_tmplsrcs $_abi | writefile ${libgcc_db_objs_tmplsrcs}
2311.44Suebayasi	get_libgcc_list_objs_cppflags $_abi | writefile ${libgcc_db_objs_cppflags}
2321.44Suebayasi	get_libgcc_list_objs_copts $_abi | writefile ${libgcc_db_objs_copts}
2331.35Suebayasi
2341.35Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
2351.44Suebayasi		get_libgcc_list_tmplsrcs $_lib $_abi
2361.35Suebayasi	done
2371.35Suebayasi}
2381.35Suebayasi
2391.35Suebayasi#####
2401.35Suebayasi
2411.40Suebayasiget_libgcc_gen_tmplsrcs_tmplsrcs () {
2421.37Suebayasi	local _lib=$1
2431.37Suebayasi
2441.37Suebayasi	printf '\n'
2451.40Suebayasi	printf 'TMPLSRCS.%s = \\\n' $_lib
2461.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
2471.37Suebayasi}
2481.37Suebayasi
2491.40Suebayasiget_libgcc_gen_tmplsrcs_tmplfpsrcs () {
2501.37Suebayasi	local _lib=$1
2511.37Suebayasi
2521.37Suebayasi	printf '\n'
2531.40Suebayasi	printf 'TMPLFPSRCS.%s = \\\n' $_lib
2541.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
2551.37Suebayasi}
2561.37Suebayasi
2571.40Suebayasiget_libgcc_gen_tmplsrcs_tmplasmsrcs () {
2581.37Suebayasi	local _lib=$1
2591.37Suebayasi
2601.37Suebayasi	printf '\n'
2611.40Suebayasi	printf 'TMPLASMSRCS.%s = \\\n' $_lib
2621.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
2631.37Suebayasi	sed -e 's,LIB1ASMSRC,G_&,'
2641.37Suebayasi}
2651.37Suebayasi
2661.36Suebayasiget_libgcc_gen_srcs () {
2671.36Suebayasi	local _lib=$1
2681.36Suebayasi
2691.36Suebayasi	printf '\n'
2701.36Suebayasi	printf 'SRCS.%s = \\\n' $_lib
2711.41Suebayasi	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
2721.36Suebayasi		comm -23 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
2731.36Suebayasi		sed -e 's,$,.c,; s,^,tmp_,'
2741.36Suebayasi		comm -12 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
2751.36Suebayasi		sed -e 's,$,.S,; s,^,tmp_,'
2761.41Suebayasi	else
2771.41Suebayasi		cat $_TOP/${libgcc_db_funcs}.${_lib%.*} | \
2781.41Suebayasi		sed -e 's,$,.c,; s,^,tmp_,'
2791.41Suebayasi	fi | sort | \
2801.36Suebayasi	sed -e 's,^,	,; s,$, \\,'
2811.36Suebayasi}
2821.36Suebayasi
2831.38Suebayasi_lookup_objs () {
2841.38Suebayasi	local _obj=$1; local _key=$2
2851.38Suebayasi
2861.38Suebayasi	eval grep \^$_obj\\\	 \$_TOP/\${libgcc_db_objs_${_key}} | cut -f2
2871.38Suebayasi}
2881.38Suebayasi
2891.40Suebayasiget_libgcc_gen_srcs_tmplsrcs () {
2901.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
2911.38Suebayasi	while read _obj; do
2921.38Suebayasi		printf 'SRCS.tmp_%s=%s\n' \
2931.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
2941.40Suebayasi			"$( _lookup_objs $_obj tmplsrcs )"
2951.38Suebayasi	done | \
2961.38Suebayasi	sed -e 's,\$(\(.*\)),${G_\1},'
2971.38Suebayasi}
2981.38Suebayasi
2991.38Suebayasiget_libgcc_gen_srcs_cppflags () {
3001.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
3011.38Suebayasi	while read _obj; do
3021.38Suebayasi		printf '_CPPFLAGS.tmp_%s=%s\n' \
3031.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
3041.38Suebayasi			"$( _lookup_objs $_obj cppflags | xargs )"
3051.38Suebayasi	done
3061.38Suebayasi}
3071.38Suebayasi
3081.38Suebayasiget_libgcc_gen_srcs_copts () {
3091.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
3101.38Suebayasi	while read _obj; do
3111.38Suebayasi		printf 'COPTS.tmp_%s=%s\n' \
3121.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
3131.38Suebayasi			"$( _lookup_objs $_obj copts | xargs )"
3141.38Suebayasi	done
3151.38Suebayasi}
3161.38Suebayasi
3171.35Suebayasiget_libgcc_new_generate () {
3181.44Suebayasi	local _abi=$1
3191.44Suebayasi
3201.36Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
3211.40Suebayasi		for _tmpl in tmplsrcs tmplfpsrcs tmplasmsrcs; do
3221.40Suebayasi			eval get_libgcc_gen_tmplsrcs_${_tmpl} $_lib | \
3231.40Suebayasi			write_mk ${libgcc_libs_mk}.${_lib%.*}.tmplsrcs.${_tmpl}.mk
3241.37Suebayasi		done
3251.37Suebayasi
3261.36Suebayasi		get_libgcc_gen_srcs $_lib | \
3271.39Suebayasi		write_mk ${libgcc_libs_mk}.${_lib%.*}.srcs.mk
3281.36Suebayasi	done
3291.38Suebayasi
3301.40Suebayasi	for _arg in tmplsrcs cppflags copts; do
3311.38Suebayasi		eval get_libgcc_gen_srcs_${_arg} | \
3321.38Suebayasi		eval writefile \$libgcc_srcs_mk_${_arg}
3331.38Suebayasi	done
3341.35Suebayasi}
3351.35Suebayasi
3361.33Suebayasi#####
3371.33Suebayasi
3381.28Suebayasiget_libgcc_new () {
3391.28Suebayasi	_subdir="$1"
3401.44Suebayasi	_abi="$2"
3411.27Suebayasi
3421.29Suebayasi	# List of generated files.
3431.29Suebayasi
3441.46Smrg	_machine_arch_subdir=$_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH/$_abi
3451.27Suebayasi
3461.28Suebayasi	libgcc_db_funcs=${_machine_arch_subdir}/funcs
3471.40Suebayasi	libgcc_db_tmplsrcs=${_machine_arch_subdir}/tmplsrcs
3481.28Suebayasi	libgcc_db_objs_libs=${_machine_arch_subdir}/objs.libs
3491.28Suebayasi	libgcc_db_objs_srcs=${_machine_arch_subdir}/objs.srcs
3501.40Suebayasi	libgcc_db_objs_tmplsrcs=${_machine_arch_subdir}/objs.tmplsrcs
3511.28Suebayasi	libgcc_db_objs_cppflags=${_machine_arch_subdir}/objs.cppflags
3521.28Suebayasi	libgcc_db_objs_copts=${_machine_arch_subdir}/objs.copts
3531.28Suebayasi
3541.44Suebayasi	get_libgcc_new_analyze $_abi
3551.36Suebayasi
3561.39Suebayasi	libgcc_libs_mk=${_machine_arch_subdir}/libs
3571.28Suebayasi	libgcc_srcs_mk=${_machine_arch_subdir}/srcs.mk
3581.40Suebayasi	libgcc_srcs_mk_tmplsrcs=${_machine_arch_subdir}/srcs.tmplsrcs.mk
3591.28Suebayasi	libgcc_srcs_mk_cppflags=${_machine_arch_subdir}/srcs.cppflags.mk
3601.28Suebayasi	libgcc_srcs_mk_copts=${_machine_arch_subdir}/srcs.copts.mk
3611.28Suebayasi
3621.44Suebayasi	get_libgcc_new_generate $_abi
3631.26Suebayasi}
3641.26Suebayasi
3651.1Smrgget_libgcc () {
3661.16Smrg	_subdir="$1"
3671.46Smrg	mkdir -p $_OUTDIR/lib/lib$_subdir/arch
3681.16Smrg
3691.16Smrg	case "$_subdir" in
3701.46Smrg	gcc4|gcc)
3711.16Smrg		_extravars="COLLECT2 UNWIND_H xm_include_list"
3721.16Smrg		_archsubdir=""
3731.16Smrg		;;
3741.16Smrg	esac
3751.1Smrg
3761.1Smrg	# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
3771.4Smrg	# XXX we should probably grab everything Just In Case for
3781.4Smrg	# the future.
3791.16Smrg	{
3801.16Smrg		getvars gcc/Makefile \
3811.16Smrg			INCLUDES LIB2ADD LIB2ADDEH \
3821.16Smrg			LIB1ASMFUNCS LIB1ASMSRC \
3831.16Smrg			LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \
3841.42Suebayasi			LIB2FUNCS_EXTRA \
3851.16Smrg			LIBGCC2_CFLAGS \
3861.16Smrg			SHLIB_MKMAP SHLIB_MKMAP_OPTS \
3871.16Smrg			SHLIB_MAPFILES SHLIB_NM_FLAGS \
3881.16Smrg			EXTRA_HEADERS xm_defines \
3891.16Smrg			tm_defines ${_extravars}
3901.46Smrg	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH.mk
3911.26Suebayasi
3921.26Suebayasi	# Generate new style files.
3931.27Suebayasi	if [ -n "${MKNATIVE_LIBGCC_NEW}" ]; then
3941.44Suebayasi		get_libgcc_new $_subdir $_ABI
3951.26Suebayasi	fi
3961.1Smrg}
3971.1Smrg
3981.24Sskrll##### gnu/lib/libgcov #####
3991.24Sskrll
4001.24Sskrllget_libgcov () {
4011.24Sskrll	_subdir="$1"
4021.24Sskrll
4031.46Smrg	mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH
4041.24Sskrll
4051.24Sskrll	{
4061.24Sskrll		getvars gcc/Makefile \
4071.24Sskrll			LIBGCOV
4081.46Smrg	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/defs.mk
4091.24Sskrll
4101.46Smrg	write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/gcov-iov.h \
4111.24Sskrll	   <$_TMPDIR/gcc/gcov-iov.h
4121.24Sskrll
4131.24Sskrll}
4141.24Sskrll
4151.16Smrg##### gnu/usr.bin/gcc[34]/libiberty #####
4161.1Smrg
4171.16Smrgget_gcc_libiberty () {
4181.16Smrg	_subdir="$1"
4191.46Smrg	case "$_subdir" in
4201.46Smrg	gcc4)
4211.46Smrg		_libibertydir="usr.bin/$_subdir/libiberty"
4221.46Smrg		;;
4231.46Smrg	gcc)
4241.48Smrg		_libibertydir="lib/libiberty"
4251.46Smrg		;;
4261.46Smrg	esac
4271.46Smrg	mkdir -p $_OUTDIR/$_libibertydir/arch/$MACHINE_ARCH
4281.1Smrg
4291.1Smrg	getvars libiberty/Makefile \
4301.1Smrg		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
4311.46Smrg		| write_mk $_OUTDIRBASE/$_libibertydir/defs.mk
4321.1Smrg
4331.46Smrg	write_c $_OUTDIRBASE/$_libibertydir/arch/$MACHINE_ARCH/config.h \
4341.1Smrg		<$_TMPDIR/libiberty/config.h
4351.1Smrg}
4361.1Smrg
4371.51Smrg##### lib/libdecnumber #####
4381.51Smrg
4391.51Smrgget_libdecnumber () {
4401.51Smrg	_subdir="$1"
4411.51Smrg
4421.51Smrg	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
4431.51Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
4441.51Smrg		<$_TMPDIR/libdecnumber/config.h
4451.51Smrg}
4461.51Smrg
4471.1Smrg##### gnu/lib/libobjc #####
4481.1Smrg
4491.1Smrgget_libobjc () {
4501.46Smrg	_subdir="$1/arch/$MACHINE_ARCH"
4511.46Smrg	_options="ALL_OPT_FILES"
4521.46Smrg	_unwind="UNWIND_H"
4531.18Smrg
4541.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir
4551.1Smrg
4561.16Smrg	{
4571.18Smrg		if [ -n "$_options" ]; then
4581.18Smrg			getvars gcc/Makefile $_options
4591.18Smrg		fi
4601.16Smrg		getvars $_PLATFORM/libobjc/Makefile \
4611.16Smrg			ALL_CFLAGS INCLUDES OBJS OBJC_H \
4621.16Smrg			| sed "s,$_GNU_DIST,\${GNUHOSTDIST},g"
4631.20Sskrll		if [ -n "$_unwind" ]; then
4641.20Sskrll			getvars gcc/Makefile $_unwind
4651.20Sskrll		fi
4661.46Smrg	} | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk
4671.23Sskrll
4681.46Smrg	write_c $_OUTDIRBASE/lib/$_subdir/config.h \
4691.23Sskrll		<$_TMPDIR/$_PLATFORM/libobjc/config.h
4701.1Smrg}
4711.1Smrg
4721.1Smrg##### gnu/lib/libstdc++-v3 #####
4731.1Smrg
4741.1Smrgget_libstdcxx_v3 () {
4751.16Smrg	_subdir="$1"
4761.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
4771.1Smrg
4781.16Smrg	case ${_subdir} in
4791.46Smrg	*)
4801.16Smrg		_src_CC_files="atomicity_file CCODECVT_CC CCOLLATE_CC CCTYPE_CC CMESSAGES_CC CMONEY_CC CNUMERIC_CC CTIME_CC CLOCALE_CC BASIC_FILE_CC"
4811.16Smrg		_headers1="host_headers debug_headers tr1_headers c_compatibility_headers_extra"
4821.16Smrg		_headers2="thread_host_headers host_headers_extra"
4831.19Smrg		_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"
4841.20Sskrll		_unwind="UNWIND_H"
4851.16Smrg		;;
4861.16Smrg	esac
4871.16Smrg
4881.19Smrg	# build files
4891.19Smrg	for h in $_build_headers; do
4901.46Smrg		write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/$h \
4911.19Smrg			<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h
4921.19Smrg	done
4931.19Smrg
4941.46Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
4951.6Smrg		<$_TMPDIR/$_PLATFORM/libstdc++-v3/config.h
4961.49Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/gstdint.h \
4971.49Smrg		<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h
4981.49Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/omp.h \
4991.49Smrg		<$_TMPDIR/$_PLATFORM/libgomp/omp.h
5001.6Smrg
5011.1Smrg	{
5021.1Smrg		# libsupc++
5031.1Smrg		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
5041.1Smrg			sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/'
5051.1Smrg		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
5061.1Smrg			c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/'
5071.1Smrg
5081.1Smrg		# src
5091.1Smrg		getvars $_PLATFORM/libstdc++-v3/src/Makefile \
5101.16Smrg			sources $_src_CC_files SECTION_FLAGS | sed 's/^G_sources=/G_SRC_SOURCES=/'
5111.1Smrg
5121.1Smrg		# include
5131.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5141.49Smrg			c_base_headers std_headers | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5151.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5161.1Smrg			bits_headers backward_headers ext_headers c_base_headers_extra \
5171.17Smrg			$_headers1 | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5181.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5191.17Smrg			$_headers2 | sed -e 's#\./[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5201.16Smrg
5211.20Sskrll		if [ -n "$_unwind" ]; then
5221.20Sskrll			getvars gcc/Makefile $_unwind
5231.20Sskrll		fi
5241.46Smrg	} | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/defs.mk
5251.1Smrg}
5261.1Smrg
5271.1Smrg##### gnu/usr.bin/gcc3 #####
5281.1Smrg
5291.1Smrgget_gcc () {
5301.16Smrg	_subdir="$1"
5311.46Smrg	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
5321.47Smrg	mkdir -p $_OUTDIR/usr.bin/$_subdir/libcpp/arch/$MACHINE_ARCH
5331.19Smrg	case ${_subdir} in
5341.19Smrg	gcc4)
5351.19Smrg		_buildname="BUILD_"
5361.19Smrg		_libcppsubdir=""
5371.20Sskrll		_extravars="TM_H ALL_OPT_FILES"
5381.20Sskrll		_hconfig_h=""
5391.20Sskrll		_extravars2="tm_file_list build_xm_include_list"
5401.20Sskrll		_extravars3="tm_p_include_list"
5411.47Smrg		;;
5421.20Sskrll		
5431.47Smrg	gcc)
5441.47Smrg		_buildname="BUILD_"
5451.47Smrg		_libcppsubdir=""
5461.47Smrg		_extravars="TM_H ALL_OPT_FILES"
5471.47Smrg		_hconfig_h=""
5481.47Smrg		_extravars2="tm_file_list build_xm_include_list"
5491.47Smrg		_extravars3="tm_p_include_list"
5501.19Smrg		;;
5511.19Smrg	esac
5521.1Smrg
5531.1Smrg	{
5541.1Smrg		getvars gcc/Makefile \
5551.19Smrg			${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \
5561.19Smrg			${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY | \
5571.16Smrg		    sed -e 's#build/errors.o#build-errors.o#g' \
5581.16Smrg			-e 's#build/print-rtl.o#build-print-rtl.o#g' \
5591.16Smrg			-e 's#build/rtl.o#build-rtl.o#g' \
5601.16Smrg			-e 's#build/varray.o#build-varray.o#g' \
5611.22Smrg			-e 's#build/ggc-none.o#build-ggc-none.o#g' \
5621.16Smrg			-e 's#build/##g'
5631.16Smrg		getvars gcc/Makefile \
5641.1Smrg			ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
5651.20Sskrll			GCOV_OBJS PROTO_OBJS ${_extravars1} \
5661.1Smrg			INCLUDES md_file OBJC_OBJS OBJS out_file version \
5671.20Sskrll			BUILD_PREFIX RTL_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \
5681.1Smrg			GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \
5691.1Smrg			GTFILES GTFILES_LANG_DIR_NAMES \
5701.1Smrg			tm_defines host_xm_file host_xm_defines tm_p_file \
5711.21Smrg			target_cpu_default ${_extravars} ${_extravars2} \
5721.20Sskrll			lang_specs_files ${_extravars3}
5731.1Smrg		getvars gcc/Makefile \
5741.1Smrg			LIB2ADDEHDEP | sed 's/unwind.inc//'
5751.1Smrg		getvars gcc/Makefile \
5761.1Smrg			CXX_OBJS CXX_C_OBJS | sed 's/cp\///g'
5771.1Smrg		getvars gcc/Makefile \
5781.1Smrg			F77_OBJS | sed 's/f\///g'
5791.19Smrg		case ${_subdir} in
5801.51Smrg		gcc4 | gcc)
5811.19Smrg			getvars libcpp/Makefile \
5821.19Smrg				libcpp_a_OBJS
5831.19Smrg			;;
5841.19Smrg		gcc3)
5851.19Smrg			getvars gcc/Makefile \
5861.19Smrg				LIBCPP_OBJS LIBCPP_H
5871.19Smrg			;;
5881.19Smrg		esac
5891.12Sskrll		getvars gcc/Makefile \
5901.16Smrg			ENABLE_SHARED
5911.20Sskrll		case ${_subdir} in
5921.46Smrg		gcc4 | gcc)
5931.20Sskrll			echo G_SHLIB_LINK="$CC -shared"
5941.20Sskrll			echo G_SHLIB_MULTILIB=.
5951.20Sskrll			;;
5961.20Sskrll		esac
5971.46Smrg	} | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/defs.mk
5981.16Smrg
5991.16Smrg	case "$_subdir" in
6001.46Smrg	gcc4)
6011.46Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
6021.46Smrg		hfiles='auto-host gencheck configargs gthr-default tm bconfig config multilib'
6031.16Smrg		;;
6041.46Smrg	gcc)
6051.51Smrg		mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$MACHINE_ARCH
6061.51Smrg		write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
6071.51Smrg		hfiles='auto-host configargs gthr-default tm bconfig config multilib bversion plugin-version'
6081.16Smrg		;;
6091.16Smrg	esac
6101.16Smrg	for f in $hfiles; do
6111.46Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
6121.1Smrg	done
6131.50Smrg
6141.51Smrg	for f in all-tree.def; do
6151.51Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f <$_TMPDIR/gcc/$f
6161.51Smrg	done
6171.1Smrg}
6181.1Smrg
6191.1Smrg##### main #####
6201.1Smrg
6211.16Smrgcase "$1" in
6221.16Smrg# .mk and .h files for libgcc bootstrap (from host build)
6231.16Smrglibgcc)
6241.16Smrg	get_libgcc gcc3
6251.16Smrg	get_crtstuff crtstuff3
6261.16Smrg	exit 0
6271.16Smrg	;;
6281.16Smrg
6291.16Smrglibgcc4)
6301.16Smrg	get_libgcc gcc4
6311.16Smrg	get_crtstuff crtstuff4
6321.16Smrg	exit 0
6331.16Smrg	;;
6341.16Smrg
6351.16Smrg# gcc files
6361.16Smrggcc4)
6371.16Smrg	get_gcc gcc4
6381.16Smrg	get_libgcc gcc4
6391.24Sskrll	get_libgcov gcc4
6401.16Smrg	get_crtstuff crtstuff4
6411.16Smrg	get_gcc_libiberty gcc4
6421.16Smrg	get_libobjc libobjc4
6431.16Smrg	get_libstdcxx_v3 libstdc++-v3_4
6441.1Smrg	exit 0
6451.1Smrg	;;
6461.1Smrg
6471.46Smrggcc45)
6481.46Smrg	_OUTDIR="$_TOP/external/gpl3/gcc"
6491.46Smrg	_OUTDIRBASE="external/gpl3/gcc"
6501.46Smrg	get_gcc gcc
6511.46Smrg	get_libgcc gcc
6521.46Smrg	get_libgcov gcc
6531.46Smrg	get_crtstuff crtstuff
6541.46Smrg	get_gcc_libiberty gcc
6551.46Smrg	get_libobjc libobjc
6561.16Smrg	get_libstdcxx_v3 libstdc++-v3
6571.51Smrg	get_libdecnumber libdecnumber
6581.1Smrg	exit 0
6591.1Smrg	;;
6601.1Smrg
6611.46Smrg
6621.1Smrg*)	echo invalid arguments; exit 1;;
6631.1Smrgesac
664