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