Skip to content

Commit ff86866

Browse files
author
Ron
committed
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.
1 parent 4986154 commit ff86866

12 files changed

+141
-28
lines changed

.gitattibutes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitignore export-ignore
2+
.gitattributes export-ignore
3+
4+
update_version export-ignore

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ opusfile.pc
3535
opusfile-uninstalled.pc
3636
opusurl.pc
3737
opusurl-uninstalled.pc
38+
package_version
3839
unix/objs
3940
unix/opusfile_example
4041
unix/seeking_example

Makefile.am

+36-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ EXTRA_DIST = \
4545
opusfile-uninstalled.pc.in \
4646
opusurl-uninstalled.pc.in \
4747
doc/Doxyfile.in \
48-
doc/git-version.sh \
4948
doc/opus_logo.svg \
5049
doc/Makefile \
5150
unix/Makefile
@@ -91,4 +90,40 @@ uninstall-local:
9190

9291
endif
9392

93+
# We check this every time make is run, with configure.ac being touched to
94+
# trigger an update of the build system files if update_version changes the
95+
# current PACKAGE_VERSION (or if package_version was modified manually by a
96+
# user with either AUTO_UPDATE=no or no update_version script present - the
97+
# latter being the normal case for tarball releases).
98+
#
99+
# We can't just add the package_version file to CONFIGURE_DEPENDENCIES since
100+
# simply running autoconf will not actually regenerate configure for us when
101+
# the content of that file changes (due to autoconf dependency checking not
102+
# knowing about that without us creating yet another file for it to include).
103+
#
104+
# The MAKECMDGOALS check is a gnu-make'ism, but will degrade 'gracefully' for
105+
# makes that don't support it. The only loss of functionality is not forcing
106+
# an update of package_version for `make dist` if AUTO_UPDATE=no, but that is
107+
# unlikely to be a real problem for any real user.
108+
$(top_srcdir)/configure.ac: force
109+
@case "$(MAKECMDGOALS)" in \
110+
dist-hook) exit 0 ;; \
111+
dist-* | dist | distcheck | distclean) _arg=release ;; \
112+
esac; \
113+
if ! $(top_srcdir)/update_version $$_arg 2> /dev/null; then \
114+
if [ ! -e $(top_srcdir)/package_version ]; then \
115+
echo 'PACKAGE_VERSION="unknown"' > $(top_srcdir)/package_version; \
116+
fi; \
117+
. $(top_srcdir)/package_version || exit 1; \
118+
[ "$(PACKAGE_VERSION)" != "$$PACKAGE_VERSION" ] || exit 0; \
119+
fi; \
120+
touch $@
121+
122+
force:
123+
124+
# Create a minimal package_version file when make dist is run.
125+
dist-hook:
126+
echo 'PACKAGE_VERSION="$(PACKAGE_VERSION)"' > $(top_distdir)/package_version
127+
128+
94129
.PHONY: opusfile install-opusfile docs install-docs

configure.ac

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# autoconf source script for generating configure
22

3-
AC_INIT([opusfile], m4_esyscmd([doc/git-version.sh]))
3+
dnl The package_version file will be automatically synced to the git revision
4+
dnl by the update_version script when configured in the repository, but will
5+
dnl remain constant in tarball releases unless it is manually edited.
6+
m4_define([CURRENT_VERSION],
7+
m4_esyscmd_s([ if test -e package_version || ./update_version; then
8+
. ./package_version
9+
printf "$PACKAGE_VERSION"
10+
else
11+
printf "unknown"
12+
fi ]))
13+
14+
AC_INIT([opusfile],[CURRENT_VERSION],[[email protected]])
15+
AC_CONFIG_SRCDIR([src/opusfile.c])
416

517
AC_USE_SYSTEM_EXTENSIONS
618
AC_SYS_LARGEFILE
719

8-
AM_INIT_AUTOMAKE([1.11 foreign])
20+
AM_INIT_AUTOMAKE([1.11 foreign no-define])
921
AM_MAINTAINER_MODE([enable])
1022
LT_INIT
1123

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

133-
AC_OUTPUT([
145+
AC_CONFIG_FILES([
134146
Makefile
135147
opusfile.pc
136148
opusurl.pc
137149
opusfile-uninstalled.pc
138150
opusurl-uninstalled.pc
139151
doc/Doxyfile
140152
])
153+
AC_OUTPUT
141154

142155
AC_MSG_NOTICE([
143156
------------------------------------------------------------------------
144-
$PACKAGE $VERSION: Automatic configuration OK.
157+
$PACKAGE_NAME $PACKAGE_VERSION: Automatic configuration OK.
145158
146159
Assertions ................... ${enable_assertions}
147160

doc/Doxyfile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Process with doxygen to generate API documentation
22

3-
PROJECT_NAME = @PACKAGE@
4-
PROJECT_NUMBER = @VERSION@
3+
PROJECT_NAME = @PACKAGE_NAME@
4+
PROJECT_NUMBER = @PACKAGE_VERSION@
55
PROJECT_BRIEF = "Stand-alone decoder library for .opus files."
66
INPUT = @top_srcdir@/include/opusfile.h
77
OPTIMIZE_OUTPUT_FOR_C = YES

doc/Makefile

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## GNU makefile for opusfile documentation.
22

3+
-include ../package_version
4+
35
all: doxygen
46

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

1820
.PHONY: all clean distclean doxygen pdf
1921

22+
../package_version:
23+
@if [ -x ../update_version ]; then \
24+
../update_version || true; \
25+
elif [ ! -e $@ ]; then \
26+
echo 'PACKAGE_VERSION="unknown"' > $@; \
27+
fi
28+
2029
# run autoconf-like replacements to finalize our config
21-
GIT_VERSION := $(shell ./git-version.sh)
22-
Doxyfile: Doxyfile.in Makefile
23-
sed -e 's/@PACKAGE@/opusfile/' \
24-
-e 's/@VERSION@/$(GIT_VERSION)/' \
30+
Doxyfile: Doxyfile.in Makefile ../package_version
31+
sed -e 's/@PACKAGE_NAME@/opusfile/' \
32+
-e 's/@PACKAGE_VERSION@/$(PACKAGE_VERSION)/' \
2533
-e 's/@top_srcdir@/../' \
2634
< $< > $@

doc/git-version.sh

-13
This file was deleted.

opusfile-uninstalled.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includedir=${pcfiledir}/@top_srcdir@/include
77

88
Name: opusfile uninstalled
99
Description: High-level Opus decoding library (not installed)
10-
Version: @VERSION@
10+
Version: @PACKAGE_VERSION@
1111
Requires.private: ogg >= 1.3 opus >= 1.0.1
1212
Conflicts:
1313
Libs: ${libdir}/libopusfile.la @lrintf_lib@

opusfile.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includedir=@includedir@
77

88
Name: opusfile
99
Description: High-level Opus decoding library
10-
Version: @VERSION@
10+
Version: @PACKAGE_VERSION@
1111
Requires.private: ogg >= 1.3 opus >= 1.0.1
1212
Conflicts:
1313
Libs: -L${libdir} -lopusfile

opusurl-uninstalled.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includedir=${pcfiledir}/@top_srcdir@/include
77

88
Name: opusfile uninstalled
99
Description: High-level Opus decoding library, URL support (not installed)
10-
Version: @VERSION@
10+
Version: @PACKAGE_VERSION@
1111
Requires: opusfile
1212
Requires.private: @openssl@
1313
Conflicts:

opusurl.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includedir=@includedir@
77

88
Name: opusurl
99
Description: High-level Opus decoding library, URL support
10-
Version: @VERSION@
10+
Version: @PACKAGE_VERSION@
1111
Requires: opusfile
1212
Requires.private: @openssl@
1313
Conflicts:

update_version

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Creates and updates the package_version information used by configure.ac
4+
# (or other makefiles). When run inside a git repository it will use the
5+
# version information that can be queried from it unless AUTO_UPDATE is set
6+
# to 'no'. If no version is currently known it will be set to 'unknown'.
7+
#
8+
# If called with the argument 'release', the PACKAGE_VERSION will be updated
9+
# even if AUTO_UPDATE=no, but the value of AUTO_UPDATE shall be preserved.
10+
# This is used to force a version update whenever `make dist` is run.
11+
#
12+
# The exit status is 1 if package_version is not modified, else 0 is returned.
13+
#
14+
# This script should NOT be included in distributed tarballs, because if a
15+
# parent directory contains a git repository we do not want to accidentally
16+
# retrieve the version information from it instead. Tarballs should ship
17+
# with only the package_version file.
18+
#
19+
# Ron <[email protected]>, 2012.
20+
21+
SRCDIR=$(dirname $0)
22+
23+
if [ -e "$SRCDIR/package_version" ]; then
24+
. "$SRCDIR/package_version"
25+
fi
26+
27+
if [ "$AUTO_UPDATE" = no ]; then
28+
[ "$1" = release ] || exit 1
29+
else
30+
AUTO_UPDATE=yes
31+
fi
32+
33+
# We run `git status` before describe here to ensure that we don't get a false
34+
# -dirty from files that have been touched but are not actually altered in the
35+
# working dir.
36+
GIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \
37+
&& git describe --tags --match 'v*' --dirty 2> /dev/null)
38+
GIT_VERSION=${GIT_VERSION#v}
39+
40+
if [ -n "$GIT_VERSION" ]; then
41+
42+
[ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1
43+
PACKAGE_VERSION="$GIT_VERSION"
44+
45+
elif [ -z "$PACKAGE_VERSION" ]; then
46+
# No current package_version and no git ...
47+
# We really shouldn't ever get here, because this script should only be
48+
# included in the git repository, and should usually be export-ignored.
49+
PACKAGE_VERSION="unknown"
50+
else
51+
exit 1
52+
fi
53+
54+
cat > "$SRCDIR/package_version" <<-EOF
55+
# Automatically generated by update_version.
56+
# This file may be sourced into a shell script or makefile.
57+
58+
# Set this to 'no' if you do not wish the version information
59+
# to be checked and updated for every build. Most people will
60+
# never want to change this, it is an option for developers
61+
# making frequent changes that they know will not be released.
62+
AUTO_UPDATE=$AUTO_UPDATE
63+
64+
PACKAGE_VERSION="$PACKAGE_VERSION"
65+
EOF

0 commit comments

Comments
 (0)