Skip to content
Snippets Groups Projects
Commit 2f2f9d63 authored by Ron's avatar Ron
Browse files

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.

The version.mk file is now only used by the VC project files.  Once they
are updated to use the package_version file too, then it can be deleted
from the repository.
parent 80c4834c
No related branches found
No related tags found
No related merge requests found
update_version export-ignore
......@@ -51,6 +51,7 @@ celt/tests/test_unit_types
*.vcxproj.user
opus.sdf
opus.suo
package_version
version.h
celt/Debug
celt/Release
......
......@@ -150,4 +150,37 @@ uninstall-local:
( cd doc && $(MAKE) $(AM_MAKEFLAGS) uninstall )
# 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 \
. $(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: opus check-opus install-opus docs install-docs
......@@ -20,8 +20,8 @@ CFLAGS := -Drestrict= $(CFLAGS)
###################### END OF OPTIONS ######################
include version.mk
CFLAGS += -DOPUS_VERSION='$(OPUS_VERSION)'
-include package_version
include silk_sources.mk
include celt_sources.mk
include opus_sources.mk
......@@ -124,5 +124,13 @@ opus_demo$(EXESUFFIX): $(OPUSDEMO_OBJS) $(TARGET)
opus_compare$(EXESUFFIX): $(OPUSCOMPARE_OBJS)
$(LINK.o.cmdline)
celt/celt.o: CFLAGS += -DPACKAGE_VERSION='$(PACKAGE_VERSION)'
celt/celt.o: package_version
package_version: force
@./update_version || true
force:
clean:
rm -f opus_demo$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) $(OBJS) $(OPUSDEMO_OBJS)
......@@ -50,6 +50,10 @@
#include "celt_lpc.h"
#include "vq.h"
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "unknown"
#endif
int resampling_factor(opus_int32 rate)
{
......@@ -193,7 +197,7 @@ const char *opus_strerror(int error)
const char *opus_get_version_string(void)
{
return "libopus " OPUS_VERSION
return "libopus " PACKAGE_VERSION
#ifdef FIXED_POINT
"-fixed"
#endif
......
......@@ -131,10 +131,6 @@ int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned cha
#define celt_decoder_ctl opus_custom_decoder_ctl
#ifndef OPUS_VERSION
#define OPUS_VERSION "unknown"
#endif
#ifdef CUSTOM_MODES
#define OPUS_CUSTOM_NOSTATIC
#else
......
dnl Process this file with autoconf to produce a configure script. -*-m4-*-
AC_INIT(src/opus_encoder.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_s([ 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],[CURRENT_VERSION],[opus@xiph.org])
AC_CONFIG_SRCDIR(src/opus_encoder.c)
dnl enable silent rules on automake 1.11 and later
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
# Read our default version string from version.mk.
# Please update this file for releases.
AC_MSG_CHECKING([version.mk])
MK_VERSION=$(awk 'BEGIN { FS = "=" }
/OPUS_VERSION/ { ver = $2}
END {
gsub(/"/, "", ver);
gsub(/^ /, "", ver);
gsub(/ $/, "", ver);
print ver;
}' $srcdir/version.mk)
if test -z "$MK_VERSION"; then
AC_MSG_RESULT([no])
else
AC_MSG_RESULT([$MK_VERSION])
OPUS_VERSION="$MK_VERSION"
fi
# Override with the git version, if available.
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])
OPUS_VERSION="$GIT_VERSION"
fi
# Use 'unknown' if all else fails.
if test -z "$OPUS_VERSION"; then
OPUS_VERSION="unknown"
fi
# For automake.
PACKAGE=opus
VERSION=$OPUS_VERSION
# For autoconf
AC_SUBST(OPUS_VERSION)
# For config.h.
AC_DEFINE_UNQUOTED([OPUS_VERSION], ["$OPUS_VERSION"],
[Opus library version string])
# For libtool.
dnl Please update these for releases.
......@@ -61,7 +29,7 @@ AC_SUBST(OPUS_LT_CURRENT)
AC_SUBST(OPUS_LT_REVISION)
AC_SUBST(OPUS_LT_AGE)
AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
AM_INIT_AUTOMAKE([no-define])
AM_MAINTAINER_MODE([enable])
AC_CANONICAL_HOST
......@@ -294,13 +262,14 @@ AC_SUBST([PC_LIBM])
AC_CONFIG_FILES([Makefile opus.pc opus-uninstalled.pc
doc/Makefile doc/Doxyfile])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT
AC_MSG_RESULT([
------------------------------------------------------------------------
$PACKAGE $VERSION: Automatic configuration OK.
$PACKAGE_NAME $PACKAGE_VERSION: Automatic configuration OK.
Compiler support:
C99 var arrays: ................ ${has_var_arrays}
......
#!/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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment