Skip to content

Commit

Permalink
Fully automate version updating
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ron committed May 13, 2013
1 parent 4986154 commit ff86866
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitattibutes
@@ -0,0 +1,4 @@
.gitignore export-ignore
.gitattributes export-ignore

update_version export-ignore
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -35,6 +35,7 @@ opusfile.pc
opusfile-uninstalled.pc
opusurl.pc
opusurl-uninstalled.pc
package_version
unix/objs
unix/opusfile_example
unix/seeking_example
37 changes: 36 additions & 1 deletion Makefile.am
Expand Up @@ -45,7 +45,6 @@ EXTRA_DIST = \
opusfile-uninstalled.pc.in \
opusurl-uninstalled.pc.in \
doc/Doxyfile.in \
doc/git-version.sh \
doc/opus_logo.svg \
doc/Makefile \
unix/Makefile
Expand Down Expand Up @@ -91,4 +90,40 @@ uninstall-local:

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
21 changes: 17 additions & 4 deletions 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],[opus@xiph.org])
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

Expand Down Expand Up @@ -130,18 +142,19 @@ if test "$HAVE_DOXYGEN" != "yes" -o "$enable_doc" != "yes" ; then
fi
AM_CONDITIONAL(HAVE_DOXYGEN, [test $HAVE_DOXYGEN = yes])

AC_OUTPUT([
AC_CONFIG_FILES([
Makefile
opusfile.pc
opusurl.pc
opusfile-uninstalled.pc
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}
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down
16 changes: 12 additions & 4 deletions doc/Makefile
@@ -1,5 +1,7 @@
## GNU makefile for opusfile documentation.

-include ../package_version

all: doxygen

doxygen: Doxyfile ../include/opusfile.h
Expand All @@ -17,10 +19,16 @@ distclean: clean

.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@/../' \
< $< > $@
13 changes: 0 additions & 13 deletions doc/git-version.sh

This file was deleted.

2 changes: 1 addition & 1 deletion opusfile-uninstalled.pc.in
Expand Up @@ -7,7 +7,7 @@ includedir=${pcfiledir}/@top_srcdir@/include

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@
Expand Down
2 changes: 1 addition & 1 deletion opusfile.pc.in
Expand Up @@ -7,7 +7,7 @@ includedir=@includedir@

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
Expand Down
2 changes: 1 addition & 1 deletion opusurl-uninstalled.pc.in
Expand Up @@ -7,7 +7,7 @@ includedir=${pcfiledir}/@top_srcdir@/include

Name: opusfile uninstalled
Description: High-level Opus decoding library, URL support (not installed)
Version: @VERSION@
Version: @PACKAGE_VERSION@
Requires: opusfile
Requires.private: @openssl@
Conflicts:
Expand Down
2 changes: 1 addition & 1 deletion opusurl.pc.in
Expand Up @@ -7,7 +7,7 @@ includedir=@includedir@

Name: opusurl
Description: High-level Opus decoding library, URL support
Version: @VERSION@
Version: @PACKAGE_VERSION@
Requires: opusfile
Requires.private: @openssl@
Conflicts:
Expand Down
65 changes: 65 additions & 0 deletions update_version
@@ -0,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

0 comments on commit ff86866

Please sign in to comment.