3 # This script generates a project-wide version identifier for use by
4 # the `elftc_version()' API.
6 # $Id: make-toolchain-version 3414 2016-02-16 22:55:28Z jkoshy $
12 elftcname="elftoolchain"
16 versionfile="elftc_version.c"
17 progname=`basename ${0}`
23 # Print a message, if supplied.
24 if [ -n "${*}" ]; then echo "##${@}"; fi
26 echo "Usage: ${progname} [options]"
27 echo " Generate a toolchain-wide version number"
28 echo " -e PROJECTNAME Set the project name [default: ${elftcname}]."
29 echo " -h HOSTOS Set the build OS [default: ${buildhost}]."
30 echo " -o OUTPUT Set the output file [default: ${versionfile}]."
31 echo " -r VERSION Set the version string [default: ${version}]."
32 echo " -t TOPDIR Set the top-of-tree directory [required]."
40 while getopts ${options} option
43 'e') elftcname="${OPTARG}" ;;
44 'h') buildhost="${OPTARG}" ;;
45 'o') versionfile="${OPTARG}" ;;
46 'r') version="${OPTARG}" ;;
47 't') top="${OPTARG}" ;;
52 [ -n "${top}" ] || usage
54 # Try to determine the in-tree revision number.
56 # This script attempts to handle the case where our sources have been
57 # incorporated into an operating system's base sources.
59 # - If SVN is detected, we use the `svninfo' tool to determine the
60 # in-tree revision number.
61 # - If CVS is detected, we use the string `unknown'.
62 # - Otherwise, we use `git --describe'.
65 cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
67 if [ -d CVS ]; then # Look for CVS (NetBSD).
68 versionstring=" cvs:unknown"
69 else # Try git (DragonFlyBSD).
70 gitversion="$(git describe --all --dirty --long 2> /dev/null)"
71 if [ -n "${gitversion}" ]; then
72 versionstring=" git:${gitversion}"
73 else # Assume an SVN checkout (SourceForge or FreeBSD).
74 svnversion="$(svnversion)"
75 if [ -n "${svnversion}" ]; then
76 versionstring=" svn:$(svnversion)"
81 if [ -z "${versionstring}" ]; then
82 echo "ERROR: cannot determine a revision number." 1>&2
86 cd ${curdir} || usage "Cannot change back to ${curdir}."
89 # Only replace the source file if its content has changed.
91 tmpfile=`mktemp ${TMPDIR:-/tmp}/MV.XXXXXXX`
92 trap "rm -f ${tmpfile};" 0 1 2 3 15
94 cat > ${tmpfile} <<EOF
95 /* WARNING: Generated by "${progname}". */
97 #include <sys/types.h>
103 return "${elftcname} ${version} ${buildhost}${versionstring}";
107 if ! cmp -s ${tmpfile} ${versionfile}; then
108 echo "@ ${progname}: building \"${versionfile}\"."
109 cp ${tmpfile} ${versionfile} || exit ${?}