newvers.sh revision 1.59 1 1.51 skrll #!/bin/sh -
2 1.16 cgd #
3 1.59 apb # $NetBSD: newvers.sh,v 1.59 2014/06/14 12:42:41 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.59 apb # Output files:
64 1.59 apb #
65 1.59 apb # vers.c The "vers.c" file in the current directory is
66 1.59 apb # the primary output.
67 1.59 apb #
68 1.59 apb # version The "version" file in the current directory
69 1.59 apb # is both an input and an output. See the
70 1.59 apb # description under "Input files".
71 1.59 apb #
72 1.59 apb # Input files:
73 1.59 apb #
74 1.59 apb # version The "version" file in the current directory
75 1.59 apb # contains an integer counter, representing the
76 1.59 apb # number of times this script has been executed in
77 1.59 apb # this directory, starting with "0" if the file
78 1.59 apb # does not exist. The serial number in the file
79 1.59 apb # is incremented after the file is read. so that
80 1.59 apb # the incremented serial number is an output from
81 1.59 apb # the present build and an input to the next build
82 1.59 apb # that is performed in the same directory.
83 1.59 apb #
84 1.59 apb # copyright The "copyright" file (in the same directory as
85 1.59 apb # this script itself) contains a copyright notice,
86 1.59 apb # which is embedded in the copyright variable in
87 1.59 apb # the output file.
88 1.59 apb #
89 1.59 apb # ident The "ident" file in the current directory is optional.
90 1.59 apb # If this file exists, then its contents override the
91 1.59 apb # default value of the kernel_ident string.
92 1.59 apb #
93 1.59 apb # Input from external commands:
94 1.59 apb #
95 1.59 apb # osrelease.sh This script is expected to print the OS revision.
96 1.59 apb # The result is stored in the osrelease variable.
97 1.59 apb #
98 1.59 apb
99 1.37 lukem if [ ! -e version ]; then
100 1.1 cgd echo 0 > version
101 1.1 cgd fi
102 1.1 cgd
103 1.34 lukem v=$(cat version)
104 1.53 yamt t=$(LC_ALL=C date)
105 1.34 lukem u=${USER-root}
106 1.34 lukem h=$(hostname)
107 1.34 lukem d=$(pwd)
108 1.37 lukem cwd=$(dirname $0)
109 1.40 christos copyright=$(awk '{ printf("\"%s\\n\"", $0); }' ${cwd}/copyright)
110 1.32 christos
111 1.55 pooka while [ $# -gt 0 ]; do
112 1.55 pooka case "$1" in
113 1.55 pooka -r)
114 1.59 apb # -r: Reproducible build
115 1.56 pooka rflag=true
116 1.55 pooka ;;
117 1.55 pooka -i)
118 1.59 apb # -i <id>: Use the secified string as the
119 1.59 apb # value of the kernel_ident variable
120 1.56 pooka id="$2"
121 1.56 pooka shift
122 1.56 pooka ;;
123 1.56 pooka -n)
124 1.59 apb # -n: Do not include a ELF note section
125 1.59 apb # in the output file.
126 1.56 pooka nflag=true
127 1.56 pooka ;;
128 1.55 pooka esac
129 1.55 pooka shift
130 1.55 pooka done
131 1.55 pooka
132 1.56 pooka if [ -z "${id}" ]; then
133 1.56 pooka if [ -f ident ]; then
134 1.56 pooka id="$(cat ident)"
135 1.56 pooka else
136 1.56 pooka id=$(basename ${d})
137 1.56 pooka fi
138 1.58 apb # Append ".${BUILDID}" to the default value of <id>.
139 1.58 apb # If the "-i <id>" command line option was used then this
140 1.58 apb # branch is not taken, so the command-line value of <id>
141 1.58 apb # is used without change.
142 1.58 apb if [ -n "${BUILDID}" ]; then
143 1.58 apb id="${id}.${BUILDID}"
144 1.58 apb fi
145 1.30 hubertf fi
146 1.32 christos
147 1.37 lukem osrelcmd=${cwd}/osrelease.sh
148 1.12 cgd
149 1.12 cgd ost="NetBSD"
150 1.32 christos osr=$(sh $osrelcmd)
151 1.32 christos
152 1.56 pooka if [ ! -z "${rflag}" ]; then
153 1.54 perry fullversion="${ost} ${osr} (${id})\n"
154 1.56 pooka else
155 1.54 perry fullversion="${ost} ${osr} (${id}) #${v}: ${t}\n\t${u}@${h}:${d}\n"
156 1.56 pooka fi
157 1.36 lukem
158 1.55 pooka echo $(expr ${v} + 1) > version
159 1.55 pooka
160 1.32 christos cat << _EOF > vers.c
161 1.32 christos /*
162 1.32 christos * Automatically generated file from $0
163 1.32 christos * Do not edit.
164 1.32 christos */
165 1.32 christos #include <sys/cdefs.h>
166 1.32 christos #include <sys/types.h>
167 1.32 christos #include <sys/param.h>
168 1.32 christos #include <sys/exec.h>
169 1.32 christos #include <sys/exec_elf.h>
170 1.32 christos
171 1.32 christos const char ostype[] = "${ost}";
172 1.32 christos const char osrelease[] = "${osr}";
173 1.36 lukem const char sccs[] = "@(#)${fullversion}";
174 1.36 lukem const char version[] = "${fullversion}";
175 1.41 thorpej const char kernel_ident[] = "${id}";
176 1.37 lukem const char copyright[] =
177 1.37 lukem ${copyright}
178 1.37 lukem "\n";
179 1.55 pooka _EOF
180 1.55 pooka
181 1.56 pooka [ ! -z "${nflag}" ] && exit 0
182 1.55 pooka
183 1.55 pooka cat << _EOF >> vers.c
184 1.12 cgd
185 1.32 christos /*
186 1.32 christos * NetBSD identity note.
187 1.32 christos */
188 1.52 skrll #ifdef __arm__
189 1.52 skrll #define _SHT_NOTE %note
190 1.52 skrll #else
191 1.52 skrll #define _SHT_NOTE @note
192 1.52 skrll #endif
193 1.52 skrll
194 1.32 christos #define _S(TAG) __STRING(TAG)
195 1.32 christos __asm(
196 1.52 skrll ".section\t\".note.netbsd.ident\", \"\"," _S(_SHT_NOTE) "\n"
197 1.32 christos "\t.p2align\t2\n"
198 1.32 christos "\t.long\t" _S(ELF_NOTE_NETBSD_NAMESZ) "\n"
199 1.32 christos "\t.long\t" _S(ELF_NOTE_NETBSD_DESCSZ) "\n"
200 1.32 christos "\t.long\t" _S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
201 1.32 christos "\t.ascii\t" _S(ELF_NOTE_NETBSD_NAME) "\n"
202 1.32 christos "\t.long\t" _S(__NetBSD_Version__) "\n"
203 1.32 christos "\t.p2align\t2\n"
204 1.32 christos );
205 1.4 cgd
206 1.32 christos _EOF
207