2019-08-10 23:57:26 +08:00
|
|
|
#!/usr/bin/env bash
|
2020-01-20 01:03:11 +08:00
|
|
|
# tools/version.sh
|
2011-04-15 00:46:17 +08:00
|
|
|
#
|
2019-09-07 23:14:21 +08:00
|
|
|
# Copyright (C) 2011, 2019 Gregory Nutt. All rights reserved.
|
2012-09-14 02:32:24 +08:00
|
|
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-04-15 00:46:17 +08:00
|
|
|
#
|
|
|
|
# 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 NuttX 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 COPYRIGHT HOLDERS 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
|
|
|
|
# COPYRIGHT OWNER 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
WD=`pwd`
|
|
|
|
|
|
|
|
# Get command line parameters
|
|
|
|
|
2019-12-13 01:17:11 +08:00
|
|
|
USAGE="USAGE: $0 [-d|-h] [-b <build>] [-v <major.minor>] <outfile-path>"
|
2011-04-15 00:46:17 +08:00
|
|
|
ADVICE="Try '$0 -h' for more information"
|
|
|
|
|
|
|
|
unset VERSION
|
|
|
|
unset BUILD
|
|
|
|
unset OUTFILE
|
|
|
|
|
2014-04-14 06:22:22 +08:00
|
|
|
while [ ! -z "$1" ]; do
|
2020-01-06 00:29:59 +08:00
|
|
|
case $1 in
|
|
|
|
-b )
|
|
|
|
shift
|
|
|
|
BUILD=$1
|
|
|
|
;;
|
|
|
|
-d )
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
-v )
|
|
|
|
shift
|
|
|
|
VERSION=$1
|
|
|
|
;;
|
|
|
|
-h )
|
|
|
|
echo "$0 is a tool for generation of proper version files for the NuttX build"
|
|
|
|
echo ""
|
|
|
|
echo $USAGE
|
|
|
|
echo ""
|
|
|
|
echo "Where:"
|
|
|
|
echo " -b <build>"
|
|
|
|
echo " Use this build identification string. Default: use GIT build ID"
|
|
|
|
echo " NOTE: GIT build information may not be available in a snapshot"
|
|
|
|
echo " -d"
|
|
|
|
echo " Enable script debug"
|
|
|
|
echo " -h"
|
|
|
|
echo " show this help message and exit"
|
|
|
|
echo " -v <major.minor>"
|
|
|
|
echo " The NuttX version number expressed as a major and minor number separated"
|
|
|
|
echo " by a period"
|
|
|
|
echo " <outfile-path>"
|
|
|
|
echo " The full path to the version file to be created"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
break;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2011-04-15 00:46:17 +08:00
|
|
|
done
|
|
|
|
|
|
|
|
OUTFILE=$1
|
|
|
|
|
2019-12-13 01:17:11 +08:00
|
|
|
if [ -z ${VERSION} ] ; then
|
2020-01-06 00:29:59 +08:00
|
|
|
VERSION=`git tag --sort=taggerdate | tail -1 | cut -d'-' -f2`
|
2019-12-13 01:17:11 +08:00
|
|
|
fi
|
|
|
|
|
2011-04-15 00:46:17 +08:00
|
|
|
# Make sure we know what is going on
|
|
|
|
|
|
|
|
if [ -z ${VERSION} ] ; then
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "Missing versioning information"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
|
|
|
exit 1
|
2011-04-15 00:46:17 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z ${OUTFILE} ] ; then
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "Missing path to the output file"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
|
|
|
exit 1
|
2011-04-15 00:46:17 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the major and minor version numbers
|
|
|
|
|
|
|
|
MAJOR=`echo ${VERSION} | cut -d'.' -f1`
|
|
|
|
if [ "X${MAJOR}" = "X${VERSION}" ]; then
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "Missing minor version number"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
|
|
|
exit 2
|
2011-04-15 00:46:17 +08:00
|
|
|
fi
|
|
|
|
MINOR=`echo ${VERSION} | cut -d'.' -f2`
|
|
|
|
|
2013-04-20 08:35:06 +08:00
|
|
|
# Get GIT information (if not provided on the command line)
|
2011-04-15 00:46:17 +08:00
|
|
|
|
|
|
|
if [ -z "${BUILD}" ]; then
|
2020-01-06 00:29:59 +08:00
|
|
|
BUILD=`git log --oneline -1 | cut -d' ' -f1 2>/dev/null`
|
|
|
|
if [ -z "${BUILD}" ]; then
|
|
|
|
echo "GIT version information is not available"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
if [ -n "`git diff-index --name-only HEAD | head -1`" ]; then
|
|
|
|
BUILD=${BUILD}-dirty
|
|
|
|
fi
|
2011-04-15 00:46:17 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Write a version file into the NuttX directoy. The syntax of file is such that it
|
|
|
|
# may be sourced by a bash script or included by a Makefile.
|
|
|
|
|
|
|
|
echo "#!/bin/bash" >${OUTFILE}
|
|
|
|
echo "" >>${OUTFILE}
|
2019-12-13 01:17:11 +08:00
|
|
|
echo "CONFIG_VERSION_STRING=\"${VERSION}\"" >>${OUTFILE}
|
2011-04-15 00:46:17 +08:00
|
|
|
echo "CONFIG_VERSION_MAJOR=${MAJOR}" >>${OUTFILE}
|
|
|
|
echo "CONFIG_VERSION_MINOR=${MINOR}" >>${OUTFILE}
|
2013-05-01 23:21:13 +08:00
|
|
|
echo "CONFIG_VERSION_BUILD=\"${BUILD}\"" >>${OUTFILE}
|