a85fe12e36
Sponsored by: The FreeBSD Foundation
105 lines
2.5 KiB
Bash
Executable File
105 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# This script generates a project-wide version identifier for use by
|
|
# the `elftc_version()' API.
|
|
#
|
|
# $Id: make-toolchain-version 2583 2012-09-14 09:49:25Z jkoshy $
|
|
|
|
#
|
|
# Defaults.
|
|
#
|
|
buildhost=`uname -s`
|
|
elftcname="elftoolchain"
|
|
options="e:h:o:r:t:"
|
|
top=""
|
|
version="HEAD"
|
|
versionfile="elftc_version.c"
|
|
progname=`basename ${0}`
|
|
|
|
usage()
|
|
{
|
|
exec >&2
|
|
|
|
# Print a message, if supplied.
|
|
if [ -n "${*}" ]; then echo "##${@}"; fi
|
|
|
|
echo "Usage: ${progname} [options]"
|
|
echo " Generate a toolchain-wide version number"
|
|
echo " -e PROJECTNAME Set the project name [default: ${elftcname}]."
|
|
echo " -h HOSTOS Set the build OS [default: ${buildhost}]."
|
|
echo " -o OUTPUT Set the output file [default: ${versionfile}]."
|
|
echo " -r VERSION Set the version string [default: ${version}]."
|
|
echo " -t TOPDIR Set the top-of-tree directory [required]."
|
|
exit 1
|
|
}
|
|
|
|
#
|
|
# Parse options.
|
|
#
|
|
|
|
while getopts ${options} option
|
|
do
|
|
case ${option} in
|
|
'e') elftcname="${OPTARG}" ;;
|
|
'h') buildhost="${OPTARG}" ;;
|
|
'o') versionfile="${OPTARG}" ;;
|
|
'r') version="${OPTARG}" ;;
|
|
't') top="${OPTARG}" ;;
|
|
'?') usage ;;
|
|
esac
|
|
done
|
|
|
|
[ -n "${top}" ] || usage
|
|
|
|
# Try to determine the in-tree revision number.
|
|
#
|
|
# This script attempts to handle the case where our sources have been
|
|
# incorporated into an operating system's base sources.
|
|
#
|
|
# - If SVN is detected, we use the `svninfo' tool to determine the
|
|
# in-tree revision number.
|
|
# - If CVS is detected, we use the string `unknown'.
|
|
# - Otherwise, we use `git --describe'.
|
|
|
|
curdir=`pwd`
|
|
cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
|
|
|
|
if [ -d .svn ]; then # FreeBSD and SF.Net sources.
|
|
versionstring=" svn:"$(svnversion)
|
|
elif [ -d CVS ]; then # NetBSD.
|
|
versionstring=" cvs:unknown"
|
|
else # DragonFlyBSD.
|
|
versionstring=" git:"$(git describe --all --dirty --long 2> /dev/null)
|
|
|
|
# Cannot determine an in-tree version number.
|
|
if [ $? -ne 0 ]; then
|
|
versionstring=""
|
|
fi
|
|
fi
|
|
|
|
cd ${curdir} || usage "Cannot change back to ${curdir}."
|
|
|
|
#
|
|
# Only replace the source file if its content has changed.
|
|
#
|
|
tmpfile=`mktemp ${TMPDIR:-/tmp}/MV.XXXXXXX`
|
|
trap "rm -f ${tmpfile};" 0 1 2 3 15
|
|
|
|
cat > ${tmpfile} <<EOF
|
|
/* WARNING: Generated by "${progname}". */
|
|
|
|
#include <sys/types.h>
|
|
#include <libelftc.h>
|
|
|
|
const char *
|
|
elftc_version(void)
|
|
{
|
|
return "${elftcname} ${version} ${buildhost}${versionstring}";
|
|
}
|
|
EOF
|
|
|
|
if ! cmp -s ${tmpfile} ${versionfile}; then
|
|
echo "@ ${progname}: building \"${versionfile}\"."
|
|
cp ${tmpfile} ${versionfile} || exit ${?}
|
|
fi
|