mknative.common revision 1.1
1#	$NetBSD: mknative.common,v 1.1 2003/11/27 00:58:26 mrg Exp $
2#
3# from: NetBSD: mknative,v 1.12 2003/03/05 06:17:17 mrg Exp
4#
5# shell-fragment common to all "mknative" scripts
6
7bomb () {
8	echo >&1 "ABORT: $*"
9	exit 1
10}
11
12# usage: getvars MAKEFILE VARNAME [VARNAME...]
13getvars () {
14	_mf="$1"; shift
15	$MAKE -f - _x_ <<EOF || bomb "getvars $_mf $* failed"
16_x_:
17.for var in $*
18	@echo G_\${var}=\${\${var}:Q} | sed 's,$_VPATH,\$\${GNUHOSTDIST},g'
19.endfor
20.include "$_TMPDIR/$_mf"
21EOF
22}
23
24# usage: write_c FILENAME
25write_c () {
26	echo '/* This file is automatically generated.  DO NOT EDIT! */' >$_TOP/$1.tmp || \
27		bomb "cannot create $1"
28	grep '$''NetBSD' $0 | sed 's,[#$],,g;s,.*,/* Generated from: & */,' >>$_TOP/$1.tmp
29	echo '' >>$_TOP/$1.tmp
30	writefile $1
31}
32
33# usage: write_mk FILENAME
34write_mk () {
35	echo '# This file is automatically generated.  DO NOT EDIT!' >$_TOP/$1.tmp || \
36		bomb "cannot create $1"
37	grep '$''NetBSD' $0 | sed 's,[#$],,g;s,.*,# Generated from: &,' >>$_TOP/$1.tmp
38	echo '#' >>$_TOP/$1.tmp
39	writefile $1
40}
41
42writefile () {
43	sed -e 's,netbsd\(elf\)*1[0-9\.]*\(_\)*[A-Z]*,netbsd\1,' \
44	    -e 's,^/\* #undef HAVE_MMAP \*/$,#define HAVE_MMAP 1,' >>$_TOP/$1.tmp
45
46	# Compare new file, sans "generated from" comments and RCS Id, to
47	# old file.  If they match, don't change anything.
48	rm -f $_TMPDIR/.1 $_TMPDIR/.2
49	grep -v 'Generated from:' $_TOP/$1 >$_TMPDIR/.1 2>/dev/null
50	grep -v 'Generated from:' $_TOP/$1.tmp >$_TMPDIR/.2
51
52	# will not overwrite a file that has the same content
53	if cmp $_TMPDIR/.1 $_TMPDIR/.2 >/dev/null 2>&1; then
54		rm -f $_TOP/$1.tmp
55	else
56		echo >&2 "$1 changed"
57		mv -f $_TOP/$1.tmp $_TOP/$1
58	fi
59}
60