Skip to content

Commit 9d88806

Browse files
committed
Add GIT_COMMIT_HASH to autotools AVRDUDE_FULL_VERSION
Add the GIT_COMMIT_HASH to the version message printed by "avrdude -?" and in the avrdude.conf avrdude_conf_version line. This should produce the same version message in autotools builds as cmake builds produce.
1 parent d77f0eb commit 9d88806

File tree

9 files changed

+407
-160
lines changed

9 files changed

+407
-160
lines changed

src/GNUmakefile.in

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Helps update the version number automatically if using GNU make.
2-
include Makefile
1+
# @configure_input@
32

4-
AUTORECONF ?= autoreconf
5-
AUTORECONF_OPTS ?= -vis
3+
include Makefile
64

7-
script_version := $(shell $(top_srcdir)/build-helpers/package-version $(top_srcdir) version-stamp)
8-
ifneq ($(PACKAGE_VERSION),$(script_version))
9-
$(info autoconf and script versions do not match: $(PACKAGE_VERSION) vs $(script_version))
10-
$(info Removing autom4te.cache and related files and re-running autoreconf)
11-
dummy1 := $(shell rm -rf $(top_srcdir)/autom4te.cache)
12-
dummy2 := $(shell $(AUTORECONF) $(AUTORECONF_OPTS) $(top_srcdir))
5+
need_to_rerun := $(shell $(top_srcdir)/build-helpers/versioninfo.sh "$(top_srcdir)" "@VERSIONINFO_STAMPFILE@" | { @VERSIONINFO_READ@; \
6+
if @VERSIONINFO_IS_UNCHANGED@ \
7+
echo "no"; \
8+
fi; } )
9+
ifneq (no,$(need_to_rerun))
10+
$(info Recorded and current version information do not match.)
11+
$(info Re-running autoreconf via bootstrap.)
12+
dummy1 := $(shell echo $(top_srcdir)/bootstrap)
1313
endif
1414

1515
# vim: syntax=make

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CLEANFILES = \
4040
config_gram.h \
4141
lexer.c
4242

43-
include build-helpers/package-version.mk
43+
include build-helpers/versioninfo.mk
4444

4545
BUILT_SOURCES = $(CLEANFILES)
4646

@@ -248,4 +248,4 @@ backup-avrdude-conf:
248248
${DESTDIR}${sysconfdir}/avrdude.conf.bak; \
249249
fi
250250

251-
ACLOCAL_AMFLAGS = -I m4
251+
ACLOCAL_AMFLAGS = -I m4 -I build-helpers

src/build-helpers/package-version

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

src/build-helpers/package-version.mk

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

src/build-helpers/versioninfo.m4

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# versioninfo.m4 - find avrdude version information for msg -*- Autoconf -*-
2+
# serial 1
3+
dnl | Increment the above serial number every time you edit this file.
4+
dnl | When it finds multiple m4 files with the same name,
5+
dnl | aclocal will use the one with the highest serial.
6+
dnl
7+
dnl The sequence of version info items to store in the version-stamp file.
8+
dnl This must be the same sequence as the versioninfo script writes.
9+
m4_pattern_forbid([versioninfo_items])
10+
m4_define([versioninfo_items], [
11+
[CMAKE_PROJECT_VERSION],
12+
[GIT_COMMIT_DATE],
13+
[GIT_COMMIT_HASH],
14+
[GIT_TAG_HASH]
15+
])
16+
dnl
17+
dnl Initialize version info from the script command given as macro argument.
18+
m4_pattern_forbid([versioninfo_init])
19+
m4_define([versioninfo_init], [
20+
m4_pushdef([versioninfo_split], m4_split(m4_esyscmd($1),m4_newline))
21+
m4_case(m4_sysval, [0], [
22+
m4_for([N], [1], m4_count(versioninfo_split), [1], [
23+
m4_define([versioninfo_]m4_normalize(m4_argn(N, versioninfo_items)),
24+
m4_normalize(m4_argn(N, versioninfo_split)))
25+
])
26+
], [
27+
m4_fatal([versioninfo script returned non-0])
28+
])
29+
])
30+
dnl
31+
m4_define([versioninfo_stampfile], [versioninfo-stamp])
32+
dnl
33+
versioninfo_init([./build-helpers/versioninfo.sh . ]m4_defn([versioninfo_stampfile]))
34+
dnl
35+
dnl
36+
dnl
37+
dnl ========================================================================
38+
dnl VERSIONINFO_SETUP()
39+
dnl ========================================================================
40+
dnl
41+
AC_DEFUN([VERSIONINFO_SETUP], [dnl
42+
m4_foreach([ITEM], [versioninfo_items], [dnl
43+
AC_SUBST(m4_normalize(ITEM), [m4_defn([versioninfo_]m4_normalize(ITEM))])
44+
AC_MSG_CHECKING([versioninfo item ]m4_normalize(ITEM))
45+
AC_MSG_RESULT([$]m4_normalize(ITEM))
46+
])
47+
dnl
48+
dnl Define helper substitutions containing shell code for use inside
49+
dnl make recipes in build-helpers/versioninfo.mk and $(shell ...)
50+
dnl calls in GNUmakefile.in dealing with version info.
51+
dnl
52+
AC_SUBST([VERSIONINFO_STAMPFILE], [m4_defn([versioninfo_stampfile])])
53+
AM_SUBST_NOTMAKE([VERSIONINFO_WRITE])
54+
dnl
55+
AC_SUBST([VERSIONINFO_READ],
56+
['m4_foreach([ITEM], [versioninfo_items], [read m4_normalize(ITEM); ]):'])
57+
AM_SUBST_NOTMAKE([VERSIONINFO_READ])
58+
dnl
59+
AC_SUBST([VERSIONINFO_WRITE],
60+
['printf "%s\n"m4_foreach([ITEM], [versioninfo_items], [ "$(m4_normalize(ITEM))"])'])
61+
AM_SUBST_NOTMAKE([VERSIONINFO_WRITE])
62+
dnl
63+
AC_SUBST([VERSIONINFO_IS_UNCHANGED],
64+
['false; then :; m4_foreach([ITEM], [versioninfo_items], [elif test "x$(m4_normalize(ITEM))" != "x$$m4_normalize(ITEM)"; then printf "%s has changed from %s to %s\n" "m4_normalize(ITEM)" "$(m4_normalize(ITEM))" "$$m4_normalize(ITEM)" >&2; ]) else '])
65+
AM_SUBST_NOTMAKE([VERSIONINFO_IS_UNCHANGED])
66+
dnl
67+
])dnl
68+
dnl
69+
dnl ####################################################################
70+
dnl
71+
dnl Local Variables:
72+
dnl mode: autoconf
73+
dnl End:

src/build-helpers/versioninfo.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
The versioninfo mechanism
2+
=========================
3+
4+
This describes the versioninfo mechanism which automatically generates
5+
the version information for use in `configure.ac` and then the rest of
6+
the autotools build system.
7+
8+
9+
The basic idea
10+
--------------
11+
12+
The main goals are
13+
14+
* Avoid the need for avrdude maintainers to edit the avrdude version
15+
in the autotools buildsystem's `configure.ac` in addition to the
16+
cmake buildsystem's main `CMakeLists.txt` file.
17+
18+
* Have the autotools buildsystem generate the same version message as
19+
the cmake buildsystem in both the `avrdude.conf` file and the
20+
`avrdude -?` output version message.
21+
22+
To achieve this, we need to replicate some of the logic from the
23+
top-level `CMakeLists.txt` which creates the `AVRDUDE_FULL_VERSION`
24+
variable.
25+
26+
We run this logic mostly at bootstrap/autoreconf time, with the
27+
`configure` propagating the information, so that some `make` time
28+
checks can determine whether the bootstrap code needs to be re-run,
29+
and re-run it automatically if possible.
30+
31+
32+
All the different build types
33+
-----------------------------
34+
35+
There are many ways to build avrdude.
36+
37+
There are three types of source trees:
38+
39+
* a git clone's working directory with a `.git/` directory
40+
41+
* an extracted GitHub tarball/zipfile (contains the same as a git
42+
clone's working directory, but no `.git/` directory with its
43+
associated git commit information)
44+
45+
* from a dist tarball as generated by the autotools buildsystem's
46+
`make dist` or `make distcheck` commands (contains the required
47+
git commit information inside the versioninfo-stamp file)
48+
49+
In any of these cases, this can be an avrdude release or non-release,
50+
determined by whether the latest commit's hash is equal to the latest
51+
tag's commit's hash (`GIT_COMMIT_HASH == GIT_TAG_HASH`).
52+
53+
In principle, any of these source types could be built with either the
54+
cmake buildsystem or the autotools buildsystem. With `configure.ac`
55+
being rooted in the `src/` subdirectory though, the dist tarball
56+
generated by `make dist` cannot contain files outside of `src/` which
57+
are required for a cmake build.
58+
59+
In all types of builds, we want the same version message when building
60+
using the autotools buildsystem as the cmake buildsystem creates:
61+
62+
* `7.3` for a release
63+
* `7.3-20240213 (9634fd15)` with commit date and commit hash for a
64+
non-release.
65+
66+
If we abbreviate those types of version messages with `R` for release
67+
and `H` for hash, we can put all cases into a table. `BS` stands for
68+
buildsystem, obviously.
69+
70+
```
71+
Version_Message
72+
SOURCE TYPE BS Release? Wanted Actual
73+
git clone wd cm yes R R
74+
git clone wd cm no H H
75+
github tarball cm yes R R
76+
github tarball cm no H R (wrong/missing info)
77+
dist tarball cm yes R cmake build N/A at this time
78+
dist tarball cm no H cmake build N/A at this time
79+
80+
git clone wd am yes R R
81+
git clone wd am no H H
82+
github tarball am yes R R
83+
github tarball am no H R (wrong/missing info/like cmake)
84+
dist tarball am yes R R
85+
dist tarball am no H H
86+
```
87+
88+
As the github tarball (like the github zipfile) does not contain any
89+
commit/tag information, it is impossible for any buildsystem to
90+
determine whether building a release or non-release.
91+
92+
The dist tarball generated by the autotools buildsystem's `make dist`
93+
does contain the commit/tag information, so builds from such a dist
94+
tarball can correctly determine whether they are building a release or
95+
a non-release source tree. However, only builds using the autotools
96+
buildsystem are possible as long as the `configure.ac` file is located
97+
inside the `src/` subdirectory instead of the top-level directory.
98+
99+
100+
The `build-helpers/versioninfo.sh` script file
101+
----------------------------------------------
102+
103+
The `versioninfo.sh` script tries to determine the version and git
104+
information from the raw sources:
105+
106+
* The version number (`7.3`) is determined from the top-level
107+
`CMakeLists.txt` file's `project(... VERSION ...)` line.
108+
109+
* The information on the latest git commit date and hash and git tag
110+
hash is determined from the `.git/` subdirectory corresponding to
111+
the top-level `CMakeLIsts.txt` file.
112+
113+
The `versioninfo.sh` script then prints these items, one per line.
114+
115+
116+
The `build-helpers/versioninfo.m4` m4 include file
117+
--------------------------------------------------
118+
119+
TODO: Write text.
120+
121+
122+
The `build-helpers/versioninfo.mk` Makefile include file
123+
--------------------------------------------------------
124+
125+
TODO: Write text.
126+
127+
128+
The `configure.ac` file
129+
-----------------------
130+
131+
TODO: Write text.
132+
133+
134+
The `GNUmakefile.in` and `GNUmakefile` files
135+
--------------------------------------------
136+
137+
If you are running GNU make, the `GNUmakefile` file generated from the
138+
`GNUmakefile.in` file will update the versioninfo automatically before
139+
executing any possible make recipes.
140+
141+
If you are not running GNU make, you will need to run the command to
142+
update the versioninfo update command manually. You will be shown that
143+
command if necessary.

0 commit comments

Comments
 (0)