#!/bin/bash # # Create the build info header file # # Usage: build_info [--build] [build-info-data-file build-info-header-file] # build_info --create build-info-data-file title author [major-version minor-version build-sequence] # build_info --help # # Author: Graham Cobb 10-Dec-2001 # # USAGE="Usage: $0 [--help] [[--build] [build-info-data-file build-info-header-file]] [--create build-info-data-file title author [major-version minor-version build-sequence]]" BUILD_INFO_VERSION=1 do_help= do_create= while [ $# -gt 0 ]; do case "$1" in --help) shift ; do_help=y ;; --create) shift ; do_create=y ;; --build) shift ;; --) shift ; break ;; -*) echo "$0: ${1}: invalid option" >&2 echo "$USAGE" >& 2 exit 2 ;; *) break ;; esac done if [ -n "$do_help" ]; then echo "This is build_info version $BUILD_INFO_VERSION" echo cat << HERE_EOF build_info --help This help text. build_info [--build] [build-info-data-file build-info-header-file] build_info creates a C header file which provides information about the build environment for a program which can be used to display version information to a user of the program. The script creates build_info.h (by default) which defines the following constants (macros): BUILD_TITLE - The program title. This can be any text string but is usually either a short name (e.g. build_info) or a one-line description (e.g. "Create build information header file"). (*) BUILD_AUTHOR - The program author. This can be any text string but is usually either the original author or the most recent modifier. (*) BUILD_VER - The program version. This is a text string of the form . (e.g. "10.3"). (*) BUILD_VER_MAJOR - Major version number. This is a numeric form of the major version (e.g. 10). (*) BUILD_VER_MINOR - Minor version number. This is a numeric form of the minor version (e.g. 3). (*) BUILD_SEQ_NUM - The sequential build number. This is a number which is incremented by one each time the script is run. (*) BUILD_SEQ_ID - Text form of the sequential build number. This is BUILD_SEQ_NUM as a string (e.g. "305"). (*) BUILD_FULL_VER - Major, minor and build number: . - (e.g. "10.3-305"). (*) BUILD_BUILDER - Builder username. This is the username of the user running the script (e.g. "cobb"). BUILD_HOST - Builder hostname. This is the hostname of the system running the script. BUILD_DATE - Build date. BUILD_TIME - Build time BUILD_YEAR - Year from build date (as a text string) * - These items are derived from information stored in the build information data file (build_info.dat by default). build_info --create build-info-data-file title author [major-version minor-version build-sequence] The data file can be created using the --create option. This requires the data file name (usually build_info.dat), the title and the author. The version numbers and initial build sequence number can also be specified as required (default is 1.0-0). HERE_EOF exit 0 fi if [ -n "$do_create" ]; then # Create the data file if [ $# -lt 3 ]; then echo "$0: Create option must specify file name, title and author" >&2 echo "$USAGE" >& 2 exit 2 fi data_file=$1 BUILD_TITLE=$2 BUILD_AUTHOR=$3 BUILD_VER_MAJOR=${4-1} BUILD_VER_MINOR=${5-0} BUILD_SEQ_NUM=${6-0} # Drop through to creating the data file else # Normal case: output the header file data_file=${1-build_info.dat} header_file=${1-build_info.h} # Read data file . $data_file BUILD_SEQ_NUM=$((BUILD_SEQ_NUM+1)) HOSTNAME=`hostname` DATE=`date "+%d-%b-%Y"` TIME=`date "+%T %Z"` YEAR=`date "+%Y"` # Create header file echo "#define BUILD_TITLE \"${BUILD_TITLE}\"" >$header_file echo "#define BUILD_AUTHOR \"${BUILD_AUTHOR}\"" >>$header_file echo "#define BUILD_VER \"${BUILD_VER_MAJOR}.${BUILD_VER_MINOR}\"" >>$header_file echo "#define BUILD_VER_MAJOR ${BUILD_VER_MAJOR}" >>$header_file echo "#define BUILD_VER_MINOR ${BUILD_VER_MINOR}" >>$header_file echo "#define BUILD_SEQ_NUM ${BUILD_SEQ_NUM}" >>$header_file echo "#define BUILD_SEQ_ID \"${BUILD_SEQ_NUM}\"" >>$header_file echo "#define BUILD_FULL_VER \"${BUILD_VER_MAJOR}.${BUILD_VER_MINOR}-${BUILD_SEQ_NUM}\"" >>$header_file echo "#define BUILD_BUILDER \"${USER}\"" >>$header_file echo "#define BUILD_HOST \"${HOSTNAME}\"" >>$header_file echo "#define BUILD_DATE \"${DATE}\"" >>$header_file echo "#define BUILD_TIME \"${TIME}\"" >>$header_file echo "#define BUILD_YEAR \"${YEAR}\"" >>$header_file fi # Create data file echo "BUILD_INFO_DATA_VERSION=${BUILD_INFO_VERSION}" >$data_file echo "BUILD_TITLE=\"${BUILD_TITLE}\"" >>$data_file echo "BUILD_AUTHOR=\"${BUILD_AUTHOR}\"" >>$data_file echo "BUILD_VER_MAJOR=${BUILD_VER_MAJOR}" >>$data_file echo "BUILD_VER_MINOR=${BUILD_VER_MINOR}" >>$data_file echo "BUILD_SEQ_NUM=${BUILD_SEQ_NUM}" >>$data_file