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