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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 36 additions & 1 deletion
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

Lines changed: 17 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 4 deletions
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

Lines changed: 0 additions & 13 deletions
This file was deleted.

opusfile-uninstalled.pc.in

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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:

0 commit comments

Comments
 (0)