2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <ccan/compiler/compiler.h>
|
2023-06-02 04:36:04 +02:00
|
|
|
#include <common/configvar.h>
|
2021-12-04 12:23:56 +01:00
|
|
|
#include <common/version.h>
|
2015-08-08 13:15:49 +02:00
|
|
|
#include <stdio.h>
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <stdlib.h>
|
2023-01-06 15:09:55 +01:00
|
|
|
#include <string.h>
|
2015-08-08 13:15:49 +02:00
|
|
|
|
2020-08-05 16:26:16 +02:00
|
|
|
/* Only common/version.c can safely include this. */
|
2020-10-22 01:51:08 +02:00
|
|
|
# include "version_gen.h"
|
2020-08-05 16:26:16 +02:00
|
|
|
|
2016-09-13 21:52:41 +02:00
|
|
|
const char *version(void)
|
|
|
|
{
|
|
|
|
return VERSION;
|
|
|
|
}
|
|
|
|
|
2023-06-02 04:36:04 +02:00
|
|
|
static char *version_and_exit(const void *unused UNUSED)
|
2015-08-08 13:15:49 +02:00
|
|
|
{
|
2018-04-03 14:16:06 +02:00
|
|
|
printf("%s\n", VERSION);
|
|
|
|
if (BUILD_FEATURES[0]) {
|
|
|
|
printf("Built with features: %s\n", BUILD_FEATURES);
|
|
|
|
}
|
2015-08-08 13:15:49 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
2023-01-06 15:09:55 +01:00
|
|
|
|
2023-06-02 04:36:04 +02:00
|
|
|
void opt_register_version(void)
|
|
|
|
{
|
|
|
|
clnopt_noarg("--version|-V", OPT_EARLY|OPT_EXITS,
|
|
|
|
version_and_exit, NULL,
|
|
|
|
"Print version and exit");
|
|
|
|
}
|
|
|
|
|
2023-01-06 15:09:55 +01:00
|
|
|
static bool cmp_release_version(const char *version) {
|
|
|
|
if (version[0] != 'v')
|
|
|
|
return false;
|
|
|
|
return strspn(version+1, ".0123456789") == strlen(version+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Released versions are of form v[year].[month]?(.patch)* */
|
|
|
|
bool is_released_version(void)
|
|
|
|
{
|
|
|
|
return cmp_release_version(version());
|
|
|
|
}
|