mknative-gcc revision 1.60
11.1Smrg#!/bin/sh
21.60Smrg#	$NetBSD: mknative-gcc,v 1.60 2011/07/03 12:11:32 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.60Smrg_DESTDIR=$6
151.15Smrg_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
161.9Smrg_GNU_DIST=`cd ${_VPATH}; pwd`
171.9Smrg
181.9Smrg. $_TOP/tools/gcc/mknative.common
191.1Smrg
201.46Smrg# default to GCC 4.1 for now
211.46Smrg_OUTDIR="$_TOP/gnu"
221.46Smrg_OUTDIRBASE="gnu"
231.46Smrg
241.14Sthorpej##### gnu/lib/crtstuff #####
251.14Sthorpej
261.14Sthorpejget_crtstuff () {
271.16Smrg	_subdir="$1"
281.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir/arch
291.14Sthorpej
301.14Sthorpej	getvars gcc/Makefile \
311.14Sthorpej		INCLUDES CRTSTUFF_CFLAGS CRTSTUFF_T_CFLAGS \
321.14Sthorpej		tm_defines xm_file xm_defines \
331.60Smrg		| sed "s,-I$_DESTDIR/usr/include,," \
341.46Smrg		| write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH.mk
351.14Sthorpej}
361.14Sthorpej
371.1Smrg##### gnu/lib/libg2c #####
381.1Smrg
391.1Smrgget_libg2c () {
401.46Smrg	mkdir -p $_OUTDIR/lib/libg2c3/arch/$MACHINE_ARCH
411.1Smrg
421.46Smrg	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h
431.46Smrg	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h
441.1Smrg
451.1Smrg	{
461.1Smrg		getvars $_PLATFORM/libf2c/Makefile \
471.1Smrg			F2CEXT
481.1Smrg		getvars $_PLATFORM/libf2c/libF77/Makefile \
491.1Smrg			ALL_CFLAGS OBJS
501.1Smrg		getvars $_PLATFORM/libf2c/libI77/Makefile \
511.1Smrg			ALL_CFLAGS OBJS | sed 's,=,+=,'
521.1Smrg		getvars $_PLATFORM/libf2c/libU77/Makefile \
531.1Smrg			ALL_CFLAGS OBJS | sed 's,=,+=,'
541.46Smrg	} | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/defs.mk
551.1Smrg}
561.1Smrg
571.1Smrg##### gnu/lib/libgcc #####
581.1Smrg
591.28Suebayasiget_libgcc_list_funcs_asm () {
601.42Suebayasi	{
611.42Suebayasi		getvars gcc/Makefile LIB1ASMFUNCS | {
621.42Suebayasi			# print newline separated list
631.42Suebayasi			sed -e '
641.42Suebayasi				s,^.*=,,
651.42Suebayasi				s, *$,,
661.42Suebayasi				s,  *, ,g
671.42Suebayasi				s, ,\
681.28Suebayasi,g'
691.42Suebayasi		}
701.42Suebayasi		getvars gcc/Makefile LIB2FUNCS_EXTRA | {
711.42Suebayasi			# print newline separated list
721.42Suebayasi			sed -e '
731.42Suebayasi				s,^.*=,,
741.42Suebayasi				s, *$,,
751.42Suebayasi				s,  *, ,g
761.42Suebayasi				s, ,\
771.42Suebayasi,g' | \
781.42Suebayasi			sed -ne '
791.42Suebayasi				/\.S$/ { s,^.*/,,; s,\.S$,,; p; }
801.42Suebayasi				/\.asm$/ { s,^.*/,,; s,\.asm$,,; p; }
811.42Suebayasi			'
821.42Suebayasi		}
831.28Suebayasi	} | {
841.28Suebayasi		# print foo and foo_s
851.28Suebayasi		sed -ne '
861.28Suebayasi			/./ {
871.28Suebayasi				p
881.28Suebayasi				s,$,_s,
891.28Suebayasi				p
901.28Suebayasi			}
911.28Suebayasi		'
921.28Suebayasi	} | sort
931.28Suebayasi}
941.28Suebayasi
951.29Suebayasiget_libgcc_list_funcs_lib () {
961.29Suebayasi	local _lib=$1
971.29Suebayasi	local _lib_prefix=${_lib%.*}
981.29Suebayasi	local _lib_suffix=${_lib#*.}
991.44Suebayasi	local _abi=${2:-'\.'}
1001.29Suebayasi
1011.43Suebayasi	cat build/gcc/libgcc.mk | \
1021.44Suebayasi	grep '/'${_abi}'/' | \
1031.29Suebayasi	sed -ne '
1041.45Suebayasi		/^'${_abi}'\/'${_lib_prefix}'\.'${_lib_suffix}': .*\.o$/ {
1051.29Suebayasi			s,^.*/,,
1061.29Suebayasi			s,\.o$,,
1071.29Suebayasi			p
1081.29Suebayasi		}
1091.43Suebayasi	' | sort
1101.29Suebayasi}
1111.29Suebayasi
1121.30Suebayasiget_libgcc_list_objs_libs () {
1131.44Suebayasi	local _abi=${1:-'\.'}
1141.44Suebayasi
1151.30Suebayasi	cat build/gcc/libgcc.mk | \
1161.44Suebayasi	grep '/'${_abi}'/' | \
1171.45Suebayasi	egrep '^'${_abi}'\/(libgcc_s\.so|libgcc\.a|libgcc_eh\.a|libgcov\.a): (libgcc_s|libgcc|libgcc_eh|libgcov)\/.*\.o$' | \
1181.30Suebayasi	sed -e '
1191.44Suebayasi		s,^'${_abi}'\/,,
1201.30Suebayasi		s,: .*/,	,
1211.30Suebayasi		s,^\(.*\)	\(.*\)$,\2	\1,
1221.30Suebayasi	' | sort
1231.30Suebayasi}
1241.30Suebayasi
1251.30Suebayasiget_libgcc_list_objs_srcs () {
1261.44Suebayasi	local _abi=${1:-'\.'}	# XXX not used
1271.44Suebayasi
1281.41Suebayasi	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
1291.30Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1301.30Suebayasi		comm -23 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
1311.30Suebayasi		sed -e 's,\(.*\),\1.o	\1.c,'
1321.30Suebayasi
1331.30Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1341.30Suebayasi		comm -12 /dev/stdin $_TOP/${libgcc_db_funcs}.S | \
1351.30Suebayasi		sed -e 's,\(.*\),\1.o	\1.S,'
1361.41Suebayasi	else
1371.41Suebayasi		cut -f1 $_TOP/${libgcc_db_objs_libs} | sed -e 's,\.o$,,' | \
1381.41Suebayasi		sed -e 's,\(.*\),\1.o	\1.c,'
1391.41Suebayasi	fi | sort
1401.30Suebayasi}
1411.30Suebayasi
1421.40Suebayasiget_libgcc_list_objs_tmplsrcs () {
1431.44Suebayasi	local _abi=${1:-'\.'}
1441.44Suebayasi
1451.32Suebayasi	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
1461.44Suebayasi	grep '/'${_abi}'/' | \
1471.32Suebayasi	sed -ne '
1481.32Suebayasi		s,^.* -c \([^ ]*\).* -o .*/\([^ ]*\.o\)$,\2	\1,
1491.32Suebayasi		# basename
1501.32Suebayasi		/\$/ { s,\$.*/,,; }
1511.32Suebayasi		/\// { s,\/.*/,,; }
1521.32Suebayasi		p
1531.43Suebayasi	' | sort -u
1541.32Suebayasi}
1551.32Suebayasi
1561.31Suebayasiget_libgcc_list_objs_xflags () {
1571.31Suebayasi	local _flags=$1
1581.44Suebayasi	local _abi=${2:-'\.'}
1591.31Suebayasi
1601.31Suebayasi	grep 'GCC_FOR_TARGET.*\.o$' build/gcc/libgcc.mk | \
1611.44Suebayasi	grep '/'${_abi}'/' | \
1621.31Suebayasi	sed -n '
1631.31Suebayasi		x
1641.31Suebayasi	:loop
1651.31Suebayasi		g
1661.31Suebayasi		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\5	\2/p
1671.31Suebayasi		g
1681.31Suebayasi		s/^\(.*\) \(-['${_flags}'][^ ][^ ]*\) \(.*\) \(-o .*\)\/\(.*\.o\)$/\1 \3 \4\/\5/
1691.31Suebayasi		h
1701.31Suebayasi		t loop
1711.31Suebayasi	' | sort
1721.31Suebayasi}
1731.31Suebayasi
1741.31Suebayasiget_libgcc_list_objs_cppflags () {
1751.44Suebayasi	get_libgcc_list_objs_xflags D $1
1761.31Suebayasi}
1771.31Suebayasi
1781.31Suebayasiget_libgcc_list_objs_copts () {
1791.44Suebayasi	get_libgcc_list_objs_xflags fmx $1
1801.31Suebayasi}
1811.31Suebayasi
1821.40Suebayasiget_libgcc_list_tmplsrcs () {
1831.33Suebayasi	local _lib=$1
1841.44Suebayasi	local _abi=$2	# XXX not used
1851.40Suebayasi	local _tmplallsrcs=$( mktemp /tmp/mknative-gcc._tmplallsrcs.XXXXXX )
1861.33Suebayasi
1871.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
1881.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
1891.40Suebayasi	touch $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
1901.33Suebayasi
1911.33Suebayasi	# all files
1921.33Suebayasi	local _lib_prefix=${_lib%.*}
1931.33Suebayasi	local _lib_suffix=${_lib#*.}
1941.40Suebayasi	join $_TOP/$libgcc_db_objs_libs $_TOP/$libgcc_db_objs_tmplsrcs | \
1951.33Suebayasi	grep ${_lib_prefix}'\.'${_lib_suffix} | cut -d' ' -f 3 | sort -u > \
1961.40Suebayasi	$_tmplallsrcs
1971.33Suebayasi
1981.40Suebayasi	# TMPLFPSRCS = [fdp]p-bit.c
1991.40Suebayasi	grep '[fdt]p-bit\.c' <$_tmplallsrcs | sort -u | \
2001.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
2011.40Suebayasi
2021.40Suebayasi	# TMPLASMSRCS = $(LIB1ASMSRC)
2031.40Suebayasi	grep '\$(LIB1ASMSRC)' <$_tmplallsrcs | sort -u | \
2041.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*}
2051.40Suebayasi
2061.40Suebayasi	# TMPLSRCS is anything else; exclude TMPLFPSRCS and TMPLASMSRCS
2071.40Suebayasi	cat $_tmplallsrcs | \
2081.40Suebayasi	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*} | \
2091.40Suebayasi	comm -23 /dev/stdin $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
2101.40Suebayasi	writefile ${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
2111.33Suebayasi
2121.40Suebayasi	rm -f $_tmplallsrcs
2131.33Suebayasi}
2141.33Suebayasi
2151.35Suebayasiget_libgcc_new_analyze () {
2161.44Suebayasi	local _abi=$1
2171.44Suebayasi
2181.35Suebayasi	mkdir -p $_TOP/${_machine_arch_subdir}
2191.35Suebayasi
2201.41Suebayasi	touch $_TOP/${libgcc_db_funcs}.S
2211.35Suebayasi	get_libgcc_list_funcs_asm | \
2221.35Suebayasi	writefile ${libgcc_db_funcs}.S
2231.35Suebayasi
2241.35Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
2251.41Suebayasi		touch $_TOP/${libgcc_db_funcs}.${_lib%.*}
2261.44Suebayasi		get_libgcc_list_funcs_lib $_lib $_abi | \
2271.35Suebayasi		writefile ${libgcc_db_funcs}.${_lib%.*}
2281.35Suebayasi	done
2291.35Suebayasi
2301.44Suebayasi	get_libgcc_list_objs_libs $_abi | writefile ${libgcc_db_objs_libs}
2311.44Suebayasi	get_libgcc_list_objs_srcs $_abi | writefile ${libgcc_db_objs_srcs}
2321.44Suebayasi	get_libgcc_list_objs_tmplsrcs $_abi | writefile ${libgcc_db_objs_tmplsrcs}
2331.44Suebayasi	get_libgcc_list_objs_cppflags $_abi | writefile ${libgcc_db_objs_cppflags}
2341.44Suebayasi	get_libgcc_list_objs_copts $_abi | writefile ${libgcc_db_objs_copts}
2351.35Suebayasi
2361.35Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
2371.44Suebayasi		get_libgcc_list_tmplsrcs $_lib $_abi
2381.35Suebayasi	done
2391.35Suebayasi}
2401.35Suebayasi
2411.35Suebayasi#####
2421.35Suebayasi
2431.40Suebayasiget_libgcc_gen_tmplsrcs_tmplsrcs () {
2441.37Suebayasi	local _lib=$1
2451.37Suebayasi
2461.37Suebayasi	printf '\n'
2471.40Suebayasi	printf 'TMPLSRCS.%s = \\\n' $_lib
2481.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplsrcs.${_lib%.*}
2491.37Suebayasi}
2501.37Suebayasi
2511.40Suebayasiget_libgcc_gen_tmplsrcs_tmplfpsrcs () {
2521.37Suebayasi	local _lib=$1
2531.37Suebayasi
2541.37Suebayasi	printf '\n'
2551.40Suebayasi	printf 'TMPLFPSRCS.%s = \\\n' $_lib
2561.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplfpsrcs.${_lib%.*}
2571.37Suebayasi}
2581.37Suebayasi
2591.40Suebayasiget_libgcc_gen_tmplsrcs_tmplasmsrcs () {
2601.37Suebayasi	local _lib=$1
2611.37Suebayasi
2621.37Suebayasi	printf '\n'
2631.40Suebayasi	printf 'TMPLASMSRCS.%s = \\\n' $_lib
2641.40Suebayasi	sed -e 's,^,	,; s,$, \\,' $_TOP/${libgcc_db_tmplsrcs}.tmplasmsrcs.${_lib%.*} | \
2651.37Suebayasi	sed -e 's,LIB1ASMSRC,G_&,'
2661.37Suebayasi}
2671.37Suebayasi
2681.36Suebayasiget_libgcc_gen_srcs () {
2691.36Suebayasi	local _lib=$1
2701.36Suebayasi
2711.36Suebayasi	printf '\n'
2721.36Suebayasi	printf 'SRCS.%s = \\\n' $_lib
2731.41Suebayasi	if [ -e $_TOP/${libgcc_db_funcs}.S ]; then
2741.36Suebayasi		comm -23 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
2751.36Suebayasi		sed -e 's,$,.c,; s,^,tmp_,'
2761.36Suebayasi		comm -12 $_TOP/${libgcc_db_funcs}.${_lib%.*} $_TOP/${libgcc_db_funcs}.S | \
2771.36Suebayasi		sed -e 's,$,.S,; s,^,tmp_,'
2781.41Suebayasi	else
2791.41Suebayasi		cat $_TOP/${libgcc_db_funcs}.${_lib%.*} | \
2801.41Suebayasi		sed -e 's,$,.c,; s,^,tmp_,'
2811.41Suebayasi	fi | sort | \
2821.36Suebayasi	sed -e 's,^,	,; s,$, \\,'
2831.36Suebayasi}
2841.36Suebayasi
2851.38Suebayasi_lookup_objs () {
2861.38Suebayasi	local _obj=$1; local _key=$2
2871.38Suebayasi
2881.38Suebayasi	eval grep \^$_obj\\\	 \$_TOP/\${libgcc_db_objs_${_key}} | cut -f2
2891.38Suebayasi}
2901.38Suebayasi
2911.40Suebayasiget_libgcc_gen_srcs_tmplsrcs () {
2921.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
2931.38Suebayasi	while read _obj; do
2941.38Suebayasi		printf 'SRCS.tmp_%s=%s\n' \
2951.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
2961.40Suebayasi			"$( _lookup_objs $_obj tmplsrcs )"
2971.38Suebayasi	done | \
2981.38Suebayasi	sed -e 's,\$(\(.*\)),${G_\1},'
2991.38Suebayasi}
3001.38Suebayasi
3011.38Suebayasiget_libgcc_gen_srcs_cppflags () {
3021.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
3031.38Suebayasi	while read _obj; do
3041.38Suebayasi		printf '_CPPFLAGS.tmp_%s=%s\n' \
3051.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
3061.38Suebayasi			"$( _lookup_objs $_obj cppflags | xargs )"
3071.38Suebayasi	done
3081.38Suebayasi}
3091.38Suebayasi
3101.38Suebayasiget_libgcc_gen_srcs_copts () {
3111.38Suebayasi	cut -f1 $_TOP/${libgcc_db_objs_libs} | \
3121.38Suebayasi	while read _obj; do
3131.38Suebayasi		printf 'COPTS.tmp_%s=%s\n' \
3141.38Suebayasi			"$( _lookup_objs $_obj srcs )" \
3151.38Suebayasi			"$( _lookup_objs $_obj copts | xargs )"
3161.38Suebayasi	done
3171.38Suebayasi}
3181.38Suebayasi
3191.35Suebayasiget_libgcc_new_generate () {
3201.44Suebayasi	local _abi=$1
3211.44Suebayasi
3221.36Suebayasi	for _lib in libgcc_s.so libgcc.a libgcc_eh.a libgcov.a; do
3231.40Suebayasi		for _tmpl in tmplsrcs tmplfpsrcs tmplasmsrcs; do
3241.40Suebayasi			eval get_libgcc_gen_tmplsrcs_${_tmpl} $_lib | \
3251.40Suebayasi			write_mk ${libgcc_libs_mk}.${_lib%.*}.tmplsrcs.${_tmpl}.mk
3261.37Suebayasi		done
3271.37Suebayasi
3281.36Suebayasi		get_libgcc_gen_srcs $_lib | \
3291.39Suebayasi		write_mk ${libgcc_libs_mk}.${_lib%.*}.srcs.mk
3301.36Suebayasi	done
3311.38Suebayasi
3321.40Suebayasi	for _arg in tmplsrcs cppflags copts; do
3331.38Suebayasi		eval get_libgcc_gen_srcs_${_arg} | \
3341.38Suebayasi		eval writefile \$libgcc_srcs_mk_${_arg}
3351.38Suebayasi	done
3361.35Suebayasi}
3371.35Suebayasi
3381.33Suebayasi#####
3391.33Suebayasi
3401.28Suebayasiget_libgcc_new () {
3411.28Suebayasi	_subdir="$1"
3421.44Suebayasi	_abi="$2"
3431.27Suebayasi
3441.29Suebayasi	# List of generated files.
3451.29Suebayasi
3461.46Smrg	_machine_arch_subdir=$_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH/$_abi
3471.27Suebayasi
3481.28Suebayasi	libgcc_db_funcs=${_machine_arch_subdir}/funcs
3491.40Suebayasi	libgcc_db_tmplsrcs=${_machine_arch_subdir}/tmplsrcs
3501.28Suebayasi	libgcc_db_objs_libs=${_machine_arch_subdir}/objs.libs
3511.28Suebayasi	libgcc_db_objs_srcs=${_machine_arch_subdir}/objs.srcs
3521.40Suebayasi	libgcc_db_objs_tmplsrcs=${_machine_arch_subdir}/objs.tmplsrcs
3531.28Suebayasi	libgcc_db_objs_cppflags=${_machine_arch_subdir}/objs.cppflags
3541.28Suebayasi	libgcc_db_objs_copts=${_machine_arch_subdir}/objs.copts
3551.28Suebayasi
3561.44Suebayasi	get_libgcc_new_analyze $_abi
3571.36Suebayasi
3581.39Suebayasi	libgcc_libs_mk=${_machine_arch_subdir}/libs
3591.28Suebayasi	libgcc_srcs_mk=${_machine_arch_subdir}/srcs.mk
3601.40Suebayasi	libgcc_srcs_mk_tmplsrcs=${_machine_arch_subdir}/srcs.tmplsrcs.mk
3611.28Suebayasi	libgcc_srcs_mk_cppflags=${_machine_arch_subdir}/srcs.cppflags.mk
3621.28Suebayasi	libgcc_srcs_mk_copts=${_machine_arch_subdir}/srcs.copts.mk
3631.28Suebayasi
3641.44Suebayasi	get_libgcc_new_generate $_abi
3651.26Suebayasi}
3661.26Suebayasi
3671.1Smrgget_libgcc () {
3681.16Smrg	_subdir="$1"
3691.46Smrg	mkdir -p $_OUTDIR/lib/lib$_subdir/arch
3701.16Smrg
3711.16Smrg	case "$_subdir" in
3721.46Smrg	gcc4|gcc)
3731.16Smrg		_extravars="COLLECT2 UNWIND_H xm_include_list"
3741.16Smrg		_archsubdir=""
3751.16Smrg		;;
3761.16Smrg	esac
3771.1Smrg
3781.1Smrg	# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
3791.4Smrg	# XXX we should probably grab everything Just In Case for
3801.4Smrg	# the future.
3811.16Smrg	{
3821.16Smrg		getvars gcc/Makefile \
3831.58Smrg			INCLUDES LIB2ADD LIB2ADDEH LIB2ADD_ST \
3841.16Smrg			LIB1ASMFUNCS LIB1ASMSRC \
3851.16Smrg			LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \
3861.42Suebayasi			LIB2FUNCS_EXTRA \
3871.16Smrg			LIBGCC2_CFLAGS \
3881.16Smrg			SHLIB_MKMAP SHLIB_MKMAP_OPTS \
3891.16Smrg			SHLIB_MAPFILES SHLIB_NM_FLAGS \
3901.16Smrg			EXTRA_HEADERS xm_defines \
3911.16Smrg			tm_defines ${_extravars}
3921.60Smrg	} | sed "s,-I$_DESTDIR/usr/include,," \
3931.60Smrg	| write_mk $_OUTDIRBASE/lib/lib$_subdir/arch${_archsubdir}/$MACHINE_ARCH.mk
3941.26Suebayasi
3951.26Suebayasi	# Generate new style files.
3961.27Suebayasi	if [ -n "${MKNATIVE_LIBGCC_NEW}" ]; then
3971.44Suebayasi		get_libgcc_new $_subdir $_ABI
3981.26Suebayasi	fi
3991.1Smrg}
4001.1Smrg
4011.24Sskrll##### gnu/lib/libgcov #####
4021.24Sskrll
4031.24Sskrllget_libgcov () {
4041.24Sskrll	_subdir="$1"
4051.24Sskrll
4061.46Smrg	mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH
4071.24Sskrll
4081.24Sskrll	{
4091.24Sskrll		getvars gcc/Makefile \
4101.24Sskrll			LIBGCOV
4111.46Smrg	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/defs.mk
4121.24Sskrll
4131.46Smrg	write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/gcov-iov.h \
4141.24Sskrll	   <$_TMPDIR/gcc/gcov-iov.h
4151.24Sskrll
4161.24Sskrll}
4171.24Sskrll
4181.16Smrg##### gnu/usr.bin/gcc[34]/libiberty #####
4191.1Smrg
4201.16Smrgget_gcc_libiberty () {
4211.16Smrg	_subdir="$1"
4221.46Smrg	case "$_subdir" in
4231.46Smrg	gcc4)
4241.46Smrg		_libibertydir="usr.bin/$_subdir/libiberty"
4251.46Smrg		;;
4261.46Smrg	gcc)
4271.48Smrg		_libibertydir="lib/libiberty"
4281.46Smrg		;;
4291.46Smrg	esac
4301.46Smrg	mkdir -p $_OUTDIR/$_libibertydir/arch/$MACHINE_ARCH
4311.1Smrg
4321.1Smrg	getvars libiberty/Makefile \
4331.1Smrg		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
4341.46Smrg		| write_mk $_OUTDIRBASE/$_libibertydir/defs.mk
4351.1Smrg
4361.46Smrg	write_c $_OUTDIRBASE/$_libibertydir/arch/$MACHINE_ARCH/config.h \
4371.1Smrg		<$_TMPDIR/libiberty/config.h
4381.1Smrg}
4391.1Smrg
4401.51Smrg##### lib/libdecnumber #####
4411.51Smrg
4421.51Smrgget_libdecnumber () {
4431.51Smrg	_subdir="$1"
4441.51Smrg
4451.52Smrg	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
4461.52Smrg	write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/config.h \
4471.51Smrg		<$_TMPDIR/libdecnumber/config.h
4481.51Smrg}
4491.51Smrg
4501.1Smrg##### gnu/lib/libobjc #####
4511.1Smrg
4521.1Smrgget_libobjc () {
4531.46Smrg	_subdir="$1/arch/$MACHINE_ARCH"
4541.46Smrg	_options="ALL_OPT_FILES"
4551.46Smrg	_unwind="UNWIND_H"
4561.18Smrg
4571.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir
4581.1Smrg
4591.16Smrg	{
4601.18Smrg		if [ -n "$_options" ]; then
4611.18Smrg			getvars gcc/Makefile $_options
4621.18Smrg		fi
4631.16Smrg		getvars $_PLATFORM/libobjc/Makefile \
4641.16Smrg			ALL_CFLAGS INCLUDES OBJS OBJC_H \
4651.16Smrg			| sed "s,$_GNU_DIST,\${GNUHOSTDIST},g"
4661.20Sskrll		if [ -n "$_unwind" ]; then
4671.20Sskrll			getvars gcc/Makefile $_unwind
4681.20Sskrll		fi
4691.46Smrg	} | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk
4701.23Sskrll
4711.46Smrg	write_c $_OUTDIRBASE/lib/$_subdir/config.h \
4721.23Sskrll		<$_TMPDIR/$_PLATFORM/libobjc/config.h
4731.1Smrg}
4741.1Smrg
4751.1Smrg##### gnu/lib/libstdc++-v3 #####
4761.1Smrg
4771.1Smrgget_libstdcxx_v3 () {
4781.16Smrg	_subdir="$1"
4791.46Smrg	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
4801.1Smrg
4811.16Smrg	case ${_subdir} in
4821.46Smrg	*)
4831.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"
4841.55Smrg		_headers1="host_headers debug_headers tr1_headers c_compatibility_headers_extra tr1_impl_headers parallel_headers decimal_headers"
4851.55Smrg		_headers2="thread_host_headers host_headers_extra"
4861.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"
4871.20Sskrll		_unwind="UNWIND_H"
4881.16Smrg		;;
4891.16Smrg	esac
4901.16Smrg
4911.19Smrg	# build files
4921.19Smrg	for h in $_build_headers; do
4931.46Smrg		write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/$h \
4941.19Smrg			<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h
4951.19Smrg	done
4961.19Smrg
4971.46Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
4981.6Smrg		<$_TMPDIR/$_PLATFORM/libstdc++-v3/config.h
4991.49Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/gstdint.h \
5001.49Smrg		<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h
5011.49Smrg	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/omp.h \
5021.49Smrg		<$_TMPDIR/$_PLATFORM/libgomp/omp.h
5031.6Smrg
5041.1Smrg	{
5051.1Smrg		# libsupc++
5061.1Smrg		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
5071.1Smrg			sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/'
5081.1Smrg		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
5091.1Smrg			c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/'
5101.1Smrg
5111.1Smrg		# src
5121.1Smrg		getvars $_PLATFORM/libstdc++-v3/src/Makefile \
5131.16Smrg			sources $_src_CC_files SECTION_FLAGS | sed 's/^G_sources=/G_SRC_SOURCES=/'
5141.1Smrg
5151.1Smrg		# include
5161.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5171.49Smrg			c_base_headers std_headers | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5181.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5191.1Smrg			bits_headers backward_headers ext_headers c_base_headers_extra \
5201.17Smrg			$_headers1 | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5211.1Smrg		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
5221.17Smrg			$_headers2 | sed -e 's#\./[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'
5231.16Smrg
5241.20Sskrll		if [ -n "$_unwind" ]; then
5251.20Sskrll			getvars gcc/Makefile $_unwind
5261.20Sskrll		fi
5271.46Smrg	} | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/defs.mk
5281.1Smrg}
5291.1Smrg
5301.1Smrg##### gnu/usr.bin/gcc3 #####
5311.1Smrg
5321.1Smrgget_gcc () {
5331.16Smrg	_subdir="$1"
5341.46Smrg	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
5351.57Smrg	mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$MACHINE_ARCH
5361.19Smrg	case ${_subdir} in
5371.19Smrg	gcc4)
5381.19Smrg		_buildname="BUILD_"
5391.19Smrg		_libcppsubdir=""
5401.20Sskrll		_extravars="TM_H ALL_OPT_FILES"
5411.20Sskrll		_hconfig_h=""
5421.20Sskrll		_extravars2="tm_file_list build_xm_include_list"
5431.20Sskrll		_extravars3="tm_p_include_list"
5441.47Smrg		;;
5451.20Sskrll		
5461.47Smrg	gcc)
5471.47Smrg		_buildname="BUILD_"
5481.47Smrg		_libcppsubdir=""
5491.47Smrg		_extravars="TM_H ALL_OPT_FILES"
5501.47Smrg		_hconfig_h=""
5511.47Smrg		_extravars2="tm_file_list build_xm_include_list"
5521.47Smrg		_extravars3="tm_p_include_list"
5531.19Smrg		;;
5541.19Smrg	esac
5551.1Smrg
5561.1Smrg	{
5571.1Smrg		getvars gcc/Makefile \
5581.19Smrg			${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \
5591.19Smrg			${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY | \
5601.16Smrg		    sed -e 's#build/errors.o#build-errors.o#g' \
5611.16Smrg			-e 's#build/print-rtl.o#build-print-rtl.o#g' \
5621.16Smrg			-e 's#build/rtl.o#build-rtl.o#g' \
5631.16Smrg			-e 's#build/varray.o#build-varray.o#g' \
5641.22Smrg			-e 's#build/ggc-none.o#build-ggc-none.o#g' \
5651.16Smrg			-e 's#build/##g'
5661.16Smrg		getvars gcc/Makefile \
5671.1Smrg			ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
5681.20Sskrll			GCOV_OBJS PROTO_OBJS ${_extravars1} \
5691.1Smrg			INCLUDES md_file OBJC_OBJS OBJS out_file version \
5701.20Sskrll			BUILD_PREFIX RTL_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \
5711.1Smrg			GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \
5721.1Smrg			GTFILES GTFILES_LANG_DIR_NAMES \
5731.1Smrg			tm_defines host_xm_file host_xm_defines tm_p_file \
5741.21Smrg			target_cpu_default ${_extravars} ${_extravars2} \
5751.60Smrg			lang_specs_files ${_extravars3} \
5761.60Smrg				| sed "s,-I$_DESTDIR/usr/include,," \
5771.1Smrg		getvars gcc/Makefile \
5781.1Smrg			LIB2ADDEHDEP | sed 's/unwind.inc//'
5791.1Smrg		getvars gcc/Makefile \
5801.1Smrg			CXX_OBJS CXX_C_OBJS | sed 's/cp\///g'
5811.1Smrg		getvars gcc/Makefile \
5821.1Smrg			F77_OBJS | sed 's/f\///g'
5831.19Smrg		case ${_subdir} in
5841.51Smrg		gcc4 | gcc)
5851.19Smrg			getvars libcpp/Makefile \
5861.19Smrg				libcpp_a_OBJS
5871.19Smrg			;;
5881.19Smrg		gcc3)
5891.19Smrg			getvars gcc/Makefile \
5901.19Smrg				LIBCPP_OBJS LIBCPP_H
5911.19Smrg			;;
5921.19Smrg		esac
5931.12Sskrll		getvars gcc/Makefile \
5941.16Smrg			ENABLE_SHARED
5951.20Sskrll		case ${_subdir} in
5961.46Smrg		gcc4 | gcc)
5971.20Sskrll			echo G_SHLIB_LINK="$CC -shared"
5981.20Sskrll			echo G_SHLIB_MULTILIB=.
5991.20Sskrll			;;
6001.20Sskrll		esac
6011.46Smrg	} | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/defs.mk
6021.16Smrg
6031.16Smrg	case "$_subdir" in
6041.46Smrg	gcc4)
6051.46Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
6061.46Smrg		hfiles='auto-host gencheck configargs gthr-default tm bconfig config multilib'
6071.16Smrg		;;
6081.46Smrg	gcc)
6091.51Smrg		write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
6101.51Smrg		hfiles='auto-host configargs gthr-default tm bconfig config multilib bversion plugin-version'
6111.16Smrg		;;
6121.16Smrg	esac
6131.16Smrg	for f in $hfiles; do
6141.46Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
6151.1Smrg	done
6161.50Smrg
6171.56Smrg	# keep identical
6181.56Smrg	for f in all-tree.def; do
6191.53Smrg		cp $_TMPDIR/gcc/$f $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
6201.51Smrg	done
6211.56Smrg
6221.56Smrg	# special transforms
6231.56Smrg	for f in gtyp-input.list; do
6241.56Smrg		sed -e 's/^.*external\/gpl3\/gcc\/dist/SRCDIR/' < $_TMPDIR/gcc/$f > $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
6251.56Smrg	done
6261.59Smrg
6271.59Smrg	# special platforms
6281.59Smrg	if [ "${MACHINE_ARCH}" = "sh3el" -o "${MACHINE_ARCH}" = "sh3eb" ]; then
6291.59Smrg		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/sysroot-suffix.h <$_TMPDIR/gcc/sysroot-suffix.h
6301.59Smrg	fi
6311.1Smrg}
6321.1Smrg
6331.1Smrg##### main #####
6341.1Smrg
6351.16Smrgcase "$1" in
6361.16Smrg# .mk and .h files for libgcc bootstrap (from host build)
6371.16Smrglibgcc)
6381.16Smrg	get_libgcc gcc3
6391.16Smrg	get_crtstuff crtstuff3
6401.16Smrg	exit 0
6411.16Smrg	;;
6421.16Smrg
6431.16Smrglibgcc4)
6441.16Smrg	get_libgcc gcc4
6451.16Smrg	get_crtstuff crtstuff4
6461.16Smrg	exit 0
6471.16Smrg	;;
6481.16Smrg
6491.16Smrg# gcc files
6501.16Smrggcc4)
6511.16Smrg	get_gcc gcc4
6521.16Smrg	get_libgcc gcc4
6531.24Sskrll	get_libgcov gcc4
6541.16Smrg	get_crtstuff crtstuff4
6551.16Smrg	get_gcc_libiberty gcc4
6561.16Smrg	get_libobjc libobjc4
6571.16Smrg	get_libstdcxx_v3 libstdc++-v3_4
6581.1Smrg	exit 0
6591.1Smrg	;;
6601.1Smrg
6611.46Smrggcc45)
6621.46Smrg	_OUTDIR="$_TOP/external/gpl3/gcc"
6631.46Smrg	_OUTDIRBASE="external/gpl3/gcc"
6641.46Smrg	get_gcc gcc
6651.46Smrg	get_libgcc gcc
6661.46Smrg	get_libgcov gcc
6671.46Smrg	get_crtstuff crtstuff
6681.46Smrg	get_gcc_libiberty gcc
6691.46Smrg	get_libobjc libobjc
6701.16Smrg	get_libstdcxx_v3 libstdc++-v3
6711.51Smrg	get_libdecnumber libdecnumber
6721.1Smrg	exit 0
6731.1Smrg	;;
6741.1Smrg
6751.46Smrg
6761.1Smrg*)	echo invalid arguments; exit 1;;
6771.1Smrgesac
678