mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
Before: Ten builds, laptop -j5, no ccache: ``` real 0m36.686000-38.956000(38.608+/-0.65)s user 2m32.864000-42.253000(40.7545+/-2.7)s sys 0m16.618000-18.316000(17.8531+/-0.48)s ``` Ten builds, laptop -j5, ccache (warm): ``` real 0m8.212000-8.577000(8.39989+/-0.13)s user 0m12.731000-13.212000(12.9751+/-0.17)s sys 0m3.697000-3.902000(3.83722+/-0.064)s ``` After: Ten builds, laptop -j5, no ccache: 8% faster ``` real 0m33.802000-35.773000(35.468+/-0.54)s user 2m19.073000-27.754000(26.2542+/-2.3)s sys 0m15.784000-17.173000(16.7165+/-0.37)s ``` Ten builds, laptop -j5, ccache (warm): 1% faster ``` real 0m8.200000-8.485000(8.30138+/-0.097)s user 0m12.485000-13.100000(12.7344+/-0.19)s sys 0m3.702000-3.889000(3.78787+/-0.056)s ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
82 lines
2.4 KiB
C
82 lines
2.4 KiB
C
/* Updates the given file if any library versions have changed. This
|
|
* is important for systemwide updates, such as sqlite3. */
|
|
#include "config.h"
|
|
#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>
|
|
#if HAVE_SQLITE3
|
|
# include <sqlite3.h>
|
|
# define IF_SQLITE3(...) __VA_ARGS__
|
|
#else
|
|
# define IF_SQLITE3(...)
|
|
#endif
|
|
#include <zlib.h>
|
|
|
|
static const char template[] =
|
|
"/* Generated file by tools/headerversions, do not edit! */\n"
|
|
"/* GMP version: %s */\n"
|
|
IF_SQLITE3("/* SQLITE3 version: %u */\n")
|
|
"/* ZLIB version: %s */\n"
|
|
"#include <ccan/err/err.h>\n"
|
|
"#include <gmp.h>\n"
|
|
IF_SQLITE3("#include <sqlite3.h>\n")
|
|
"#include <zlib.h>\n"
|
|
"\n"
|
|
"static inline void check_linked_library_versions(void)\n"
|
|
"{\n"
|
|
" char compiled_gmp_version[100];\n"
|
|
IF_SQLITE3(
|
|
" if (SQLITE_VERSION_NUMBER != sqlite3_libversion_number())\n"
|
|
" errx(1, \"SQLITE version mismatch: compiled %%u, now %%u\",\n"
|
|
" SQLITE_VERSION_NUMBER, sqlite3_libversion_number());\n"
|
|
)
|
|
" /* zlib documents that first char alters ABI. Kudos! */\n"
|
|
" if (zlibVersion()[0] != ZLIB_VERSION[0])\n"
|
|
" errx(1, \"zlib version mismatch: compiled %%s, now %%s\",\n"
|
|
" ZLIB_VERSION, zlibVersion());\n"
|
|
" /* GMP doesn't say anything, and we have to assemble our own string. */\n"
|
|
" snprintf(compiled_gmp_version, sizeof(compiled_gmp_version),\n"
|
|
" \"%%u.%%u.%%u\",\n"
|
|
" __GNU_MP_VERSION,\n"
|
|
" __GNU_MP_VERSION_MINOR,\n"
|
|
" __GNU_MP_VERSION_PATCHLEVEL);\n"
|
|
" if (strcmp(compiled_gmp_version, gmp_version) != 0)\n"
|
|
" errx(1, \"gmp version mismatch: compiled %%s, now %%s\",\n"
|
|
" compiled_gmp_version, gmp_version);\n"
|
|
"}\n";
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
char *file, *new;
|
|
|
|
/* We don't bother with setup_locale(); we're a build tool */
|
|
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, template,
|
|
gmp_version,
|
|
IF_SQLITE3(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;
|
|
}
|