Home | History | Annotate | Line # | Download | only in conf
newvers.sh revision 1.58
      1 #!/bin/sh -
      2 #
      3 #	$NetBSD: newvers.sh,v 1.58 2014/06/14 12:35:18 apb Exp $
      4 #
      5 # Copyright (c) 1984, 1986, 1990, 1993
      6 #	The Regents of the University of California.  All rights reserved.
      7 #
      8 # Redistribution and use in source and binary forms, with or without
      9 # modification, are permitted provided that the following conditions
     10 # are met:
     11 # 1. Redistributions of source code must retain the above copyright
     12 #    notice, this list of conditions and the following disclaimer.
     13 # 2. Redistributions in binary form must reproduce the above copyright
     14 #    notice, this list of conditions and the following disclaimer in the
     15 #    documentation and/or other materials provided with the distribution.
     16 # 3. Neither the name of the University nor the names of its contributors
     17 #    may be used to endorse or promote products derived from this software
     18 #    without specific prior written permission.
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30 # SUCH DAMAGE.
     31 #
     32 #	@(#)newvers.sh	8.1 (Berkeley) 4/20/94
     33 
     34 if [ ! -e version ]; then
     35 	echo 0 > version
     36 fi
     37 
     38 v=$(cat version)
     39 t=$(LC_ALL=C date)
     40 u=${USER-root}
     41 h=$(hostname)
     42 d=$(pwd)
     43 cwd=$(dirname $0)
     44 copyright=$(awk '{ printf("\"%s\\n\"", $0); }' ${cwd}/copyright)
     45 
     46 while [ $# -gt 0 ]; do
     47 	case "$1" in
     48 	-r)
     49 		rflag=true
     50 		;;
     51 	-i)
     52 		id="$2"
     53 		shift
     54 		;;
     55 	-n)
     56 		nflag=true
     57 		;;
     58 	esac
     59 	shift
     60 done
     61 
     62 if [ -z "${id}" ]; then
     63 	if [ -f ident ]; then
     64 		id="$(cat ident)"
     65 	else
     66 		id=$(basename ${d})
     67 	fi
     68 	# Append ".${BUILDID}" to the default value of <id>.
     69 	# If the "-i <id>" command line option was used then this
     70 	# branch is not taken, so the command-line value of <id>
     71 	# is used without change.
     72 	if [ -n "${BUILDID}" ]; then
     73 		id="${id}.${BUILDID}"
     74 	fi
     75 fi
     76 
     77 osrelcmd=${cwd}/osrelease.sh
     78 
     79 ost="NetBSD"
     80 osr=$(sh $osrelcmd)
     81 
     82 if [ ! -z "${rflag}" ]; then
     83 	fullversion="${ost} ${osr} (${id})\n"
     84 else
     85 	fullversion="${ost} ${osr} (${id}) #${v}: ${t}\n\t${u}@${h}:${d}\n"
     86 fi
     87 
     88 echo $(expr ${v} + 1) > version
     89 
     90 cat << _EOF > vers.c
     91 /*
     92  * Automatically generated file from $0
     93  * Do not edit.
     94  */
     95 #include <sys/cdefs.h>
     96 #include <sys/types.h>
     97 #include <sys/param.h>
     98 #include <sys/exec.h>
     99 #include <sys/exec_elf.h>
    100 
    101 const char ostype[] = "${ost}";
    102 const char osrelease[] = "${osr}";
    103 const char sccs[] = "@(#)${fullversion}";
    104 const char version[] = "${fullversion}";
    105 const char kernel_ident[] = "${id}";
    106 const char copyright[] =
    107 ${copyright}
    108 "\n";
    109 _EOF
    110 
    111 [ ! -z "${nflag}" ] && exit 0
    112 
    113 cat << _EOF >> vers.c
    114 
    115 /*
    116  * NetBSD identity note.
    117  */
    118 #ifdef __arm__
    119 #define _SHT_NOTE	%note
    120 #else
    121 #define _SHT_NOTE	@note
    122 #endif
    123 
    124 #define	_S(TAG)	__STRING(TAG)
    125 __asm(
    126 	".section\t\".note.netbsd.ident\", \"\"," _S(_SHT_NOTE) "\n"
    127 	"\t.p2align\t2\n"
    128 	"\t.long\t" _S(ELF_NOTE_NETBSD_NAMESZ) "\n"
    129 	"\t.long\t" _S(ELF_NOTE_NETBSD_DESCSZ) "\n"
    130 	"\t.long\t" _S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
    131 	"\t.ascii\t" _S(ELF_NOTE_NETBSD_NAME) "\n"
    132 	"\t.long\t" _S(__NetBSD_Version__) "\n"
    133 	"\t.p2align\t2\n"
    134 );
    135 
    136 _EOF
    137