Home | History | Annotate | Line # | Download | only in conf
newvers.sh revision 1.60
      1  1.51     skrll #!/bin/sh -
      2  1.16       cgd #
      3  1.60       apb #	$NetBSD: newvers.sh,v 1.60 2014/08/03 09:13:11 apb 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.59       apb # newvers.sh -- Create a "vers.c" file containing version information.
     35  1.59       apb #
     36  1.59       apb # The "vers.c" file in the current directory is the primary output.  It
     37  1.59       apb # contains C source code with several variables containing information
     38  1.59       apb # about the build.  This file is expected to be incorporated into a
     39  1.59       apb # kernel, and when that kernel is booted then the information can be
     40  1.59       apb # queried by the uname(8) command.
     41  1.59       apb #
     42  1.59       apb # Command line options:
     43  1.59       apb #
     44  1.59       apb #     -r                Reproducible build: Do not embed directory
     45  1.59       apb #                       names, user names, time stamps, or other dynamic
     46  1.59       apb #                       information into the output file.  This intended
     47  1.59       apb #                       to allow two builds done at different times and
     48  1.59       apb #                       even by different people on different hosts to
     49  1.59       apb #                       produce identical output.
     50  1.59       apb #
     51  1.59       apb #     -i <id>           Use the specified string as the value of the
     52  1.59       apb #                       kernel_ident variable
     53  1.59       apb #
     54  1.59       apb #     -n                Do not include an ELF note section in the output
     55  1.59       apb #                       file.
     56  1.59       apb # Environment variables:
     57  1.59       apb #
     58  1.59       apb #     BUILDID		If defined, ${BUILDID} is appended to the
     59  1.59       apb #			default value of the kernel_ident string.
     60  1.59       apb #			(If the -i command line option is used, then
     61  1.59       apb #			BUILDID is not appended.)
     62  1.59       apb #
     63  1.60       apb #     BUILDINFO		A string to be stored in the kernel's buildinfo
     64  1.60       apb #			variable.  ${BUILDINFO} may be a multi-line string,
     65  1.60       apb #			and may use C-style backslash escapes.
     66  1.60       apb #			Lines may be separated by either literal newlines
     67  1.60       apb #			or "\n" escape sequences.
     68  1.60       apb #
     69  1.59       apb # Output files:
     70  1.59       apb #
     71  1.59       apb #     vers.c            The "vers.c" file in the current directory is
     72  1.59       apb #                       the primary output.
     73  1.59       apb #
     74  1.59       apb #     version           The "version" file in the current directory
     75  1.59       apb #                       is both an input and an output.  See the
     76  1.59       apb #                       description under "Input files".
     77  1.59       apb #
     78  1.59       apb # Input files:
     79  1.59       apb #
     80  1.59       apb #     version           The "version" file in the current directory
     81  1.59       apb #                       contains an integer counter, representing the
     82  1.59       apb #                       number of times this script has been executed in
     83  1.59       apb #                       this directory, starting with "0" if the file
     84  1.59       apb #                       does not exist.  The serial number in the file
     85  1.59       apb #                       is incremented after the file is read. so that
     86  1.59       apb #                       the incremented serial number is an output from
     87  1.59       apb #                       the present build and an input to the next build
     88  1.59       apb #                       that is performed in the same directory.
     89  1.59       apb #
     90  1.59       apb #     copyright         The "copyright" file (in the same directory as
     91  1.59       apb #                       this script itself) contains a copyright notice,
     92  1.59       apb #                       which is embedded in the copyright variable in
     93  1.59       apb #                       the output file.
     94  1.59       apb #
     95  1.59       apb #     ident             The "ident" file in the current directory is optional.
     96  1.59       apb #			If this file exists, then its contents override the
     97  1.59       apb #			default value of the kernel_ident string.
     98  1.59       apb #
     99  1.59       apb # Input from external commands:
    100  1.59       apb #
    101  1.59       apb #     osrelease.sh      This script is expected to print the OS revision.
    102  1.59       apb #                       The result is stored in the osrelease variable.
    103  1.59       apb #
    104  1.59       apb 
    105  1.60       apb # FUNCTIONS
    106  1.60       apb 
    107  1.60       apb # source_lines [input] --
    108  1.60       apb #
    109  1.60       apb # Convert a multi-line string to a format that's suitable for inclusion in
    110  1.60       apb # C source code.  The result should look like this:
    111  1.60       apb #
    112  1.60       apb # "first line\n"
    113  1.60       apb # "second line\n"
    114  1.60       apb #
    115  1.60       apb # with <backslash><letter n> inside the quotes for each line,
    116  1.60       apb # literal quotation marks around each line,
    117  1.60       apb # and a literal newline separating one line from the next.
    118  1.60       apb #
    119  1.60       apb # Input is from "$1" if that is defined, or from stdin if $1 is not defined.
    120  1.60       apb #
    121  1.60       apb source_lines()
    122  1.60       apb {
    123  1.60       apb 	if [ -n "${1+set}" ]; then
    124  1.60       apb 		printf "%s" "$1"
    125  1.60       apb 	else
    126  1.60       apb 		cat
    127  1.60       apb 	fi \
    128  1.60       apb 	| awk '{
    129  1.60       apb 		# awk does not care about whether or not the last line
    130  1.60       apb 		# of input ends with a newline.
    131  1.60       apb 		# Convert <backslash> to <backslash><backslash>.
    132  1.60       apb 		gsub("\\\\","\\\\");
    133  1.60       apb 		# Convert <quote> to <backslash><quote>
    134  1.60       apb 		gsub("\"","\\\"");
    135  1.60       apb 		# Add <backslash><letter n> to the end of each line,
    136  1.60       apb 		# and wrap each line in double quotes.
    137  1.60       apb 		printf("\"%s\\n\"\n", $0);
    138  1.60       apb 	}'
    139  1.60       apb }
    140  1.60       apb 
    141  1.60       apb # MAIN PROGRAM
    142  1.60       apb 
    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.60       apb 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.59       apb 		# -r: Reproducible build
    159  1.56     pooka 		rflag=true
    160  1.55     pooka 		;;
    161  1.55     pooka 	-i)
    162  1.59       apb 		# -i <id>: Use the secified string as the
    163  1.59       apb 		# 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.59       apb 		# -n: Do not include a ELF note section
    169  1.59       apb 		# 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.58       apb 	# Append ".${BUILDID}" to the default value of <id>.
    183  1.58       apb 	# If the "-i <id>" command line option was used then this
    184  1.58       apb 	# branch is not taken, so the command-line value of <id>
    185  1.58       apb 	# is used without change.
    186  1.58       apb 	if [ -n "${BUILDID}" ]; then
    187  1.58       apb 		id="${id}.${BUILDID}"
    188  1.58       apb 	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.60       apb # Convert multi-line strings to C source code.
    203  1.60       apb # Also add an extra blank line to copyright.
    204  1.60       apb #
    205  1.60       apb copyright_source="$(printf "%s\n\n" "${copyright}" | source_lines)"
    206  1.60       apb fullversion_source="$(printf "%b" "${fullversion}" | source_lines)"
    207  1.60       apb buildinfo_source="$(printf "%b" "${BUILDINFO}" | source_lines)"
    208  1.60       apb 
    209  1.60       apb # Increment the serial number in the version file
    210  1.55     pooka echo $(expr ${v} + 1) > version
    211  1.55     pooka 
    212  1.32  christos cat << _EOF > vers.c
    213  1.32  christos /*
    214  1.32  christos  * Automatically generated file from $0
    215  1.32  christos  * Do not edit.
    216  1.32  christos  */
    217  1.32  christos #include <sys/cdefs.h>
    218  1.32  christos #include <sys/types.h>
    219  1.32  christos #include <sys/param.h>
    220  1.32  christos #include <sys/exec.h>
    221  1.32  christos #include <sys/exec_elf.h>
    222  1.32  christos 
    223  1.32  christos const char ostype[] = "${ost}";
    224  1.32  christos const char osrelease[] = "${osr}";
    225  1.60       apb const char sccs[] = "@(#)" ${fullversion_source};
    226  1.60       apb const char version[] = ${fullversion_source};
    227  1.60       apb const char buildinfo[] = ${buildinfo_source:-\"\"};
    228  1.41   thorpej const char kernel_ident[] = "${id}";
    229  1.60       apb const char copyright[] = ${copyright_source};
    230  1.55     pooka _EOF
    231  1.55     pooka 
    232  1.56     pooka [ ! -z "${nflag}" ] && exit 0
    233  1.55     pooka 
    234  1.55     pooka cat << _EOF >> vers.c
    235  1.12       cgd 
    236  1.32  christos /*
    237  1.32  christos  * NetBSD identity note.
    238  1.32  christos  */
    239  1.52     skrll #ifdef __arm__
    240  1.52     skrll #define _SHT_NOTE	%note
    241  1.52     skrll #else
    242  1.52     skrll #define _SHT_NOTE	@note
    243  1.52     skrll #endif
    244  1.52     skrll 
    245  1.32  christos #define	_S(TAG)	__STRING(TAG)
    246  1.32  christos __asm(
    247  1.52     skrll 	".section\t\".note.netbsd.ident\", \"\"," _S(_SHT_NOTE) "\n"
    248  1.32  christos 	"\t.p2align\t2\n"
    249  1.32  christos 	"\t.long\t" _S(ELF_NOTE_NETBSD_NAMESZ) "\n"
    250  1.32  christos 	"\t.long\t" _S(ELF_NOTE_NETBSD_DESCSZ) "\n"
    251  1.32  christos 	"\t.long\t" _S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
    252  1.32  christos 	"\t.ascii\t" _S(ELF_NOTE_NETBSD_NAME) "\n"
    253  1.32  christos 	"\t.long\t" _S(__NetBSD_Version__) "\n"
    254  1.32  christos 	"\t.p2align\t2\n"
    255  1.32  christos );
    256   1.4       cgd 
    257  1.32  christos _EOF
    258