3 # This script generates a project-wide version identifier for use by
4 # the `elftc_version()' API.
6 # $Id: make-toolchain-version 3731 2019-04-06 14:28:34Z 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]."
36 # Determine the revision number for the source tree.
38 # - If CVS is detected, we use the string `unknown'.
39 # - If SVN is detected, we use the `svninfo' tool to determine the
40 # in-tree revision number.
41 # - Otherwise, we use `git --describe'.
45 if [ -d CVS ]; then # Look for CVS (NetBSD).
47 elif [ -d .svn ]; then # An SVN checkout (SourceForge or FreeBSD).
48 svnversion="$(svnversion 2>/dev/null)"
49 if [ -n "${svnversion}" ]; then
52 else # Try git (DragonflyBSD).
53 gitversion="$(git describe --all --dirty --long 2> /dev/null)"
54 if [ -n "${gitversion}" ]; then
66 while getopts ${options} option
69 'e') elftcname="${OPTARG}" ;;
70 'h') buildhost="${OPTARG}" ;;
71 'o') versionfile="${OPTARG}" ;;
72 'r') version="${OPTARG}" ;;
73 't') top="${OPTARG}" ;;
78 [ -n "${top}" ] || usage
81 cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
83 # Determine the in-tree revision number.
84 versionstring="$(get_revision_string)" || {
85 echo "ERROR: cannot determine a revision number." 1>&2;
89 cd ${curdir} || usage "Cannot change back to ${curdir}."
92 # Only replace the source file if its content has changed.
94 tmpfile=`mktemp ${TMPDIR:-/tmp}/MV.XXXXXXX`
95 trap "rm -f ${tmpfile};" 0 1 2 3 15
97 cat > ${tmpfile} <<EOF
98 /* WARNING: Generated by "${progname}". */
100 #include <sys/types.h>
101 #include <libelftc.h>
106 return "${elftcname} ${version} ${buildhost} ${versionstring}";
110 if ! cmp -s ${tmpfile} ${versionfile}; then
111 echo "@ ${progname}: building \"${versionfile}\"."
112 cp ${tmpfile} ${versionfile} || exit ${?}