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