# $NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp $ # # from: NetBSD: mknative,v 1.12 2003/03/05 06:17:17 mrg Exp # # shell-fragment common to all "mknative" scripts bomb() { echo >&2 "ABORT: $*" exit 1 } # Make sure we can run OK. if [ -x "$MAKE" ]; then : else bomb "MAKE not set" fi # usage: getvars MAKEFILE VARNAME [VARNAME...] # getvars() { _mfp="$1"; shift case "$MAKE" in *gmake) _dir=$(dirname "$_TMPDIR/$_mfp") _mf=$(basename "$_TMPDIR/$_mfp") env MAKEFLAGS= $MAKE -C "$_dir" --quiet -f - -f "$_mf" _x_ < # getlinks() { _cs="$1"; shift _dir="$1"; shift echo -n G_CONFIGLINKS= grep "^config_links=" $_cs | sed -e 's@config_links="\([^"]*\)"@\1@g' -e "s@\([^:]*\):\([^ ]*\)@\${GNUHOSTDIST}/${_dir}/\2 \1 @g" } # 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 '$NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp $' | 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 '$NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp $' | sed 's,[#$],,g;s,.*,# Generated from: &,' >>$_TOP/$1.tmp echo '#' >>$_TOP/$1.tmp writefile $1 } writefile() { sed -e 's,netbsd\(elf\)*1[0-9\.]*\(_\)*[A-Z]*,netbsd\1,' \ -e 's,^/\* #undef HAVE_MMAP \*/$,#define HAVE_MMAP 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 2>/dev/null 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 rm -f $_TOP/$1.tmp else echo >&2 "$1 changed" mv -f $_TOP/$1.tmp $_TOP/$1 fi }