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