From ef441f58d3bf9f2fe4e918bee69d580d3e062cae Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Wed, 31 Jul 2024 14:32:35 +0200 Subject: [PATCH 1/6] Elaborate comments on versioninfo_* Elaborate a bit more on the VERSIONINFO_* and versioninfo_* m4 macros. This should help me get back into things when I come back to this in a year or so and have forgotten most of the details. --- src/configure.ac | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/configure.ac b/src/configure.ac index b1e3102c..b4d053e9 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -32,9 +32,10 @@ dnl 2018-02-25 automake 1.16 dnl 2018-03-11 automake 1.16.1 install-sh symlink fix -dnl Change this definition if you want to change the dist tarball name -dnl pattern from avrdude-7.3 for releases and avrdude-7.3-${COMMIT_DATE} -dnl for snapshots. +dnl Define the dist tarball name as +dnl * avrdude-7.3 for releases +dnl * avrdude-7.3-${COMMIT_DATE} for snapshots +dnl just like CMakeLists.txt does. m4_define([versioninfo_AVRDUDE_PACKAGE_VERSION], m4_case(m4_defn([versioninfo_GIT_COMMIT_HASH]), m4_defn([versioninfo_GIT_TAG_HASH]), @@ -64,6 +65,9 @@ AM_INIT_AUTOMAKE([ AM_SILENT_RULES([yes]) +dnl Set up the macro definitions for versioninfo_* which we hand to AC_INIT. +dnl Yes, it does work to expand the VERSIONINFO_SETUP macro *after* AC_INIT. +dnl For details, see the build-helpers/versioninfo.{md,m4,mk,sh} files. VERSIONINFO_SETUP() dnl Inform about the derived PACKAGE_VERSION From 50751ee5b37c3b945a127c71288841c5062eae6e Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Wed, 31 Jul 2024 17:32:56 +0200 Subject: [PATCH 2/6] configure.ac: Guard macros with m4_pattern_forbid Guard m4 macro calls with m4_pattern_forbid for all macros which do not come with Autoconf/Automake. All other macros might not be present on the system, and it is better to m4_pattern_forbid them and have autoreconf fail, than to have autoreconf generate a malformed broken configure script which then always fails with a weird error message. --- src/configure.ac | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/configure.ac b/src/configure.ac index b4d053e9..bb340f72 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -64,10 +64,13 @@ AM_INIT_AUTOMAKE([ AM_SILENT_RULES([yes]) - dnl Set up the macro definitions for versioninfo_* which we hand to AC_INIT. -dnl Yes, it does work to expand the VERSIONINFO_SETUP macro *after* AC_INIT. +dnl +dnl Yes, it does work to expand the VERSIONINFO_SETUP macro *after* AC_INIT: +dnl The presence of VERSIONINFO_SETUP pulls in the definitions at the top. +dnl dnl For details, see the build-helpers/versioninfo.{md,m4,mk,sh} files. +m4_pattern_forbid([VERSIONINFO_SETUP])dnl VERSIONINFO_SETUP() dnl Inform about the derived PACKAGE_VERSION @@ -97,13 +100,17 @@ AC_PROG_SED AC_PROG_YACC AC_PROG_LEX([noyywrap]) AM_PROG_AR + +m4_pattern_forbid([LT_INIT])dnl LT_INIT() -# If macro PKG_PROG_PKG_CONFIG is not available, Autoconf generates a misleading error message, -# so check for existence first, and otherwise provide helpful advice. +dnl If macro PKG_PROG_PKG_CONFIG is not available, Autoconf generates +dnl a misleading error message, so check for existence first, and +dnl otherwise provide helpful advice. m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal(m4_normalize([ Macro PKG_PROG_PKG_CONFIG is not available. It is usually defined in file pkg.m4 provided by package pkg-config.]))]) +m4_pattern_forbid([PKG_PROG_PKG_CONFIG])dnl PKG_PROG_PKG_CONFIG([0.23]) AH_TEMPLATE([HAVE_YYLEX_DESTROY], From 0b82a1f124a1deafe48afc79e1c587f9048526a6 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Sun, 25 Feb 2024 16:25:33 +0100 Subject: [PATCH 3/6] CI: no need to install gettext for linux autotools test --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a583fa96..d87a7b2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,6 @@ jobs: build-essential automake libtool - gettext flex bison libelf-dev From a74c58b32aedd282cbb564f0ba66bf7edc4d55a2 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 20 Feb 2024 01:46:32 +0100 Subject: [PATCH 4/6] Keep workaround for no-dist-built-files not being available As no-dist-built-files was only introduced in Automake 1.16.4, we cannot rely on that feature being present and need to continue using our own workaround. This hooks the dist-hook in a more robust fashion in the face of multiple dist-hook targets (and versioninfo.mk already uses one). --- src/Makefile.am | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index fc978271..3d7ac11f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,15 +31,19 @@ EXTRA_DIST = \ avrdude.spec \ bootstrap -CLEANFILES = \ - config_gram.c \ - config_gram.h \ - lexer.c +BUILT_SOURCES = +CLEANFILES = + +built_sources = +built_sources += config_gram.c +built_sources += config_gram.h +built_sources += lexer.c + +BUILT_SOURCES += $(built_sources) +CLEANFILES += $(built_sources) include build-helpers/versioninfo.mk -BUILT_SOURCES = $(CLEANFILES) - #SUBDIRS = doc #DIST_SUBDIRS = doc @@ -77,11 +81,12 @@ lib_LTLIBRARIES = libavrdude.la # https://savannah.nongnu.org/bugs/index.php?func=detailitem&item_id=15536 # # for why we don't want to have them. -dist-hook: - rm -f \ - $(distdir)/lexer.c \ - $(distdir)/config_gram.c \ - $(distdir)/config_gram.h +# +# We could avoid this dist-hook altogether if we could require +# Automake >= 1.16.4 and just use its no-dist-built-sources flag. +dist-hook: dist-hook-no-dist-built-sources-workaround +dist-hook-no-dist-built-sources-workaround: + cd "$(distdir)" && rm -f $(built_sources) libavrdude_a_SOURCES = \ config_gram.y \ From dfe14e63ae1b2c051b935d3b78392a72d1873fa0 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Thu, 1 Aug 2024 00:05:06 +0200 Subject: [PATCH 5/6] Only build and use libavrdude as a libtool library As libtool is supposed to be able to build libraries for every target system, we delegate library building to libtool and stop building our own static libavrdude.a library. You can control whether the static/dynamic library is built by using the --(disable|enable)-(static|dynamic) configure flags. --- src/Makefile.am | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 3d7ac11f..55ca6ec4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -57,19 +57,16 @@ AM_YFLAGS = -d avrdude_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" -libavrdude_a_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" -libavrdude_la_CPPFLAGS = $(libavrdude_a_CPPFLAGS) +libavrdude_la_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" avrdude_CFLAGS = @ENABLE_WARNINGS@ -libavrdude_a_CFLAGS = @ENABLE_WARNINGS@ $(LIBGPIOD_CFLAGS) -libavrdude_la_CFLAGS = $(libavrdude_a_CFLAGS) +libavrdude_la_CFLAGS = @ENABLE_WARNINGS@ $(LIBGPIOD_CFLAGS) -avrdude_LDADD = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB_1_0@ @LIBHIDAPI@ @LIBUSB@ @LIBFTDI1@ @LIBFTDI@ @LIBHID@ @LIBELF@ @LIBPTHREAD@ @LIBSERIALPORT@ $(LIBGPIOD_LIBS) -lm +avrdude_LDADD = libavrdude.la @LIBUSB_1_0@ @LIBHIDAPI@ @LIBUSB@ @LIBFTDI1@ @LIBFTDI@ @LIBHID@ @LIBELF@ @LIBPTHREAD@ @LIBSERIALPORT@ $(LIBGPIOD_LIBS) -lm bin_PROGRAMS = avrdude -noinst_LIBRARIES = libavrdude.a lib_LTLIBRARIES = libavrdude.la # automake thinks these generated files should be in the distribution, @@ -88,7 +85,7 @@ dist-hook: dist-hook-no-dist-built-sources-workaround dist-hook-no-dist-built-sources-workaround: cd "$(distdir)" && rm -f $(built_sources) -libavrdude_a_SOURCES = \ +libavrdude_la_SOURCES = \ config_gram.y \ lexer.l \ arduino.h \ @@ -223,7 +220,6 @@ libavrdude_a_SOURCES = \ wiring.c \ xbee.h \ xbee.c -libavrdude_la_SOURCES = $(libavrdude_a_SOURCES) libavrdude_la_LDFLAGS = -version-info 2:0 include_HEADERS = libavrdude.h From c4d903e155608459daf6bdf28b4152d9df0dc669 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Wed, 14 Feb 2024 04:54:09 +0100 Subject: [PATCH 6/6] Use cmake libavrdude SOVERSION/VERSION for autotools This transfers the information from the CMakeLists.txt libavrdude VERSION and SOVERSION into the autotools configure script and (partly) uses the information to build the libavrdude.la libtool library. At this time, VERSION must always be SOVERSION.0.0 for this to work (and that is checked). --- src/Makefile.am | 2 +- src/build-helpers/versioninfo.m4 | 2 ++ src/build-helpers/versioninfo.sh | 34 +++++++++++++++++++++++++++++++- src/configure.ac | 27 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 55ca6ec4..5b995756 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -220,7 +220,7 @@ libavrdude_la_SOURCES = \ wiring.c \ xbee.h \ xbee.c -libavrdude_la_LDFLAGS = -version-info 2:0 +libavrdude_la_LDFLAGS = -version-info @LIBAVRDUDE_VERSION_INFO@ include_HEADERS = libavrdude.h include_HEADERS += libavrdude-avrintel.h diff --git a/src/build-helpers/versioninfo.m4 b/src/build-helpers/versioninfo.m4 index 30e36d6e..1fa441ef 100644 --- a/src/build-helpers/versioninfo.m4 +++ b/src/build-helpers/versioninfo.m4 @@ -9,6 +9,8 @@ dnl This must be the same sequence as the versioninfo script writes. m4_pattern_forbid([versioninfo_items]) m4_define([versioninfo_items], [ [CMAKE_PROJECT_VERSION], + [CMAKE_LIBAVRDUDE_VERSION], + [CMAKE_LIBAVRDUDE_SOVERSION], [GIT_COMMIT_DATE], [GIT_COMMIT_HASH], [GIT_TAG_HASH] diff --git a/src/build-helpers/versioninfo.sh b/src/build-helpers/versioninfo.sh index 58ebc9c6..4ca2a95e 100755 --- a/src/build-helpers/versioninfo.sh +++ b/src/build-helpers/versioninfo.sh @@ -89,6 +89,36 @@ test -n "$PROJECT_VERSION" || \ ret_error "Cannot find project(...) in top-level avrdude 'CMakeLists.txt'" +# Parse libavrdude library version from CMakeLists.txt +tmp="$(${AWK-awk} ' +BEGIN { v=0; } +($1 == "set_target_properties(libavrdude") { v=1; } +(v == 1) && /^[[:space:]]+\)/ { v=0; } +(v == 1) && /^[[:space:]]+VERSION[[:space:]]+/ { version=$2; } +(v == 1) && /^[[:space:]]+SOVERSION[[:space:]]+/ { soversion=$2; } +END { print version; + print soversion; } +' < "$top_srcdir/CMakeLists.txt")" + + +# Extract the libavrdude VERSION +CMAKE_LIBAVRDUDE_VERSION="$(printf "%s\n" "$tmp" | { \ + read LIB_VERSION; read LIB_SOVERSION; \ + printf "%s\n" "$LIB_VERSION"; })" + +test -n "$CMAKE_LIBAVRDUDE_VERSION" || \ + ret_error "Cannot find library VERSION in library 'CMakeLists.txt'" + + +# Extract the libavrdude SOVERSION +CMAKE_LIBAVRDUDE_SOVERSION="$(printf "%s\n" "$tmp" | { \ + read LIB_VERSION; read LIB_SOVERSION; \ + printf "%s\n" "$LIB_SOVERSION"; })" + +test -n "$CMAKE_LIBAVRDUDE_SOVERSION" || \ + ret_error "Cannot find library SOVERSION in library 'CMakeLists.txt'" + + # If GIT_DIR is set, use it. If not, try "$top_srcdir/../.git". test -n "$GIT_DIR" || { \ GIT_DIR="$top_srcdir/../.git"; \ @@ -106,11 +136,13 @@ if test -d "$GIT_DIR" && ${GIT-git} --version > /dev/null 2>&1; then ret_error "$prog: Cannot run 'git log' for tag hash" # This must be the same sequence as versioninfo_items in configure.ac ret_ok "${PROJECT_VERSION}" \ + "${CMAKE_LIBAVRDUDE_VERSION}" "${CMAKE_LIBAVRDUDE_SOVERSION}" \ "${GIT_COMMIT_DATE}" "${GIT_COMMIT_HASH}" "${GIT_TAG_HASH}" else # This is a github release tarball or github snapshot tarball # Presume this is a release version, because who would build a # non-release version from a snapshot tarball? - ret_ok "${PROJECT_VERSION}" + ret_ok "${PROJECT_VERSION}" \ + "${CMAKE_LIBAVRDUDE_VERSION}" "${CMAKE_LIBAVRDUDE_SOVERSION}" fi diff --git a/src/configure.ac b/src/configure.ac index bb340f72..2abf9219 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -92,6 +92,33 @@ AC_DEFINE_UNQUOTED([AVRDUDE_FULL_VERSION], ["$AVRDUDE_FULL_VERSION"], AC_SUBST([AVRDUDE_FULL_VERSION]) +# Define libavrdude libtool version from cmake libavrdude information +dnl +dnl This is a very simple consistency check. If this check ever fails, +dnl the library versioning policy and its technical implementation +dnl must be adapted. +m4_case(m4_defn([versioninfo_CMAKE_LIBAVRDUDE_SOVERSION])[.0.0], + m4_defn([versioninfo_CMAKE_LIBAVRDUDE_VERSION]), + [], + [m4_fatal([ +The cmake libavrdude VERSION should be SOVERSION.0.0 ("]m4_defn([versioninfo_CMAKE_LIBAVRDUDE_SOVERSION])[.0.0"), +but it is actually "]m4_defn([versioninfo_CMAKE_LIBAVRDUDE_VERSION])[". + +This is an internal error in the logic which transfers library version +information from the cmake buildsystem to the automake buildsystem. + +Please file a GitHub issue for avrdude and mention @ndim. + ])])dnl +dnl +AC_MSG_CHECKING([versioninfo derived libtool -version-info for libavrdude]) +libavrdude_lt_cur=$CMAKE_LIBAVRDUDE_SOVERSION +libavrdude_lt_rev=0 +libavrdude_lt_age=0 +AC_SUBST([LIBAVRDUDE_VERSION_INFO], + [${libavrdude_lt_cur}:${libavrdude_lt_rev}:${libavrdude_lt_age}]) +AC_MSG_RESULT([$LIBAVRDUDE_VERSION_INFO]) + + # Checks for programs. AC_PROG_CC AC_PROG_INSTALL