Home | History | Annotate | Line # | Download | only in conf
newvers.sh revision 1.57.22.1
      1       1.51     skrll #!/bin/sh -
      2       1.16       cgd #
      3  1.57.22.1       tls #	$NetBSD: newvers.sh,v 1.57.22.1 2014/08/20 00:03:34 tls Exp $
      4        1.1       cgd #
      5       1.12       cgd # Copyright (c) 1984, 1986, 1990, 1993
      6       1.12       cgd #	The Regents of the University of California.  All rights reserved.
      7        1.1       cgd #
      8        1.1       cgd # Redistribution and use in source and binary forms, with or without
      9        1.1       cgd # modification, are permitted provided that the following conditions
     10        1.1       cgd # are met:
     11        1.1       cgd # 1. Redistributions of source code must retain the above copyright
     12        1.1       cgd #    notice, this list of conditions and the following disclaimer.
     13        1.1       cgd # 2. Redistributions in binary form must reproduce the above copyright
     14        1.1       cgd #    notice, this list of conditions and the following disclaimer in the
     15        1.1       cgd #    documentation and/or other materials provided with the distribution.
     16       1.57       snj # 3. Neither the name of the University nor the names of its contributors
     17        1.1       cgd #    may be used to endorse or promote products derived from this software
     18        1.1       cgd #    without specific prior written permission.
     19        1.1       cgd #
     20        1.1       cgd # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21        1.1       cgd # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22        1.1       cgd # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23        1.1       cgd # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24        1.1       cgd # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25        1.1       cgd # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26        1.1       cgd # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27        1.1       cgd # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28        1.1       cgd # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29        1.1       cgd # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30        1.1       cgd # SUCH DAMAGE.
     31        1.1       cgd #
     32       1.15       cgd #	@(#)newvers.sh	8.1 (Berkeley) 4/20/94
     33        1.1       cgd 
     34  1.57.22.1       tls # newvers.sh -- Create a "vers.c" file containing version information.
     35  1.57.22.1       tls #
     36  1.57.22.1       tls # The "vers.c" file in the current directory is the primary output.  It
     37  1.57.22.1       tls # contains C source code with several variables containing information
     38  1.57.22.1       tls # about the build.  This file is expected to be incorporated into a
     39  1.57.22.1       tls # kernel, and when that kernel is booted then the information can be
     40  1.57.22.1       tls # queried by the uname(8) command.
     41  1.57.22.1       tls #
     42  1.57.22.1       tls # Command line options:
     43  1.57.22.1       tls #
     44  1.57.22.1       tls #     -r                Reproducible build: Do not embed directory
     45  1.57.22.1       tls #                       names, user names, time stamps, or other dynamic
     46  1.57.22.1       tls #                       information into the output file.  This intended
     47  1.57.22.1       tls #                       to allow two builds done at different times and
     48  1.57.22.1       tls #                       even by different people on different hosts to
     49  1.57.22.1       tls #                       produce identical output.
     50  1.57.22.1       tls #
     51  1.57.22.1       tls #     -i <id>           Use the specified string as the value of the
     52  1.57.22.1       tls #                       kernel_ident variable
     53  1.57.22.1       tls #
     54  1.57.22.1       tls #     -n                Do not include an ELF note section in the output
     55  1.57.22.1       tls #                       file.
     56  1.57.22.1       tls # Environment variables:
     57  1.57.22.1       tls #
     58  1.57.22.1       tls #     BUILDID		If defined, ${BUILDID} is appended to the
     59  1.57.22.1       tls #			default value of the kernel_ident string.
     60  1.57.22.1       tls #			(If the -i command line option is used, then
     61  1.57.22.1       tls #			BUILDID is not appended.)
     62  1.57.22.1       tls #
     63  1.57.22.1       tls #     BUILDINFO		A string to be stored in the kernel's buildinfo
     64  1.57.22.1       tls #			variable.  ${BUILDINFO} may be a multi-line string,
     65  1.57.22.1       tls #			and may use C-style backslash escapes.
     66  1.57.22.1       tls #			Lines may be separated by either literal newlines
     67  1.57.22.1       tls #			or "\n" escape sequences.
     68  1.57.22.1       tls #
     69  1.57.22.1       tls # Output files:
     70  1.57.22.1       tls #
     71  1.57.22.1       tls #     vers.c            The "vers.c" file in the current directory is
     72  1.57.22.1       tls #                       the primary output.
     73  1.57.22.1       tls #
     74  1.57.22.1       tls #     version           The "version" file in the current directory
     75  1.57.22.1       tls #                       is both an input and an output.  See the
     76  1.57.22.1       tls #                       description under "Input files".
     77  1.57.22.1       tls #
     78  1.57.22.1       tls # Input files:
     79  1.57.22.1       tls #
     80  1.57.22.1       tls #     version           The "version" file in the current directory
     81  1.57.22.1       tls #                       contains an integer counter, representing the
     82  1.57.22.1       tls #                       number of times this script has been executed in
     83  1.57.22.1       tls #                       this directory, starting with "0" if the file
     84  1.57.22.1       tls #                       does not exist.  The serial number in the file
     85  1.57.22.1       tls #                       is incremented after the file is read. so that
     86  1.57.22.1       tls #                       the incremented serial number is an output from
     87  1.57.22.1       tls #                       the present build and an input to the next build
     88  1.57.22.1       tls #                       that is performed in the same directory.
     89  1.57.22.1       tls #
     90  1.57.22.1       tls #     copyright         The "copyright" file (in the same directory as
     91  1.57.22.1       tls #                       this script itself) contains a copyright notice,
     92  1.57.22.1       tls #                       which is embedded in the copyright variable in
     93  1.57.22.1       tls #                       the output file.
     94  1.57.22.1       tls #
     95  1.57.22.1       tls #     ident             The "ident" file in the current directory is optional.
     96  1.57.22.1       tls #			If this file exists, then its contents override the
     97  1.57.22.1       tls #			default value of the kernel_ident string.
     98  1.57.22.1       tls #
     99  1.57.22.1       tls # Input from external commands:
    100  1.57.22.1       tls #
    101  1.57.22.1       tls #     osrelease.sh      This script is expected to print the OS revision.
    102  1.57.22.1       tls #                       The result is stored in the osrelease variable.
    103  1.57.22.1       tls #
    104  1.57.22.1       tls 
    105  1.57.22.1       tls # FUNCTIONS
    106  1.57.22.1       tls 
    107  1.57.22.1       tls # source_lines [input] --
    108  1.57.22.1       tls #
    109  1.57.22.1       tls # Convert a multi-line string to a format that's suitable for inclusion in
    110  1.57.22.1       tls # C source code.  The result should look like this:
    111  1.57.22.1       tls #
    112  1.57.22.1       tls # "first line\n"
    113  1.57.22.1       tls # "second line\n"
    114  1.57.22.1       tls #
    115  1.57.22.1       tls # with <backslash><letter n> inside the quotes for each line,
    116  1.57.22.1       tls # literal quotation marks around each line,
    117  1.57.22.1       tls # and a literal newline separating one line from the next.
    118  1.57.22.1       tls #
    119  1.57.22.1       tls # Input is from "$1" if that is defined, or from stdin if $1 is not defined.
    120  1.57.22.1       tls #
    121  1.57.22.1       tls source_lines()
    122  1.57.22.1       tls {
    123  1.57.22.1       tls 	if [ -n "${1+set}" ]; then
    124  1.57.22.1       tls 		printf "%s" "$1"
    125  1.57.22.1       tls 	else
    126  1.57.22.1       tls 		cat
    127  1.57.22.1       tls 	fi \
    128  1.57.22.1       tls 	| awk '{
    129  1.57.22.1       tls 		# awk does not care about whether or not the last line
    130  1.57.22.1       tls 		# of input ends with a newline.
    131  1.57.22.1       tls 		# Convert <backslash> to <backslash><backslash>.
    132  1.57.22.1       tls 		gsub("\\\\","\\\\");
    133  1.57.22.1       tls 		# Convert <quote> to <backslash><quote>
    134  1.57.22.1       tls 		gsub("\"","\\\"");
    135  1.57.22.1       tls 		# Add <backslash><letter n> to the end of each line,
    136  1.57.22.1       tls 		# and wrap each line in double quotes.
    137  1.57.22.1       tls 		printf("\"%s\\n\"\n", $0);
    138  1.57.22.1       tls 	}'
    139  1.57.22.1       tls }
    140  1.57.22.1       tls 
    141  1.57.22.1       tls # MAIN PROGRAM
    142  1.57.22.1       tls 
    143       1.37     lukem if [ ! -e version ]; then
    144        1.1       cgd 	echo 0 > version
    145        1.1       cgd fi
    146        1.1       cgd 
    147       1.34     lukem v=$(cat version)
    148       1.53      yamt t=$(LC_ALL=C date)
    149       1.34     lukem u=${USER-root}
    150       1.34     lukem h=$(hostname)
    151       1.34     lukem d=$(pwd)
    152       1.37     lukem cwd=$(dirname $0)
    153  1.57.22.1       tls copyright="$(cat "${cwd}/copyright")"
    154       1.32  christos 
    155       1.55     pooka while [ $# -gt 0 ]; do
    156       1.55     pooka 	case "$1" in
    157       1.55     pooka 	-r)
    158  1.57.22.1       tls 		# -r: Reproducible build
    159       1.56     pooka 		rflag=true
    160       1.55     pooka 		;;
    161       1.55     pooka 	-i)
    162  1.57.22.1       tls 		# -i <id>: Use the secified string as the
    163  1.57.22.1       tls 		# value of the kernel_ident variable
    164       1.56     pooka 		id="$2"
    165       1.56     pooka 		shift
    166       1.56     pooka 		;;
    167       1.56     pooka 	-n)
    168  1.57.22.1       tls 		# -n: Do not include a ELF note section
    169  1.57.22.1       tls 		# in the output file.
    170       1.56     pooka 		nflag=true
    171       1.56     pooka 		;;
    172       1.55     pooka 	esac
    173       1.55     pooka 	shift
    174       1.55     pooka done
    175       1.55     pooka 
    176       1.56     pooka if [ -z "${id}" ]; then
    177       1.56     pooka 	if [ -f ident ]; then
    178       1.56     pooka 		id="$(cat ident)"
    179       1.56     pooka 	else
    180       1.56     pooka 		id=$(basename ${d})
    181       1.56     pooka 	fi
    182  1.57.22.1       tls 	# Append ".${BUILDID}" to the default value of <id>.
    183  1.57.22.1       tls 	# If the "-i <id>" command line option was used then this
    184  1.57.22.1       tls 	# branch is not taken, so the command-line value of <id>
    185  1.57.22.1       tls 	# is used without change.
    186  1.57.22.1       tls 	if [ -n "${BUILDID}" ]; then
    187  1.57.22.1       tls 		id="${id}.${BUILDID}"
    188  1.57.22.1       tls 	fi
    189       1.30   hubertf fi
    190       1.32  christos 
    191       1.37     lukem osrelcmd=${cwd}/osrelease.sh
    192       1.12       cgd 
    193       1.12       cgd ost="NetBSD"
    194       1.32  christos osr=$(sh $osrelcmd)
    195       1.32  christos 
    196       1.56     pooka if [ ! -z "${rflag}" ]; then
    197       1.54     perry 	fullversion="${ost} ${osr} (${id})\n"
    198       1.56     pooka else
    199       1.54     perry 	fullversion="${ost} ${osr} (${id}) #${v}: ${t}\n\t${u}@${h}:${d}\n"
    200       1.56     pooka fi
    201       1.36     lukem 
    202  1.57.22.1       tls # Convert multi-line strings to C source code.
    203  1.57.22.1       tls # Also add an extra blank line to copyright.
    204  1.57.22.1       tls #
    205  1.57.22.1       tls copyright_source="$(printf "%s\n\n" "${copyright}" | source_lines)"
    206  1.57.22.1       tls fullversion_source="$(printf "%b" "${fullversion}" | source_lines)"
    207  1.57.22.1       tls buildinfo_source="$(printf "%b" "${BUILDINFO}" | source_lines)"
    208  1.57.22.1       tls 
    209  1.57.22.1       tls # Increment the serial number in the version file
    210       1.55     pooka echo $(expr ${v} + 1) > version
    211       1.55     pooka 
    212  1.57.22.1       tls # work around escaping issues with different shells
    213  1.57.22.1       tls emptyq='""'
    214  1.57.22.1       tls 
    215       1.32  christos cat << _EOF > vers.c
    216       1.32  christos /*
    217       1.32  christos  * Automatically generated file from $0
    218       1.32  christos  * Do not edit.
    219       1.32  christos  */
    220       1.32  christos #include <sys/cdefs.h>
    221       1.32  christos #include <sys/types.h>
    222       1.32  christos #include <sys/param.h>
    223       1.32  christos #include <sys/exec.h>
    224       1.32  christos #include <sys/exec_elf.h>
    225       1.32  christos 
    226       1.32  christos const char ostype[] = "${ost}";
    227       1.32  christos const char osrelease[] = "${osr}";
    228  1.57.22.1       tls const char sccs[] = "@(#)" ${fullversion_source};
    229  1.57.22.1       tls const char version[] = ${fullversion_source};
    230  1.57.22.1       tls const char buildinfo[] = ${buildinfo_source:-${emptyq}};
    231       1.41   thorpej const char kernel_ident[] = "${id}";
    232  1.57.22.1       tls const char copyright[] = ${copyright_source};
    233       1.55     pooka _EOF
    234       1.55     pooka 
    235       1.56     pooka [ ! -z "${nflag}" ] && exit 0
    236       1.55     pooka 
    237       1.55     pooka cat << _EOF >> vers.c
    238       1.12       cgd 
    239       1.32  christos /*
    240       1.32  christos  * NetBSD identity note.
    241       1.32  christos  */
    242       1.52     skrll #ifdef __arm__
    243       1.52     skrll #define _SHT_NOTE	%note
    244       1.52     skrll #else
    245       1.52     skrll #define _SHT_NOTE	@note
    246       1.52     skrll #endif
    247       1.52     skrll 
    248       1.32  christos #define	_S(TAG)	__STRING(TAG)
    249       1.32  christos __asm(
    250       1.52     skrll 	".section\t\".note.netbsd.ident\", \"\"," _S(_SHT_NOTE) "\n"
    251       1.32  christos 	"\t.p2align\t2\n"
    252       1.32  christos 	"\t.long\t" _S(ELF_NOTE_NETBSD_NAMESZ) "\n"
    253       1.32  christos 	"\t.long\t" _S(ELF_NOTE_NETBSD_DESCSZ) "\n"
    254       1.32  christos 	"\t.long\t" _S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
    255       1.32  christos 	"\t.ascii\t" _S(ELF_NOTE_NETBSD_NAME) "\n"
    256       1.32  christos 	"\t.long\t" _S(__NetBSD_Version__) "\n"
    257       1.32  christos 	"\t.p2align\t2\n"
    258       1.32  christos );
    259        1.4       cgd 
    260       1.32  christos _EOF
    261