From 521c7790917102535ac42bdb33c86adca0bd5006 Mon Sep 17 00:00:00 2001 From: satindergrewal Date: Tue, 23 Nov 2021 00:31:19 +1300 Subject: [PATCH] update bet version at build times and add statically to C header file --- privatebet/Makefile | 8 +++++--- privatebet/bet.c | 3 ++- privatebet/bet_version.h | 1 + privatebet/commands.c | 18 +----------------- 4 files changed, 9 insertions(+), 21 deletions(-) create mode 100644 privatebet/bet_version.h diff --git a/privatebet/Makefile b/privatebet/Makefile index 8dbc8ee3..24cefc4e 100644 --- a/privatebet/Makefile +++ b/privatebet/Makefile @@ -4,6 +4,8 @@ LIB := libbet SRCFILES := cards777.c client.c commands.c gfshare.c host.c network.c oracle.c payment.c states.c table.c poker.c cashier.c storage.c config.c misc.c heartbeat.c help.c err.c OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) # CC := gcc-8 +BET_VERSION=$(shell git describe --always --abbrev=7 2>/dev/null || pwd | sed -n 's|.*/c\{0,1\}bet-v\{0,1\}\([0-9a-f.rc\-]*\)$$|\1|gp') +# UPDATE_BET_VERSION=$(shell echo "char BET_VERSION[200]=\"${BET_VERSION}\";" > bet_version.h) UNAME_S := $(shell uname -s) UNAME_P := $(shell uname -p) @@ -19,7 +21,7 @@ CFLAGS := -g -fPIC -std=c99 $(WARNINGS) LIGHTNING := lightning -all: $(PROJNAME) build_dir_tree +all: $(PROJNAME) clean: $(RM) $(OBJFILES) @@ -50,12 +52,12 @@ ifeq ($(UNAME_S),Darwin) endif $(info $$CC is [${CC}]) +$(info $$BET_VERSION is [${BET_VERSION}]) $(PROJNAME): $(OBJFILES) + $(shell echo "char BET_VERSION[200]=\"${BET_VERSION}\";" > bet_version.h) $(CC) $(CFLAGS) -o $@ bet.c $^ ../external/iniparser/libiniparser.a ../crypto777/libcrypto777.a -L$(TARGET_DIR) -I$(LIBWEBSOCKETS_HEADERS) -I$(LIBWALLY_CORE_HEADERS) -I$(LIBJSMN_HEADERS) -I$(LIBINIPARSER_HEADERS) -L$(LIBWEBSOCKETS_LDFLAGS) $(LDFLAGS) $(CPPFLAGS) -lcurl -ldl -lnng -lpthread -lm -lwallycore -lsecp256k1 -ljsmn -lwebsockets -ldlg -L/usr/local/lib -lm -lgmp -lsqlite3 -L/usr/local/lib -lssl -lcrypto -levent -lpthread -lstdc++ cp $(PROJNAME) $(CASHIER) %.o: %.c $(CC) $(CFLAGS) -L$(TARGET_DIR) -I$(LIBINIPARSER_HEADERS) -I$(LIBWEBSOCKETS_HEADERS) -I$(LIBWALLY_CORE_HEADERS) -I$(LIBJSMN_HEADERS) -L$(LIBINIPARSER_LDFLAGS) -L$(LIBWEBSOCKETS_LDFLAGS) $(LDFLAGS) $(CPPFLAGS) -c $< -o $@ -I ../includes/curl -build_dir_tree: - sh ./scripts/build_dir_tree.sh diff --git a/privatebet/bet.c b/privatebet/bet.c index d9c4448b..538a59db 100644 --- a/privatebet/bet.c +++ b/privatebet/bet.c @@ -30,6 +30,7 @@ #include "misc.h" #include "help.h" #include "err.h" +#include "bet_version.h" #include #include @@ -438,7 +439,7 @@ int main(int argc, char **argv) } } else if ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "v") == 0) || (strcmp(argv[1], "--version") == 0) || (strcmp(argv[1], "version") == 0)) { - dlg_info("%s", bet_git_version()); + printf("%s\n", BET_VERSION); } else if (strcmp(argv[1], "spendable") == 0) { cJSON *spendable_tx = chips_spendable_tx(); dlg_info("CHIPS Spendable tx's :: %s\n", cJSON_Print(spendable_tx)); diff --git a/privatebet/bet_version.h b/privatebet/bet_version.h new file mode 100644 index 00000000..8e3b4a0d --- /dev/null +++ b/privatebet/bet_version.h @@ -0,0 +1 @@ +char BET_VERSION[200]="v0.1.3-570-gfbb5eef"; diff --git a/privatebet/commands.c b/privatebet/commands.c index a712b5d8..009a8977 100644 --- a/privatebet/commands.c +++ b/privatebet/commands.c @@ -1852,20 +1852,4 @@ int32_t ln_establish_channel(char *uri) } end: return retval; -} - -char *bet_git_version() -{ - int argc = 2; - char **argv = NULL; - cJSON *version = NULL; - - bet_alloc_args(argc, &argv); - argv = bet_copy_args(argc, "git", "describe"); - version = cJSON_CreateObject(); - make_command(argc, argv, &version); - - bet_dealloc_args(argc, &argv); - - return unstringify(cJSON_Print(version)); -} +} \ No newline at end of file