123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #!/bin/sh
- ## Copyright (c) 2016 Minoca Corp. All Rights Reserved.
- ##
- ## Script Name:
- ##
- ## print_version.sh <file> <form> <major> <minor> <revision> <release>
- ## <serial> <build_string>
- ##
- ## Abstract:
- ##
- ## This script either prints the current version, or creates a version.h
- ## header file.
- ##
- ## Author:
- ##
- ## Evan Green 13-May-2014
- ##
- ## Environment:
- ##
- ## Minoca (Windows) Build
- ##
- file="$1"
- form="$2"
- major="$3"
- minor="$4"
- revision="$5"
- release="$6"
- serial="$7"
- build_string="$8"
- [ "$major" ] || major=0
- [ "$minor" ] || minor=0
- [ "$revision" ] || revision=0
- [ "$release" ] || release=SystemReleaseDevelopment
- license="All rights reserved."
- cd $SRCROOT/os
- ##
- ## The serial number is the commit count. Use the hardcoded version in a file
- ## if it's supplied, or generate by counting commits in git.
- ##
- if [ -z "$serial" ]; then
- if [ -r "$SRCROOT/os/revision" ]; then
- serial=`cat "$SRCROOT/os/revision"`
- else
- ##
- ## If this is the OS repository and it has not been git replaced with
- ## the old history, add 1000.
- ##
- os_init_rev=1598fc5f1734f7d7ee01e014ee64e131601b78a7
- serial=`git rev-list --count HEAD`
- if [ x`git rev-list --max-parents=0 HEAD` = x$os_init_rev ]; then
- serial=$(($serial + 1000))
- else
- serial=$(($serial + 1))
- fi
- fi
- fi
- ##
- ## Get the build time in seconds since the Minoca epoch, which is January 1,
- ## 2000.
- ##
- build_time=$((`date +%s` - 978307200))
- build_time_string=`date "+%b %d %Y %H:%M:%S"`
- ##
- ## Generate the build string if needed.
- ##
- if [ -z "$build_string" ]; then
- if [ -r "$SRCROOT/os/branch" ]; then
- branch=`cat $SRCROOT/os/branch`
- else
- branch=`git rev-parse --abbrev-ref HEAD`
- fi
- if [ -r "$SRCROOT/os/commit" ]; then
- commit=`cat $SRCROOT/os/commit`
- else
- commit=`git rev-parse HEAD`
- fi
- commit_abbrev=`echo $commit | cut -c1-7`
- commit8=`echo $commit | cut -c1-8`
- user="$USER"
- [ $user ] || user="$LOGNAME"
- [ $user ] || user="$USERNAME"
- [ "$user" = root ] && user=
- [ $VARIANT ] && build_string="${VARIANT}-"
- [ $user ] && build_string="${build_string}${user}-"
- [ $branch != "master" ] && build_string="${build_string}${branch}-"
- build_string="${build_string}${commit_abbrev}"
- build_string="$build_string $build_time_string"
- fi
- ##
- ## For simple revisions, just print out the basic version number.
- ##
- if [ "$form" == "simple" ]; then
- printf "$major.$minor.$revision.$serial" > $file
- exit 0
- fi
- if [ "$form" != "header" ]; then
- echo "Error: unknown form $form."
- exit 1
- fi
- comment_year=`date +%Y`
- comment_date=`date +%e-%b-%Y`
- file_name=`basename $file`
- cat >"$file" <<_EOS
- /*++
- Copyright (c) $comment_year Minoca Corp. All Rights Reserved
- Module Name:
- $file_name
- Abstract:
- This header contains generated version information.
- This file is automatically generated.
- Author:
- Minoca Build $comment_date
- --*/
- //
- // ---------------------------------------------------------------- Definitions
- //
- #define VERSION_MAJOR $major
- #define VERSION_MINOR $minor
- #define VERSION_REVISION $revision
- #define VERSION_RELEASE $release
- #define VERSION_SERIAL $serial
- #define VERSION_BUILD_STRING "$build_string"
- #define VERSION_BUILD_TIME $build_time
- #define VERSION_BUILD_TIME_STRING "$build_time_string"
- //
- // The full commit number string.
- //
- #define VERSION_COMMIT_STRING "$commit"
- //
- // The abbreviated commit number string.
- //
- #define VERSION_COMMIT_ABBREVIATED "$commit_abbrev"
- //
- // An integer of the first 32 bits of the commit.
- //
- #define VERSION_COMMIT_NUMBER 0x$commit8
- //
- // The current branch name.
- //
- #define VERSION_BRANCH "$branch"
- //
- // The user name of the soul doing the building.
- //
- #define VERSION_BUILD_USER "$user"
- //
- // The license under which the software is released.
- //
- #define VERSION_LICENSE "$license"
- _EOS
|