#!/bin/sh - # # Copyright (c) 1984, 1986, 1990, 1993 # The Regents of the University of California. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # @(#)newvers.sh 8.1 (Berkeley) 4/20/94 # $FreeBSD: stable/11/sys/conf/newvers.sh 324397 2017-10-07 20:18:20Z emaste $ # Command line options: # # -r Reproducible build. Do not embed directory names, user # names, time stamps or other dynamic information into # the output file. This is intended to allow two builds # done at different times and even by different people on # different hosts to produce identical output. # # -R Reproducible build if the tree represents an unmodified # checkout from a version control system. Metadata is # included if the tree is modified. setglobal TYPE = '"FreeBSD'" setglobal REVISION = '"11.1'" setglobal BRANCH = '"STABLE'" if test -n $(BRANCH_OVERRIDE) { setglobal BRANCH = $(BRANCH_OVERRIDE) } setglobal RELEASE = ""$(REVISION)-$(BRANCH)"" setglobal VERSION = ""$(TYPE) $(RELEASE)"" # # findvcs dir # Looks up directory dir at world root and up the filesystem # proc findvcs { local savedir setglobal savedir = $[pwd] cd $(SYSDIR)/.. while test $[pwd] != "/" { if test -e "./$1" { setglobal VCSDIR = "$[pwd]"/$1"" cd $(savedir) return 0 } cd .. } cd $(savedir) return 1 } if test -z $(SYSDIR) { setglobal SYSDIR = "$[dirname $0]/.." } if test -n $(PARAMFILE) { setglobal RELDATE = $[awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \ $(PARAMFILE)] } else { setglobal RELDATE = $[awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \ $(SYSDIR)/sys/param.h] } setglobal b = 'share/examples/etc/bsd-style-copyright' if test -r "$(SYSDIR)/../COPYRIGHT" { setglobal year = $[sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' $(SYSDIR)/../COPYRIGHT] } else { setglobal year = $[date +%Y] } # look for copyright template for bsd_copyright in [../$b ../../$b ../../../$b /usr/src/$b /usr/$b] { if test -r $bsd_copyright { setglobal COPYRIGHT = $[sed \ -e "s/\[year\]/1992-$year/" \ -e 's/\[your name here\]\.* /The FreeBSD Project./' \ -e 's/\[your name\]\.*/The FreeBSD Project./' \ -e '/\[id for your version control system, if any\]/d' \ $bsd_copyright] break } } # no copyright found, use a dummy if test -z $COPYRIGHT { setglobal COPYRIGHT = ""/*- * Copyright (c) 1992-$year The FreeBSD Project. * All rights reserved. * */"" } # add newline setglobal COPYRIGHT = ""$COPYRIGHT "" # VARS_ONLY means no files should be generated, this is just being # included. if test -n $VARS_ONLY { return 0 } setglobal LC_ALL = 'C'; export LC_ALL if test ! -r version { echo 0 > version } touch version setglobal v = $[cat version] setglobal u = $(USER:-root) setglobal d = $[pwd] setglobal h = $(HOSTNAME:-`hostname`) if test -n $SOURCE_DATE_EPOCH { if ! setglobal t = $[date -r $SOURCE_DATE_EPOCH !2 >/dev/null] { echo "Invalid SOURCE_DATE_EPOCH" > !2 exit 1 } } else { setglobal t = $[date] } setglobal i = $[$(MAKE:-make) -V KERN_IDENT] setglobal compiler_v = $[$[$(MAKE:-make) -V CC] -v !2 > !1 | grep -w 'version] for dir in [/usr/bin /usr/local/bin] { if test ! -z $(svnversion) { break } if test -x "$(dir)/svnversion" && test -z $(svnversion) { # Run svnversion from ${dir} on this script; if return code # is not zero, the checkout might not be compatible with the # svnversion being used. $(dir)/svnversion $[realpath $(0)] >/dev/null !2 > !1 if test $Status -eq 0 { setglobal svnversion = "$(dir)/svnversion" break } } } if test -z $(svnversion) && test -x /usr/bin/svnliteversion { /usr/bin/svnliteversion $[realpath $(0)] >/dev/null !2 > !1 if test $Status -eq 0 { setglobal svnversion = '/usr/bin/svnliteversion' } else { setglobal svnversion = '' } } for dir in [/usr/bin /usr/local/bin] { if test -x "$(dir)/p4" && test -z $(p4_cmd) { setglobal p4_cmd = "$(dir)/p4" } } if findvcs .git { for dir in [/usr/bin /usr/local/bin] { if test -x "$(dir)/git" { setglobal git_cmd = ""$(dir)/git --git-dir=$(VCSDIR)"" break } } } if findvcs .hg { for dir in [/usr/bin /usr/local/bin] { if test -x "$(dir)/hg" { setglobal hg_cmd = ""$(dir)/hg -R $(VCSDIR)"" break } } } if test -n $svnversion { setglobal svn = $[cd $(SYSDIR) && $svnversion !2 >/dev/null] match $svn { with [0-9]*[MSP]|*:* setglobal svn = "" r$(svn)"" setglobal modified = 'true' with [0-9]* setglobal svn = "" r$(svn)"" with * unset svn } } if test -n $git_cmd { setglobal git = $[$git_cmd rev-parse --verify --short HEAD !2 >/dev/null] setglobal svn = $[$git_cmd svn find-rev $git !2 >/dev/null] if test -n $svn { setglobal svn = "" r$(svn)"" setglobal git = ""=$(git)"" } else { setglobal svn = $[$git_cmd log --grep '^git-svn-id:' | \ grep '^ git-svn-id:' | head -1 | \ sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p] if test -z $svn { setglobal svn = $[$git_cmd log --format='format:%N' | \ grep '^svn ' | head -1 | \ sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p] } if test -n $svn { setglobal svn = "" r$(svn)"" setglobal git = ""+$(git)"" } else { setglobal git = "" $(git)"" } } setglobal git_b = $[$git_cmd rev-parse --abbrev-ref HEAD] if test -n $git_b { setglobal git = ""$(git)($(git_b))"" } if $git_cmd --work-tree=$(VCSDIR)/.. diff-index \ --name-only HEAD | read dummy { setglobal git = ""$(git)-dirty"" setglobal modified = 'true' } } if test -n $p4_cmd { setglobal p4version = $[cd $(SYSDIR) && $p4_cmd changes -m1 "./...#have" !2 > !1 | \ awk '{ print $2 }] match $p4version { with [0-9]* setglobal p4version = "" $(p4version)"" setglobal p4opened = $[cd $(SYSDIR) && $p4_cmd opened ./... !2 > !1] match $p4opened { with File* with //* setglobal p4version = ""$(p4version)+edit"" setglobal modified = 'true' } with * unset p4version } } if test -n $hg_cmd { setglobal hg = $[$hg_cmd id !2 >/dev/null] setglobal svn = $[$hg_cmd svn info !2 >/dev/null | \ awk -F': ' '/Revision/ { print $2 }] if test -n $svn { setglobal svn = "" r$(svn)"" } if test -n $hg { setglobal hg = "" $(hg)"" } } setglobal include_metadata = 'true' while getopts rR opt { match $opt { with r setglobal include_metadata = '' with R if test -z $(modified) { setglobal include_metadata = '' } } } shift $shExpr('OPTIND - 1') if test -z $(include_metadata) { setglobal VERINFO = ""$(VERSION) $(svn)$(git)$(hg)$(p4version)"" setglobal VERSTR = ""$(VERINFO)\\n"" } else { setglobal VERINFO = ""$(VERSION) #$(v)$(svn)$(git)$(hg)$(p4version): $(t)"" setglobal VERSTR = ""$(VERINFO)\\n $(u)@$(h):$(d)\\n"" } cat << """ > vers.c $COPYRIGHT #define SCCSSTR "@(#)$(VERINFO)" #define VERSTR "$(VERSTR)" #define RELSTR "$(RELEASE)" char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; char compiler_version[] = "$(compiler_v)"; char ostype[] = "$(TYPE)"; char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; int osreldate = $(RELDATE); char kern_ident[] = "$(i)"; """ > vers.c $COPYRIGHT #define SCCSSTR "@(#)${VERINFO}" #define VERSTR "${VERSTR}" #define RELSTR "${RELEASE}" char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; char compiler_version[] = "${compiler_v}"; char ostype[] = "${TYPE}"; char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; int osreldate = ${RELDATE}; char kern_ident[] = "${i}"; EOF echo $shExpr('v + 1') > version