NetBSD/gnu/toolchain2netbsd
mrg e10f2bf04d - get SIM_OBS for GDB.
- build a usr.bin/sim/arch tree, copy sim/ppc/config.h there for powerpc.
2002-01-22 13:13:00 +00:00

302 lines
8.1 KiB
Bash

#!/bin/sh
# $NetBSD: toolchain2netbsd,v 1.14 2002/01/22 13:13:00 mrg Exp $
#
# Shell script for generating all the constants needed for a native
# platform build of src/gnu/dist/toolchain.
#
TMPDIR=${TMPDIR:-/tmp}
MAKE=${MAKE:-make}
# usage: getvars MAKEFILE VARNAME [VARNAME...]
getvars () {
_mf="$1"; shift
$MAKE -f - _x_ <<EOF || { echo >&2 "ABORT: getvars $_mf $* failed"; exit 1; }
_x_:
.for var in $*
@echo G_\${var}=\${\${var}:Q} | sed 's,$_VPATH,\$\${DIST},g'
.endfor
.include "$_TMPDIR/$_mf"
EOF
}
# usage: write_c FILENAME
write_c () {
echo '/* This file is automatically generated. DO NOT EDIT! */' >$1.tmp || \
{ echo >&2 "ABORT: cannot create $1"; exit 1; }
grep '$''NetBSD' toolchain2netbsd | sed 's,[#$],,g;s,.*,/* Generated from: & */,' >>$1.tmp
echo '' >>$1.tmp
writefile $1
}
# usage: write_mk FILENAME
write_mk () {
echo '# This file is automatically generated. DO NOT EDIT!' >$1.tmp || \
{ echo >&2 "ABORT: cannot create $1"; exit 1; }
grep '$''NetBSD' toolchain2netbsd | sed 's,[#$],,g;s,.*,# Generated from: &,' >>$1.tmp
echo '#' >>$1.tmp
writefile $1
}
writefile () {
sed 's,netbsd\(elf\)*1[0-9\.]*\(_\)*[A-Z]*,netbsd\1,' >>$1.tmp
# will not overwrite a file that has the same content
if cmp $1.tmp $1 >/dev/null 2>&1; then
echo >&2 "$1 is unchanged"
rm -f $1.tmp
else
mv -f $1.tmp $1
fi
}
##### run GNU configure script #####
_TMPDIR=${TMPDIR:-/tmp}/gnu.dist.toolchain.tmp
MACHINE_ARCH=`sysctl -n hw.machine_arch`
cwd=`pwd`
# Basic configuration.
if [ ! -f $_TMPDIR/gprof/Makefile ]; then
(mkdir -p $_TMPDIR && cd $_TMPDIR && \
LDFLAGS=-lintl LANGUAGES="c c++ objc f77" \
$cwd/dist/toolchain/configure --disable-shared)
fi
# Library configuration, for after g++ or g77 are installed.
if [ "`cc --version 2>/dev/null`" = "2.95.3" ]; then
touch $_TMPDIR/tree-check.h # for libf2c
export objc_cv_thread_file=single # for libobjc
for dir in libf2c libio libobjc libstdc++; do
if [ ! -f $_TMPDIR/$dir/Makefile ]; then
(mkdir -p $_TMPDIR/$dir && cd $_TMPDIR/$dir && \
export CC="gcc -idirafter $_TMPDIR -idirafter $cwd/usr.bin/gcc/arch/$MACHINE_ARCH" && \
if [ -f $cwd/dist/toolchain/$dir/configure ]; then
$cwd/dist/toolchain/$dir/configure --disable-shared
else
$cwd/dist/toolchain/configure --srcdir=$cwd/dist/toolchain/$dir --disable-shared
fi)
fi
done
if [ ! -f $_TMPDIR/libio/_G_config.h ]; then
(cd $_TMPDIR/libio && \
$cwd/dist/toolchain/libio/gen-params >tmp-config.h && \
mv tmp-config.h _G_config.h)
fi
have_new_gcc=yes
fi
_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*= ,,'`
##### gnu/lib/libbfd #####
mkdir -p lib/libbfd/arch/$MACHINE_ARCH
{
getvars bfd/Makefile \
libbfd_la_DEPENDENCIES libbfd_la_OBJECTS DEFS INCLUDES TDEFAULTS
getvars opcodes/Makefile \
archdefs BFD_MACHINES libopcodes_la_SOURCES
} | write_mk lib/libbfd/arch/$MACHINE_ARCH/defs.mk
(cd $_TMPDIR/bfd && $MAKE bfd.h)
write_c lib/libbfd/arch/$MACHINE_ARCH/bfd.h <$_TMPDIR/bfd/bfd.h
{
cat $_TMPDIR/bfd/config.h
grep -v PACKAGE $_TMPDIR/opcodes/config.h
} | write_c lib/libbfd/arch/$MACHINE_ARCH/config.h
##### gnu/lib/libf2c #####
if [ "$have_new_gcc" = "yes" ]; then
mkdir -p lib/libg2c/arch/$MACHINE_ARCH
write_c lib/libg2c/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libf2c/libU77/config.h
write_c lib/libg2c/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/libf2c/g2c.h
{
getvars libf2c/Makefile \
F2CEXT
getvars libf2c/libF77/Makefile \
ALL_CFLAGS OBJS
getvars libf2c/libI77/Makefile \
ALL_CFLAGS OBJ | sed 's,=,+=,'
getvars libf2c/libU77/Makefile \
ALL_CFLAGS OBJS | sed 's,=,+=,'
} | write_mk lib/libg2c/arch/$MACHINE_ARCH/defs.mk
fi
##### gnu/lib/libgcc #####
# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
getvars gcc/Makefile \
CXX_EXTRA_HEADERS CXX_LIB2FUNCS CXX_LIB2SRCS \
INCLUDES LIB2ADD LIB2FUNCS LIB2FUNCS_EH \
LIBGCC2_CFLAGS MAYBE_USE_COLLECT2 \
| write_mk lib/libgcc/$MACHINE_ARCH.mk
##### gnu/lib/libiberty #####
mkdir -p lib/libiberty/arch/$MACHINE_ARCH
getvars libiberty/Makefile \
ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
| write_mk lib/libiberty/arch/$MACHINE_ARCH/defs.mk
write_c lib/libiberty/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libiberty/config.h
##### gnu/lib/libobjc #####
if [ "$have_new_gcc" = "yes" ]; then
getvars libobjc/Makefile \
ALL_CFLAGS INCLUDES OBJS \
| write_mk lib/libobjc/$MACHINE_ARCH.mk
getvars libobjc/Makefile \
OBJC_H \
| write_mk lib/libobjc/defs.mk
fi
##### gnu/lib/libstdc++ #####
if [ "$have_new_gcc" = "yes" ]; then
mkdir -p lib/libstdc++/arch/$MACHINE_ARCH
(cd $_TMPDIR/libiberty && $MAKE needed-list)
write_c lib/libstdc++/arch/$MACHINE_ARCH/_G_config.h <$_TMPDIR/libio/_G_config.h
{
getvars libio/Makefile \
CINCLUDES LIBIOSTREAM_USE MT_CFLAGS XCFLAGS XCXXFLAGS
# Ugly hack for backticks:
(cd $_TMPDIR/libstdc++ && \
printf 'x:\n\t@echo G_LIBIBERTY_OBJS=${LIBIBERTY_OBJS}\n.include "Makefile"' | $MAKE -f - x)
getvars libstdc++/Makefile \
COMFUNCS COMIO CXXINCLUDES HEADERS OBJS STRFUNCS STRIO
(cd dist/toolchain/libstdc++ && echo 'STD_HEADERS=' *.h std/*.h std/*.cc std/*.tcc)
(cd dist/toolchain/libstdc++/stl && echo 'STL_HEADERS=' *.h)
(cd dist/toolchain/libio && echo 'LIBIO_HEADERS=' *.h)
} | write_mk lib/libstdc++/arch/$MACHINE_ARCH/defs.mk
fi
##### gnu/usr.bin/binutils/common #####
mkdir -p usr.bin/binutils/common/arch/$MACHINE_ARCH
{
getvars binutils/Makefile \
DEFS INCLUDES man_MANS PROGRAMS TEXINFOS
for f in `getvars binutils/Makefile PROGRAMS | sed 'y,-,_,;s,^[^=]*=,,'`; do
getvars binutils/Makefile ${f}_OBJECTS ${f}_DEPENDENCIES
done
} | write_mk usr.bin/binutils/common/arch/$MACHINE_ARCH/defs.mk
write_c usr.bin/binutils/common/arch/$MACHINE_ARCH/config.h <$_TMPDIR/binutils/config.h
##### gnu/usr.bin/binutils/gas #####
mkdir -p usr.bin/binutils/gas/arch/$MACHINE_ARCH
getvars gas/Makefile \
DEFS INCLUDES OBJS \
| write_mk usr.bin/binutils/gas/arch/$MACHINE_ARCH/defs.mk
for f in config itbl-cpu obj-format targ-cpu targ-env; do
write_c usr.bin/binutils/gas/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gas/$f.h
done
##### gnu/usr.bin/binutils/gprof #####
mkdir -p usr.bin/binutils/gprof/arch/$MACHINE_ARCH
getvars gprof/Makefile \
DEFS gprof_OBJECTS INCLUDES TEXINFOS \
| write_mk usr.bin/binutils/gprof/arch/$MACHINE_ARCH/defs.mk
write_c usr.bin/binutils/gprof/arch/$MACHINE_ARCH/gconfig.h <$_TMPDIR/gprof/gconfig.h
##### gnu/usr.bin/binutils/ld #####
mkdir -p usr.bin/binutils/ld/arch/$MACHINE_ARCH
{
getvars ld/Makefile \
DEFS EMUL EMULATION_OFILES INCLUDES OFILES STRINGIFY TEXINFOS
getvars ld/Makefile \
target_alias | sed 's,[\._0-9A-Z]*$,,'
} | write_mk usr.bin/binutils/ld/arch/$MACHINE_ARCH/defs.mk
(cd $_TMPDIR/ld && $MAKE ldemul-list.h)
for f in config ldemul-list; do
write_c usr.bin/binutils/ld/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/ld/$f.h
done
##### gnu/usr.bin/gcc #####
mkdir -p usr.bin/gcc/arch/$MACHINE_ARCH
{
getvars gcc/Makefile \
ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
GCOV_OBJS HOST_LIBS HOST_PRINT HOST_RTL HOST_RTLANAL \
INCLUDES md_file OBJC_OBJS OBJS out_file version
getvars gcc/cp/Makefile \
CXX_OBJS
getvars gcc/f/Makefile \
F77_OBJS
} | write_mk usr.bin/gcc/arch/$MACHINE_ARCH/defs.mk
for f in auto-host config gencheck hconfig options specs tconfig tm; do
write_c usr.bin/gcc/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
done
##### gnu/usr.bin/gdb #####
mkdir -p usr.bin/gdb/arch/$MACHINE_ARCH
{
getvars gdb/Makefile \
INTERNAL_CFLAGS LIBGDB_OBS SIM_OBJS
getvars readline/Makefile \
CCFLAGS OBJECTS
} | write_mk usr.bin/gdb/arch/$MACHINE_ARCH/defs.mk
(cd $_TMPDIR/gdb && $MAKE init.c version.c)
cat $_TMPDIR/gdb/config.h $_TMPDIR/readline/config.h \
| write_c usr.bin/gdb/arch/$MACHINE_ARCH/config.h
write_c usr.bin/gdb/arch/$MACHINE_ARCH/init.c <$_TMPDIR/gdb/init.c
write_c usr.bin/gdb/arch/$MACHINE_ARCH/version.c <$_TMPDIR/gdb/version.c
for f in nm tm xm; do
ls -l $_TMPDIR/gdb/$f.h | sed 's,^.*->.*/gdb/config/,,;s,^,#include <,;s,$,>,' \
| write_c usr.bin/gdb/arch/$MACHINE_ARCH/$f.h
done
##### gnu/usr.bin/sim #####
if [ -n `getvars gdb/Makefile SIM` ]; then
mkdir -p usr.bin/sim/arch/$MACHINE_ARCH
case $MACHINE_ARCH in
powerpc*)
write_c usr.bin/sim/arch/$MACHINE_ARCH/config.h <$_TMPDIR/sim/ppc/config.h
;;
*)
;;
esac
fi
# -rm -rf ${_TMPDIR}