NetBSD/tools/gcc/mknative.common

92 lines
2.4 KiB
Plaintext
Raw Normal View History

# $NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp $
2003-11-27 03:58:26 +03:00
#
# from: NetBSD: mknative,v 1.12 2003/03/05 06:17:17 mrg Exp
#
# shell-fragment common to all "mknative" scripts
2004-12-11 04:37:36 +03:00
bomb()
{
echo >&2 "ABORT: $*"
2003-11-27 03:58:26 +03:00
exit 1
}
# Make sure we can run OK.
if [ -x "$MAKE" ]; then
:
else
bomb "MAKE not set"
fi
2003-11-27 03:58:26 +03:00
# usage: getvars MAKEFILE VARNAME [VARNAME...]
2004-12-11 04:37:36 +03:00
#
getvars()
{
2003-11-27 03:58:26 +03:00
_mf="$1"; shift
case "$MAKE" in
*gmake)
env MAKEFLAGS= $MAKE -f - -f "$_TMPDIR/$_mf" _x_ <<EOF || bomb "getvars $_mf $* failed"
define echo_var
@echo G_\${var}="\${\${var}}" | sed -e 's,\([^\.]\)\./\([a-zA-Z0-9_-]*\.o\),\1\2,g' -e 's,$_VPATH,\$\${GNUHOSTDIST},g' -e 's,$_GNU_DIST,\$\${GNUHOSTDIST},g'
endef
_x_:
\$(foreach var,$*,\$(echo_var))
EOF
;;
*)
$MAKE -B -f - _x_ <<EOF || bomb "getvars $_mf $* failed"
2003-11-27 03:58:26 +03:00
_x_:
.for var in $*
@echo G_\${var}=\${\${var}:Q} | sed -e 's,\([^\.]\)\./\([a-zA-Z0-9_-]*\.o\),\1\2,g' -e 's,$_VPATH,\$\${GNUHOSTDIST},g' -e 's,$_GNU_DIST,\$\${GNUHOSTDIST},g'
2003-11-27 03:58:26 +03:00
.endfor
.include "$_TMPDIR/$_mf"
EOF
;;
esac
2003-11-27 03:58:26 +03:00
}
# usage: write_c FILENAME
2004-12-11 04:37:36 +03:00
#
write_c()
{
2003-11-27 03:58:26 +03:00
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 '$NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp $' | sed 's,[#$],,g;s,.*,/* Generated from: & */,' >>$_TOP/$1.tmp
2003-11-27 03:58:26 +03:00
echo '' >>$_TOP/$1.tmp
writefile $1
}
# usage: write_mk FILENAME
2004-12-11 04:37:36 +03:00
#
write_mk()
{
2003-11-27 03:58:26 +03:00
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 '$NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp $' | sed 's,[#$],,g;s,.*,# Generated from: &,' >>$_TOP/$1.tmp
2003-11-27 03:58:26 +03:00
echo '#' >>$_TOP/$1.tmp
writefile $1
}
2004-12-11 04:37:36 +03:00
writefile()
{
2003-11-27 03:58:26 +03:00
sed -e 's,netbsd\(elf\)*1[0-9\.]*\(_\)*[A-Z]*,netbsd\1,' \
2004-12-11 04:37:36 +03:00
-e 's,^/\* #undef HAVE_MMAP \*/$,#define HAVE_MMAP 1,' \
>>$_TOP/$1.tmp
2003-11-27 03:58:26 +03:00
2004-12-11 04:37:36 +03:00
# Compare new file, sans "generated from" comments and RCS Id,
# to old file. If they match, don't change anything.
2003-11-27 03:58:26 +03:00
rm -f $_TMPDIR/.1 $_TMPDIR/.2
grep -v 'Generated from:' $_TOP/$1 >$_TMPDIR/.1 2>/dev/null
grep -v 'Generated from:' $_TOP/$1.tmp >$_TMPDIR/.2
2004-12-11 04:37:36 +03:00
# will not overwrite a file that has the same content
2003-11-27 03:58:26 +03:00
if cmp $_TMPDIR/.1 $_TMPDIR/.2 >/dev/null 2>&1; then
rm -f $_TOP/$1.tmp
else
echo >&2 "$1 changed"
mv -f $_TOP/$1.tmp $_TOP/$1
fi
}