Skip to content

Commit

Permalink
update bet version at build times and add statically to C header file
Browse files Browse the repository at this point in the history
  • Loading branch information
satindergrewal committed Nov 22, 2021
1 parent fbb5eef commit 521c779
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
8 changes: 5 additions & 3 deletions privatebet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,7 +21,7 @@ CFLAGS := -g -fPIC -std=c99 $(WARNINGS)

LIGHTNING := lightning

all: $(PROJNAME) build_dir_tree
all: $(PROJNAME)

clean:
$(RM) $(OBJFILES)
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion privatebet/bet.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "misc.h"
#include "help.h"
#include "err.h"
#include "bet_version.h"

#include <netinet/in.h>
#include <stdio.h>
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions privatebet/bet_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
char BET_VERSION[200]="v0.1.3-570-gfbb5eef";
18 changes: 1 addition & 17 deletions privatebet/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 521c779

Please sign in to comment.