NetBSD/tools/toolchain/mknative

100 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# $NetBSD: mknative,v 1.1 2002/02/11 21:24:10 tv Exp $
#
# Shell script for generating all the constants needed for a native
# platform build of src/gnu/dist/toolchain.
#
bomb () {
echo >&1 "ABORT: $*"
exit 1
}
# usage: getsysvar VARNAME
getsysvar () {
$MAKE -f - _x_ <<EOF || bomb "getvars $1 failed"
.include <bsd.hostprog.mk>
_x_:
@echo \${$1}
EOF
}
# usage: getvars MAKEFILE VARNAME [VARNAME...]
getvars () {
_mf="$1"; shift
$MAKE -f - _x_ <<EOF || bomb "getvars $_mf $* failed"
_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! */' >$_TOP/$1.tmp || \
bomb "cannot create $1"
grep '$''NetBSD' $0 | sed 's,[#$],,g;s,.*,/* Generated from: & */,' >>$_TOP/$1.tmp
echo '' >>$_TOP/$1.tmp
writefile $1
}
# usage: write_mk FILENAME
write_mk () {
echo '# This file is automatically generated. DO NOT EDIT!' >$_TOP/$1.tmp || \
bomb "cannot create $1"
grep '$''NetBSD' $0 | sed 's,[#$],,g;s,.*,# Generated from: &,' >>$_TOP/$1.tmp
echo '#' >>$_TOP/$1.tmp
writefile $1
}
writefile () {
sed 's,netbsd\(elf\)*1[0-9\.]*\(_\)*[A-Z]*,netbsd\1,' >>$_TOP/$1.tmp
# Compare new file, sans "generated from" comments and RCS Id, to
# old file. If they match, don't change anything.
rm -f $_TMPDIR/.1 $_TMPDIR/.2
grep -v 'Generated from:' $_TOP/$1 >$_TMPDIR/.1
grep -v 'Generated from:' $_TOP/$1.tmp >$_TMPDIR/.2
# will not overwrite a file that has the same content
if cmp $_TMPDIR/.1 $_TMPDIR/.2 >/dev/null 2>&1; then
echo >&2 "$1 is unchanged"
rm -f $_TOP/$1.tmp
else
echo >&2 "$1 created"
mv -f $_TOP/$1.tmp $_TOP/$1
fi
}
##### gnu/lib/libgcc #####
get_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 gnu/lib/libgcc/$MACHINE_ARCH.mk
for f in tconfig tm; do
write_c gnu/usr.bin/gcc/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
done
}
##### main #####
_TMPDIR=`pwd`/build
_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*= ,,'`
case $1 in
libgcc) # .mk and .h files for libgcc bootstrap (from host build)
_TOP=$2
get_libgcc
exit 0
;;
*) echo invalid arguments; exit 1;;
esac