shithub: opusfile

Download patch

ref: ff868661e2e2031212a1a74fbc10f2a72f8ddb36
parent: 498615438ac44622e688b6ca85a2bc0cd5f2de3c
author: Ron <[email protected]>
date: Mon May 13 16:32:13 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/.gitattibutes
@@ -1,0 +1,4 @@
+.gitignore		export-ignore
+.gitattributes		export-ignore
+
+update_version		export-ignore
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@
 opusfile-uninstalled.pc
 opusurl.pc
 opusurl-uninstalled.pc
+package_version
 unix/objs
 unix/opusfile_example
 unix/seeking_example
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,7 +45,6 @@
  opusfile-uninstalled.pc.in \
  opusurl-uninstalled.pc.in \
  doc/Doxyfile.in \
- doc/git-version.sh \
  doc/opus_logo.svg \
  doc/Makefile \
  unix/Makefile
@@ -90,5 +89,41 @@
 	$(RM) -r $(DESTDIR)$(docdir)/html
 
 endif
+
+# 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
+
 
 .PHONY: opusfile install-opusfile docs install-docs
--- a/configure.ac
+++ b/configure.ac
@@ -1,11 +1,23 @@
 # autoconf source script for generating configure
 
-AC_INIT([opusfile], m4_esyscmd([doc/git-version.sh]))
+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_s([ if test -e package_version || ./update_version; then
+                             . ./package_version
+                             printf "$PACKAGE_VERSION"
+                         else
+                             printf "unknown"
+                         fi ]))
 
+AC_INIT([opusfile],[CURRENT_VERSION],[[email protected]])
+AC_CONFIG_SRCDIR([src/opusfile.c])
+
 AC_USE_SYSTEM_EXTENSIONS
 AC_SYS_LARGEFILE
 
-AM_INIT_AUTOMAKE([1.11 foreign])
+AM_INIT_AUTOMAKE([1.11 foreign no-define])
 AM_MAINTAINER_MODE([enable])
 LT_INIT
 
@@ -130,7 +142,7 @@
 fi
 AM_CONDITIONAL(HAVE_DOXYGEN, [test $HAVE_DOXYGEN = yes])
 
-AC_OUTPUT([
+AC_CONFIG_FILES([
   Makefile
   opusfile.pc
   opusurl.pc
@@ -138,10 +150,11 @@
   opusurl-uninstalled.pc
   doc/Doxyfile
 ])
+AC_OUTPUT
 
 AC_MSG_NOTICE([
 ------------------------------------------------------------------------
-  $PACKAGE $VERSION: Automatic configuration OK.
+  $PACKAGE_NAME $PACKAGE_VERSION: Automatic configuration OK.
 
     Assertions ................... ${enable_assertions}
 
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -1,7 +1,7 @@
 # Process with doxygen to generate API documentation
 
-PROJECT_NAME           = @PACKAGE@
-PROJECT_NUMBER         = @VERSION@
+PROJECT_NAME           = @PACKAGE_NAME@
+PROJECT_NUMBER         = @PACKAGE_VERSION@
 PROJECT_BRIEF          = "Stand-alone decoder library for .opus files."
 INPUT                  = @top_srcdir@/include/opusfile.h
 OPTIMIZE_OUTPUT_FOR_C  = YES
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,5 +1,7 @@
 ## GNU makefile for opusfile documentation.
 
+-include ../package_version
+
 all: doxygen
 
 doxygen: Doxyfile ../include/opusfile.h
@@ -17,10 +19,16 @@
 
 .PHONY: all clean distclean doxygen pdf
 
+../package_version:
+	@if [ -x ../update_version ]; then \
+		../update_version || true; \
+	elif [ ! -e $@ ]; then \
+		echo 'PACKAGE_VERSION="unknown"' > $@; \
+	fi
+
 # run autoconf-like replacements to finalize our config
-GIT_VERSION := $(shell ./git-version.sh)
-Doxyfile: Doxyfile.in Makefile
-	sed -e 's/@PACKAGE@/opusfile/' \
-	    -e 's/@VERSION@/$(GIT_VERSION)/' \
+Doxyfile: Doxyfile.in Makefile ../package_version
+	sed -e 's/@PACKAGE_NAME@/opusfile/' \
+	    -e 's/@PACKAGE_VERSION@/$(PACKAGE_VERSION)/' \
 	    -e 's/@top_srcdir@/../' \
 	  < $< > $@
--- a/doc/git-version.sh
+++ /dev/null
@@ -1,13 +1,0 @@
-#!/bin/sh
-
-# script to build a version string
-
-GIT_VERSION=$(git describe --tags --match 'v*' --dirty 2> /dev/null)
-GIT_VERSION=$(echo ${GIT_VERSION} | sed 's/^v//')
-if test -z ${GIT_VERSION}; then
-  VERSION='unknown'
-else
-  VERSION=${GIT_VERSION}
-fi
-
-/bin/echo -n ${VERSION}
--- a/opusfile-uninstalled.pc.in
+++ b/opusfile-uninstalled.pc.in
@@ -7,7 +7,7 @@
 
 Name: opusfile uninstalled
 Description: High-level Opus decoding library (not installed)
-Version: @VERSION@
+Version: @PACKAGE_VERSION@
 Requires.private: ogg >= 1.3 opus >= 1.0.1
 Conflicts:
 Libs: ${libdir}/libopusfile.la @lrintf_lib@
--- a/opusfile.pc.in
+++ b/opusfile.pc.in
@@ -7,7 +7,7 @@
 
 Name: opusfile
 Description: High-level Opus decoding library
-Version: @VERSION@
+Version: @PACKAGE_VERSION@
 Requires.private: ogg >= 1.3 opus >= 1.0.1
 Conflicts:
 Libs: -L${libdir} -lopusfile
--- a/opusurl-uninstalled.pc.in
+++ b/opusurl-uninstalled.pc.in
@@ -7,7 +7,7 @@
 
 Name: opusfile uninstalled
 Description: High-level Opus decoding library, URL support (not installed)
-Version: @VERSION@
+Version: @PACKAGE_VERSION@
 Requires: opusfile
 Requires.private: @openssl@
 Conflicts:
--- a/opusurl.pc.in
+++ b/opusurl.pc.in
@@ -7,7 +7,7 @@
 
 Name: opusurl
 Description: High-level Opus decoding library, URL support
-Version: @VERSION@
+Version: @PACKAGE_VERSION@
 Requires: opusfile
 Requires.private: @openssl@
 Conflicts:
--- /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 <[email protected]>, 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