shithub: opus-tools

Download patch

ref: d4e389c4a7da73cd3f2e1648c69f419711d248a3
parent: 0d834f5faa6ec03e9b339a370b261d31db93880e
author: Ron <ron@debian.org>
date: Sat Jun 8 20:45:07 EDT 2013

Fully automate version updating

This one meets or exceeds the following requirements:

 - Version is checked/updated for every build action when in the git repo.
   Does not require the user to re- ./configure to get the correct version.

 - Version is not updated automatically when using exported tarball source.
   Avoids accidentally getting a wrong version from some other git repo in
   a parent directory of the source, and allows setting the correct version
   for distro package exports.

 - Automatic updating can be manually suppressed.
   For developers doing lots of change/rebuild cycles they don't plan to
   release, when they don't want a full rebuild triggered for every commit,
   and again for every change made immediately after a commit.
   The version will still always be updated if they do a `make dist`.

 - Does not require any manual updating of versions in the mainline git
   repo for each release aside from normal tagging.  The version is
   recorded in one file only, that is automatically generated and will
   never need to be committed.

 - Does not require gnu-make features for the autoconf builds.

It does not currently:

 - Keep a checksum of every source file in tarball releases to mangle the
   version if people modify the tarball source.  Responsible people can
   manually update the version easily though in such cases.

--- /dev/null
+++ b/.gitattributes
@@ -1,0 +1,4 @@
+.gitignore		export-ignore
+.gitattributes		export-ignore
+
+update_version		export-ignore
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@
 config.h
 config.log
 config.status
+package_version
 stamp-h1
 opusenc
 opusdec
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,4 @@
+ACLOCAL_AMFLAGS = -I m4
 
 #AUTOMAKE_OPTIONS = subdir-objects 1.6 dist-zip
 AUTOMAKE_OPTIONS = subdir-objects 1.11 dist-zip dist-xz
@@ -71,3 +72,40 @@
 opusrtp_LDADD = @LIBPCAP@ $(OGG_LIBS) $(Opus_LIBS)
 
 #TESTS = FIXME
+
+
+# We check this every time make is run, with configure.ac being touched to
+# trigger an update of the build system files if update_version changes the
+# current PACKAGE_VERSION (or if package_version was modified manually by a
+# user with either AUTO_UPDATE=no or no update_version script present - the
+# latter being the normal case for tarball releases).
+#
+# We can't just add the package_version file to CONFIGURE_DEPENDENCIES since
+# simply running autoconf will not actually regenerate configure for us when
+# the content of that file changes (due to autoconf dependency checking not
+# knowing about that without us creating yet another file for it to include).
+#
+# The MAKECMDGOALS check is a gnu-make'ism, but will degrade 'gracefully' for
+# makes that don't support it.  The only loss of functionality is not forcing
+# an update of package_version for `make dist` if AUTO_UPDATE=no, but that is
+# unlikely to be a real problem for any real user.
+$(top_srcdir)/configure.ac: force
+	@case "$(MAKECMDGOALS)" in \
+	    dist-hook)                             exit 0       ;; \
+	    dist-* | dist | distcheck | distclean) _arg=release ;; \
+	esac; \
+	if ! $(top_srcdir)/update_version $$_arg 2> /dev/null; then \
+	    if [ ! -e $(top_srcdir)/package_version ]; then \
+		echo 'PACKAGE_VERSION="unknown"' > $(top_srcdir)/package_version; \
+	    fi; \
+	    . $(top_srcdir)/package_version || exit 1; \
+	    [ "$(PACKAGE_VERSION)" != "$$PACKAGE_VERSION" ] || exit 0; \
+	fi; \
+	touch $@
+
+force:
+
+# Create a minimal package_version file when make dist is run.
+dist-hook:
+	echo 'PACKAGE_VERSION="$(PACKAGE_VERSION)"' > $(top_distdir)/package_version
+
--- a/Makefile.unix
+++ b/Makefile.unix
@@ -1,6 +1,9 @@
 #Opus-tools should be built with autotools, not this makefile.
 #Run ./configure to run autotools/autoconf.
 #This makefile exists as a fallback where autotools isn't working.
+
+-include package_version
+
 #CC=gcc
 CFLAGS := -O2 -g -c -Wall -Wextra $(CFLAGS)
 INCLUDES := -I../opus/include -I/usr/include/FLAC
@@ -23,7 +26,8 @@
 
 VERSIONED_OBJS = src/opusenc.o src/opusdec.o src/opusinfo.o src/opusrtp.o
 
-$(VERSIONED_OBJS): CFLAGS += -DPACKAGE_NAME='"opus-tools"' -DPACKAGE_VERSION='"0.1.6git"'
+$(VERSIONED_OBJS): CFLAGS += -DPACKAGE_NAME='"opus-tools"' -DPACKAGE_VERSION='$(PACKAGE_VERSION)'
+$(VERSIONED_OBJS): package_version
 
 RESAMPLER_CPPFLAGS = -DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=opustools -DOUTSIDE_SPEEX -DFLOATING_POINT
 
@@ -46,3 +50,14 @@
 
 opusrtp: src/opusrtp.o
 	$(CC) $(LDFLAGS) $^ -o $@ ../opus/.libs/libopus.a -logg -lm
+
+
+package_version: force
+	@if [ -x ./update_version ]; then \
+		./update_version || true; \
+	elif [ ! -e ./package_version ]; then \
+		echo 'PACKAGE_VERSION="unknown"' > ./package_version; \
+	fi
+
+force:
+
--- a/configure.ac
+++ b/configure.ac
@@ -1,32 +1,24 @@
 dnl Process this file with autoconf to produce a configure script. -*-m4-*-
 
-AC_INIT(src/opusenc.c)
+dnl The package_version file will be automatically synced to the git revision
+dnl by the update_version script when configured in the repository, but will
+dnl remain constant in tarball releases unless it is manually edited.
+m4_define([CURRENT_VERSION],
+          m4_esyscmd([ if test -e package_version || ./update_version; then
+                           . ./package_version
+                           printf "$PACKAGE_VERSION"
+                       else
+                           printf "unknown"
+                       fi ]))
 
-AC_CONFIG_HEADERS([config.h])
+AC_INIT([opus-tools],[CURRENT_VERSION],[opus@xiph.org])
+AC_CONFIG_SRCDIR([src/opusenc.c])
+AC_CONFIG_MACRO_DIR([m4])
 
 dnl enable silent rules on automake 1.11 and later
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-OPUSTOOLS_MAJOR_VERSION=0
-OPUSTOOLS_MINOR_VERSION=1
-OPUSTOOLS_MICRO_VERSION=6
-OPUSTOOLS_EXTRA_VERSION=git
-
-OPUSTOOLS_VERSION="$OPUSTOOLS_MAJOR_VERSION.$OPUSTOOLS_MINOR_VERSION.$OPUSTOOLS_MICRO_VERSION$OPUSTOOLS_EXTRA_VERSION"
-AC_MSG_CHECKING([git revision])
-GIT_VERSION=$(git describe --tags --match 'v*' 2>/dev/null | sed 's/^v//')
-if test -z "$GIT_VERSION"; then
-  AC_MSG_RESULT([no])
-else
-  AC_MSG_RESULT([$GIT_VERSION])
-  OPUSTOOLS_VERSION="$GIT_VERSION"
-fi
-
-# For automake.
-VERSION=$OPUSTOOLS_VERSION
-PACKAGE=opus-tools
-
-AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
+AM_INIT_AUTOMAKE([1.11 foreign no-define])
 AM_MAINTAINER_MODE([enable])
 
 AC_CANONICAL_HOST
@@ -92,11 +84,6 @@
 
 AC_CHECK_LIB(winmm, main)
 
-AC_DEFINE_UNQUOTED(OPUSTOOLS_MAJOR_VERSION, ${OPUSTOOLS_MAJOR_VERSION}, [Version major])
-AC_DEFINE_UNQUOTED(OPUSTOOLS_MINOR_VERSION, ${OPUSTOOLS_MINOR_VERSION}, [Version minor])
-AC_DEFINE_UNQUOTED(OPUSTOOLS_MICRO_VERSION, ${OPUSTOOLS_MICRO_VERSION}, [Version micro])
-AC_DEFINE_UNQUOTED(OPUSTOOLS_EXTRA_VERSION, "${OPUSTOOLS_EXTRA_VERSION}", [Version extra])
-
 ac_enable_assertions="no"
 AC_ARG_ENABLE(assertions, [  --enable-assertions     enable additional software error checking],
 [if test "$enableval" = yes; then
@@ -374,11 +361,13 @@
 AC_SUBST(SIZE16)
 AC_SUBST(SIZE32)
 
-AC_OUTPUT([Makefile])
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
 
-AC_MSG_RESULT([
+AC_MSG_NOTICE([
 ------------------------------------------------------------------------
-  $PACKAGE $VERSION:  Automatic configuration OK.
+  $PACKAGE_NAME $PACKAGE_VERSION:  Automatic configuration OK.
 
     Compiler support:
 
@@ -393,7 +382,7 @@
       FLAC input: .................... ${ac_enable_flac}
 
 ------------------------------------------------------------------------
+
+ Type "make; make install" to compile and install
 ])
 
-echo "Type \"make; make install\" to compile and install";
-echo "Type \"make check\" to run the test suite";
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -471,14 +471,13 @@
 
 void version(void)
 {
-   printf("opusdec %s %s (using %s)\n",PACKAGE,VERSION,opus_get_version_string());
+   printf("opusdec %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opus_get_version_string());
    printf("Copyright (C) 2008-2013 Xiph.Org Foundation\n");
 }
 
 void version_short(void)
 {
-   printf("opusdec %s %s (using %s)\n",PACKAGE,VERSION,opus_get_version_string());
-   printf("Copyright (C) 2008-2013 Xiph.Org Foundation\n");
+   version();
 }
 
 /*Process an Opus header and setup the opus decoder based on it.
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -97,14 +97,13 @@
 
 void opustoolsversion(const char *opusversion)
 {
-  printf("opusenc %s %s (using %s)\n",PACKAGE,VERSION,opusversion);
+  printf("opusenc %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opusversion);
   printf("Copyright (C) 2008-2013 Xiph.Org Foundation\n");
 }
 
 void opustoolsversion_short(const char *opusversion)
 {
-  printf("opusenc %s %s (using %s)\n",PACKAGE,VERSION,opusversion);
-  printf("Copyright (C) 2008-2013 Xiph.Org Foundation\n");
+  opustoolsversion(opusversion);
 }
 
 void usage(void)
@@ -393,7 +392,7 @@
   /*Vendor string should just be the encoder library,
     the ENCODER comment specifies the tool used.*/
   comment_init(&inopt.comments, &inopt.comments_length, opus_version);
-  snprintf(ENCODER_string, sizeof(ENCODER_string), "opusenc from %s %s",PACKAGE,VERSION);
+  snprintf(ENCODER_string, sizeof(ENCODER_string), "opusenc from %s %s",PACKAGE_NAME,PACKAGE_VERSION);
   comment_add(&inopt.comments, &inopt.comments_length, "ENCODER", ENCODER_string);
 
   /*Process command-line options*/
--- a/src/opusinfo.c
+++ b/src/opusinfo.c
@@ -924,7 +924,7 @@
 }
 
 static void version (void) {
-    printf (_("opusinfo from %s %s\n"), PACKAGE, VERSION);
+    printf (_("opusinfo from %s %s\n"), PACKAGE_NAME, PACKAGE_VERSION);
 }
 
 static void usage(void) {
--- a/src/opusrtp.c
+++ b/src/opusrtp.c
@@ -842,7 +842,7 @@
 
 void opustools_version(void)
 {
-  printf("opusrtp %s %s\n", PACKAGE, VERSION);
+  printf("opusrtp %s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
   printf("Copyright (C) 2012 Xiph.Org Foundation\n");
 }
 
--- a/src/wave_out.c
+++ b/src/wave_out.c
@@ -61,7 +61,7 @@
 static int
 Box ( const char* msg )
 {
-	MessageBox ( NULL, msg, " "PACKAGE" "VERSION": Error Message . . .", MB_OK | MB_ICONEXCLAMATION );
+	MessageBox ( NULL, msg, " "PACKAGE_NAME" "PACKAGE_VERSION": Error Message . . .", MB_OK | MB_ICONEXCLAMATION );
 	return -1;
 }
 
--- /dev/null
+++ b/update_version
@@ -1,0 +1,65 @@
+#!/bin/bash
+
+# Creates and updates the package_version information used by configure.ac
+# (or other makefiles).  When run inside a git repository it will use the
+# version information that can be queried from it unless AUTO_UPDATE is set
+# to 'no'.  If no version is currently known it will be set to 'unknown'.
+#
+# If called with the argument 'release', the PACKAGE_VERSION will be updated
+# even if AUTO_UPDATE=no, but the value of AUTO_UPDATE shall be preserved.
+# This is used to force a version update whenever `make dist` is run.
+#
+# The exit status is 1 if package_version is not modified, else 0 is returned.
+#
+# This script should NOT be included in distributed tarballs, because if a
+# parent directory contains a git repository we do not want to accidentally
+# retrieve the version information from it instead.  Tarballs should ship
+# with only the package_version file.
+#
+# Ron <ron@debian.org>, 2012.
+
+SRCDIR=$(dirname $0)
+
+if [ -e "$SRCDIR/package_version" ]; then
+    . "$SRCDIR/package_version"
+fi
+
+if [ "$AUTO_UPDATE" = no ]; then
+    [ "$1" = release ] || exit 1
+else
+    AUTO_UPDATE=yes
+fi
+
+# We run `git status` before describe here to ensure that we don't get a false
+# -dirty from files that have been touched but are not actually altered in the
+# working dir.
+GIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \
+                           && git describe --tags --match 'v*' --dirty 2> /dev/null)
+GIT_VERSION=${GIT_VERSION#v}
+
+if [ -n "$GIT_VERSION" ]; then
+
+    [ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1
+    PACKAGE_VERSION="$GIT_VERSION"
+
+elif [ -z "$PACKAGE_VERSION" ]; then
+    # No current package_version and no git ...
+    # We really shouldn't ever get here, because this script should only be
+    # included in the git repository, and should usually be export-ignored.
+    PACKAGE_VERSION="unknown"
+else
+    exit 1
+fi
+
+cat > "$SRCDIR/package_version" <<-EOF
+	# Automatically generated by update_version.
+	# This file may be sourced into a shell script or makefile.
+
+	# Set this to 'no' if you do not wish the version information
+	# to be checked and updated for every build.  Most people will
+	# never want to change this, it is an option for developers
+	# making frequent changes that they know will not be released.
+	AUTO_UPDATE=$AUTO_UPDATE
+
+	PACKAGE_VERSION="$PACKAGE_VERSION"
+EOF
--- a/win32/config.h
+++ b/win32/config.h
@@ -14,7 +14,7 @@
 
 #define RANDOM_PREFIX foo
 
-#define PACKAGE "opus-tools"
+#define PACKAGE_NAME "opus-tools"
 #include "version.h"
 
 
--- a/win32/version.h
+++ b/win32/version.h
@@ -1,1 +1,1 @@
-#define VERSION "v0.1.6git"
+#define PACKAGE_VERSION "v0.1.6git"