Makefile: add dependency on external header versions.

There were a few reports that upgrading Ubuntu recently caused issues
because we assert that the sqlite3 library version matches the one we
were built with. 'make' doesn't fix this, because it doesn't know the
external libraries have changed.

Fix this harder, with a helper which updates a file every binary depends
on, which gets relinked every time so we detect link changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-12-11 10:00:53 +10:30
parent a304db9be2
commit 2a90325e80
2 changed files with 57 additions and 2 deletions

View file

@ -334,8 +334,16 @@ gen_version.h: FORCE
@(echo "#define VERSION \"$(VERSION)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new
@if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; echo Version updated; fi
# All binaries require the external libs, ccan
$(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS): $(EXTERNAL_LIBS) $(CCAN_OBJS)
# We force make to relink this every time, to detect version changes.
tools/headerversions: FORCE tools/headerversions.o $(CCAN_OBJS)
@$(LINK.o) tools/headerversions.o $(CCAN_OBJS) $(LOADLIBES) $(LDLIBS) -o $@
# That forces this rule to be run every time, too.
gen_header_versions.h: tools/headerversions
@tools/headerversions $@
# All binaries require the external libs, ccan and external library versions.
$(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS): $(EXTERNAL_LIBS) $(CCAN_OBJS) gen_header_versions.h
# Each test program depends on its own object.
$(ALL_TEST_PROGRAMS): %: %.o

47
tools/headerversions.c Normal file
View file

@ -0,0 +1,47 @@
/* Updates the given file if any library versions have changed. This
* is important for systemwide updates, such as sqlite3. */
#include <ccan/err/err.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/str/str.h>
#include <errno.h>
#include <fcntl.h>
#include <gmp.h>
#include <sqlite3.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <zlib.h>
int main(int argc, char *argv[])
{
char *file, *new;
err_set_progname(argv[0]);
if (argc != 2)
errx(1, "Usage: %s <versionheader>", argv[0]);
file = grab_file(NULL, argv[1]);
if (!file && errno != ENOENT)
err(1, "Reading %s", argv[1]);
new = tal_fmt(NULL,
"/* Generated file by tools/headerversions, do not edit! */\n"
"/* GMP version: %s */\n"
"/* SQLITE3 version: %u */\n"
"/* ZLIB version: %s */\n",
gmp_version,
sqlite3_libversion_number(),
zlibVersion());
if (!file || !streq(new, file)) {
int fd = open(argv[1], O_TRUNC|O_WRONLY|O_CREAT, 0666);
if (fd < 0)
err(1, "Writing %s", argv[1]);
if (!write_all(fd, new, strlen(new)))
err(1, "Writing to %s", argv[1]);
close(fd);
}
tal_free(new);
tal_free(file);
return 0;
}