Home | History | Annotate | Line # | Download | only in conf
      1 #!/bin/sh -
      2 #
      3 # $NetBSD: newvers_stand.sh,v 1.11 2024/10/14 17:01:18 christos Exp $
      4 #
      5 # Copyright (c) 2000 The NetBSD Foundation, Inc.
      6 # All rights reserved.
      7 #
      8 # This code is derived from software contributed to The NetBSD Foundation
      9 # by Jaromir Dolecek.
     10 #
     11 # Redistribution and use in source and binary forms, with or without
     12 # modification, are permitted provided that the following conditions
     13 # are met:
     14 # 1. Redistributions of source code must retain the above copyright
     15 #    notice, this list of conditions and the following disclaimer.
     16 # 2. Redistributions in binary form must reproduce the above copyright
     17 #    notice, this list of conditions and the following disclaimer in the
     18 #    documentation and/or other materials provided with the distribution.
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30 # POSSIBILITY OF SUCH DAMAGE.
     31 
     32 # Script for generating of vers.c file from given template. Used in
     33 # bootblock build on various architectures.
     34 #
     35 # Called as:
     36 #	sh ${S}/conf/newvers_stand.sh [-dkn] [-D <date>] [-m <machine>] VERSION_TEMPLATE [EXTRA_MSG]
     37 
     38 DATE=${TOOL_DATE:-date}
     39 AWK=${TOOL_AWK:-awk}
     40 
     41 cwd=$(dirname "$0")
     42 
     43 add_name=true
     44 add_date=true
     45 add_kernrev=true
     46 machine="unknown"
     47 dateargs=
     48 
     49 # parse command args
     50 while getopts "m:D:dknm:" OPT; do
     51 	case ${OPT} in
     52 	D)	dateargs="-r ${OPTARG}";;
     53 	d)	add_date=false;;
     54 	k)	add_kernrev=false;;
     55 	m)	machine=${OPTARG};;
     56 	n)	add_name=false;;
     57 	*)	echo "Usage: newvers_stand.sh [-dkn] [-D <date>] [-m <machine>] VERSION_TEMPLATE EXTRA_COMMENT" >&2
     58 		exit 1;;
     59 	esac
     60 done
     61 
     62 shift $(expr ${OPTIND} - 1)
     63 
     64 r=$("${AWK}" -F: '$1 ~ /^[0-9.]*$/ { it = $1; } END { print it }' "$1")
     65 shift
     66 t=$(LC_ALL=C TZ=UTC "${DATE}" ${dateargs})
     67 
     68 if ${add_date}; then
     69 	echo "const char bootprog_rev[] = \"${r} (${t})\";" > vers.c
     70 else
     71 	echo "const char bootprog_rev[] = \"${r}\";" > vers.c
     72 fi
     73 
     74 if ${add_name}; then
     75 	extra=${1:+" $1"}
     76 
     77 	echo "const char bootprog_name[] = \"NetBSD/${machine}${extra}\";" >> vers.c
     78 fi
     79 
     80 if ${add_kernrev}; then
     81 	osr=$(sh "${cwd}/osrelease.sh")
     82 	echo "const char bootprog_kernrev[] = \"${osr}\";" >> vers.c
     83 fi
     84