build-sys: detect a build from git and show its short commit hash

This commit is contained in:
Benno Schulenberg 2016-04-08 10:22:09 +02:00
parent 4b5b66a806
commit ec295f5e68
4 changed files with 24 additions and 6 deletions

View File

@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
# USA.
AC_INIT([GNU nano], [2.5.3-git], [nano-devel@gnu.org], [nano])
AC_INIT([GNU nano], [2.5.3], [nano-devel@gnu.org], [nano])
AC_CONFIG_SRCDIR([src/nano.c])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE
@ -692,6 +692,16 @@ AM_CONDITIONAL(GROFF_HTML, test x$groff_html_support = xyes)
AC_CHECK_PROG(haveit, makeinfo, yes, no)
AM_CONDITIONAL(HAVE_MAKEINFO, test x$haveit = xyes)
AC_MSG_CHECKING([whether building from git])
if test -d .git ; then
AC_MSG_RESULT([yes])
AC_PATH_PROG([GIT], [git])
REVISION=`($GIT rev-parse --is-inside-work-tree >/dev/null 2>&1) && ($GIT rev-parse --short HEAD)`
AC_SUBST(REVISION)
AC_DEFINE_UNQUOTED([REVISION],"${REVISION}","Setting REVISION in config.h.")
else
AC_MSG_RESULT([no])
fi
AC_CONFIG_FILES([
Makefile

View File

@ -933,7 +933,11 @@ void usage(void)
* it was compiled with. */
void version(void)
{
#ifdef REVISION
printf(" GNU nano from git, commit %s (after %s)\n", REVISION, VERSION);
#else
printf(_(" GNU nano, version %s\n"), VERSION);
#endif
printf(" (C) 1999..2016 Free Software Foundation, Inc.\n");
printf(
_(" Email: nano@nano-editor.org Web: http://www.nano-editor.org/"));

View File

@ -581,4 +581,10 @@ enum
/* The maximum number of bytes buffered at one time. */
#define MAX_BUF_SIZE 128
#ifdef REVISION
#define BRANDING PACKAGE_VERSION"-git "REVISION
#else
#define BRANDING PACKAGE_STRING
#endif
#endif /* !NANO_H */

View File

@ -1952,9 +1952,8 @@ void titlebar(const char *path)
{
int space = COLS;
/* The space we have available for display. */
size_t verlen = strlenpt(PACKAGE_STRING) + 1;
/* The length of the version message in columns, plus one for
* padding. */
size_t verlen = strlenpt(BRANDING);
/* The length of the version message in columns. */
const char *prefix;
/* "DIR:", "File:", or "New Buffer". Goes before filename. */
size_t prefixlen;
@ -1996,8 +1995,7 @@ void titlebar(const char *path)
if (space >= 4) {
/* Add a space after the version message, and account for both
* it and the two spaces before it. */
mvwaddnstr(topwin, 0, 2, PACKAGE_STRING,
actual_x(PACKAGE_STRING, verlen));
mvwaddnstr(topwin, 0, 2, BRANDING, actual_x(BRANDING, verlen));
verlen += 3;
/* Account for the full length of the version message. */