The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/conf/newvers.sh

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #!/bin/sh -
    2 #
    3 # Copyright (c) 1984, 1986, 1990, 1993
    4 #       The Regents of the University of California.  All rights reserved.
    5 #
    6 # Redistribution and use in source and binary forms, with or without
    7 # modification, are permitted provided that the following conditions
    8 # are met:
    9 # 1. Redistributions of source code must retain the above copyright
   10 #    notice, this list of conditions and the following disclaimer.
   11 # 2. Redistributions in binary form must reproduce the above copyright
   12 #    notice, this list of conditions and the following disclaimer in the
   13 #    documentation and/or other materials provided with the distribution.
   14 # 3. Neither the name of the University nor the names of its contributors
   15 #    may be used to endorse or promote products derived from this software
   16 #    without specific prior written permission.
   17 #
   18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28 # SUCH DAMAGE.
   29 #
   30 #       @(#)newvers.sh  8.1 (Berkeley) 4/20/94
   31 # $FreeBSD$
   32 
   33 # Command line options:
   34 #
   35 #     -r               Reproducible build.  Do not embed directory names, user
   36 #                      names, time stamps or other dynamic information into
   37 #                      the output file.  This is intended to allow two builds
   38 #                      done at different times and even by different people on
   39 #                      different hosts to produce identical output.
   40 #
   41 #     -R               Reproducible build if the tree represents an unmodified
   42 #                      checkout from a version control system.  Metadata is
   43 #                      included if the tree is modified.
   44 
   45 TYPE="FreeBSD"
   46 REVISION="11.4"
   47 BRANCH="STABLE"
   48 if [ -n "${BRANCH_OVERRIDE}" ]; then
   49         BRANCH=${BRANCH_OVERRIDE}
   50 fi
   51 RELEASE="${REVISION}-${BRANCH}"
   52 VERSION="${TYPE} ${RELEASE}"
   53 
   54 #
   55 # findvcs dir
   56 #       Looks up directory dir at world root and up the filesystem
   57 #
   58 findvcs()
   59 {
   60         local savedir
   61 
   62         savedir=$(pwd)
   63         cd ${SYSDIR}/..
   64         while [ $(pwd) != "/" ]; do
   65                 if [ -e "./$1" ]; then
   66                         VCSDIR=$(pwd)"/$1"
   67                         cd ${savedir}
   68                         return 0
   69                 fi
   70                 cd ..
   71         done
   72         cd ${savedir}
   73         return 1
   74 }
   75 
   76 if [ -z "${SYSDIR}" ]; then
   77     SYSDIR=$(dirname $0)/..
   78 fi
   79 
   80 if [ -n "${PARAMFILE}" ]; then
   81         RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
   82                 ${PARAMFILE})
   83 else
   84         RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
   85                 ${SYSDIR}/sys/param.h)
   86 fi
   87 
   88 b=share/examples/etc/bsd-style-copyright
   89 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
   90         year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
   91 else
   92         year=$(date +%Y)
   93 fi
   94 # look for copyright template
   95 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
   96 do
   97         if [ -r "$bsd_copyright" ]; then
   98                 COPYRIGHT=`sed \
   99                     -e "s/\[year\]/1992-$year/" \
  100                     -e 's/\[your name here\]\.* /The FreeBSD Project./' \
  101                     -e 's/\[your name\]\.*/The FreeBSD Project./' \
  102                     -e '/\[id for your version control system, if any\]/d' \
  103                     $bsd_copyright` 
  104                 break
  105         fi
  106 done
  107 
  108 # no copyright found, use a dummy
  109 if [ -z "$COPYRIGHT" ]; then
  110         COPYRIGHT="/*-
  111  * Copyright (c) 1992-$year The FreeBSD Project.
  112  * All rights reserved.
  113  *
  114  */"
  115 fi
  116 
  117 # add newline
  118 COPYRIGHT="$COPYRIGHT
  119 "
  120 
  121 # VARS_ONLY means no files should be generated, this is just being
  122 # included.
  123 if [ -n "$VARS_ONLY" ]; then
  124         return 0
  125 fi
  126 
  127 LC_ALL=C; export LC_ALL
  128 if [ ! -r version ]
  129 then
  130         echo 0 > version
  131 fi
  132 
  133 touch version
  134 v=`cat version`
  135 u=${USER:-root}
  136 d=`pwd`
  137 h=${HOSTNAME:-`hostname`}
  138 if [ -n "$SOURCE_DATE_EPOCH" ]; then
  139         if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
  140                 echo "Invalid SOURCE_DATE_EPOCH" >&2
  141                 exit 1
  142         fi
  143 else
  144         t=`date`
  145 fi
  146 i=`${MAKE:-make} -V KERN_IDENT`
  147 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
  148 
  149 for dir in /usr/bin /usr/local/bin; do
  150         if [ ! -z "${svnversion}" ] ; then
  151                 break
  152         fi
  153         if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
  154                 # Run svnversion from ${dir} on this script; if return code
  155                 # is not zero, the checkout might not be compatible with the
  156                 # svnversion being used.
  157                 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
  158                 if [ $? -eq 0 ]; then
  159                         svnversion=${dir}/svnversion
  160                         break
  161                 fi
  162         fi
  163 done
  164 
  165 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
  166         /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
  167         if [ $? -eq 0 ]; then
  168                 svnversion=/usr/bin/svnliteversion
  169         else
  170                 svnversion=
  171         fi
  172 fi
  173 
  174 for dir in /usr/bin /usr/local/bin; do
  175         if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
  176                 p4_cmd=${dir}/p4
  177         fi
  178 done
  179 
  180 if findvcs .git; then
  181         for dir in /usr/bin /usr/local/bin; do
  182                 if [ -x "${dir}/git" ] ; then
  183                         git_cmd="${dir}/git --git-dir=${VCSDIR}"
  184                         break
  185                 fi
  186         done
  187 fi
  188 
  189 if findvcs .hg; then
  190         for dir in /usr/bin /usr/local/bin; do
  191                 if [ -x "${dir}/hg" ] ; then
  192                         hg_cmd="${dir}/hg -R ${VCSDIR}"
  193                         break
  194                 fi
  195         done
  196 fi
  197 
  198 if [ -n "$svnversion" ] ; then
  199         svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
  200         case "$svn" in
  201         [0-9]*[MSP]|*:*)
  202                 svn=" r${svn}"
  203                 modified=true
  204                 ;;
  205         [0-9]*)
  206                 svn=" r${svn}"
  207                 ;;
  208         *)
  209                 unset svn
  210                 ;;
  211         esac
  212 fi
  213 
  214 if [ -n "$git_cmd" ] ; then
  215         git=$($git_cmd rev-parse --verify --short HEAD 2>/dev/null)
  216         git_cnt=$($git_cmd rev-list --first-parent --count HEAD 2>/dev/null)
  217         if [ -n "$git_cnt" ] ; then
  218                 git="n${git_cnt}-${git}"
  219         fi
  220         git_b=$($git_cmd rev-parse --abbrev-ref HEAD)
  221         if [ -n "$git_b" -a "$git_b" != "HEAD" ] ; then
  222                 git="${git_b}-${git}"
  223         fi
  224         if $git_cmd --work-tree=${VCSDIR}/.. diff-index \
  225             --name-only HEAD | read dummy; then
  226                 git="${git}-dirty"
  227                 modified=true
  228         fi
  229         git=" ${git}"
  230 fi
  231 
  232 if [ -n "$p4_cmd" ] ; then
  233         p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
  234                 awk '{ print $2 }'`
  235         case "$p4version" in
  236         [0-9]*)
  237                 p4version=" ${p4version}"
  238                 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
  239                 case "$p4opened" in
  240                 File*) ;;
  241                 //*)
  242                         p4version="${p4version}+edit"
  243                         modified=true
  244                         ;;
  245                 esac
  246                 ;;
  247         *)      unset p4version ;;
  248         esac
  249 fi
  250 
  251 if [ -n "$hg_cmd" ] ; then
  252         hg=`$hg_cmd id 2>/dev/null`
  253         svn=`$hg_cmd svn info 2>/dev/null | \
  254                 awk -F': ' '/Revision/ { print $2 }'`
  255         if [ -n "$svn" ] ; then
  256                 svn=" r${svn}"
  257         fi
  258         if [ -n "$hg" ] ; then
  259                 hg=" ${hg}"
  260         fi
  261 fi
  262 
  263 include_metadata=true
  264 while getopts rR opt; do
  265         case "$opt" in
  266         r)
  267                 include_metadata=
  268                 ;;
  269         R)
  270                 if [ -z "${modified}" ]; then
  271                         include_metadata=
  272                 fi
  273         esac
  274 done
  275 shift $((OPTIND - 1))
  276 
  277 if [ -z "${include_metadata}" ]; then
  278         VERINFO="${VERSION} ${svn}${git}${hg}${p4version}"
  279         VERSTR="${VERINFO}\\n"
  280 else
  281         VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
  282         VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
  283 fi
  284 
  285 cat << EOF > vers.c
  286 $COPYRIGHT
  287 #define SCCSSTR "@(#)${VERINFO}"
  288 #define VERSTR "${VERSTR}"
  289 #define RELSTR "${RELEASE}"
  290 
  291 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
  292 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
  293 char compiler_version[] = "${compiler_v}";
  294 char ostype[] = "${TYPE}";
  295 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
  296 int osreldate = ${RELDATE};
  297 char kern_ident[] = "${i}";
  298 EOF
  299 
  300 echo $((v + 1)) > version

Cache object: 37d30cbdaad8568655fa23af97a68564


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.