[v1.03] Print git hash and tag when printing version

This commit is contained in:
Dr-Noob
2023-01-18 20:14:08 +01:00
parent 2b8a942a98
commit 57f11f3eab
2 changed files with 14 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ COMMON_SRC = $(SRC_COMMON)main.c $(SRC_COMMON)cpu.c $(SRC_COMMON)udev.c $(SRC_CO
COMMON_HDR = $(SRC_COMMON)ascii.h $(SRC_COMMON)cpu.h $(SRC_COMMON)udev.h $(SRC_COMMON)printer.h $(SRC_COMMON)args.h $(SRC_COMMON)global.h COMMON_HDR = $(SRC_COMMON)ascii.h $(SRC_COMMON)cpu.h $(SRC_COMMON)udev.h $(SRC_COMMON)printer.h $(SRC_COMMON)args.h $(SRC_COMMON)global.h
ifneq ($(OS),Windows_NT) ifneq ($(OS),Windows_NT)
GIT_VERSION := "$(shell git describe --abbrev=4 --dirty --always --tags)"
arch := $(shell uname -m) arch := $(shell uname -m)
ifeq ($(arch), $(filter $(arch), x86_64 amd64 i386 i486 i586 i686)) ifeq ($(arch), $(filter $(arch), x86_64 amd64 i386 i486 i586 i686))
SRC_DIR=src/x86/ SRC_DIR=src/x86/
@@ -50,6 +51,7 @@ $(error Aborting compilation)
OUTPUT=cpufetch OUTPUT=cpufetch
else else
# Assume x86_64 # Assume x86_64
GIT_VERSION := ""
SRC_DIR=src/x86/ SRC_DIR=src/x86/
SOURCE += $(COMMON_SRC) $(SRC_DIR)cpuid.c $(SRC_DIR)apic.c $(SRC_DIR)cpuid_asm.c $(SRC_DIR)uarch.c SOURCE += $(COMMON_SRC) $(SRC_DIR)cpuid.c $(SRC_DIR)apic.c $(SRC_DIR)cpuid_asm.c $(SRC_DIR)uarch.c
HEADERS += $(COMMON_HDR) $(SRC_DIR)cpuid.h $(SRC_DIR)apic.h $(SRC_DIR)cpuid_asm.h $(SRC_DIR)uarch.h HEADERS += $(COMMON_HDR) $(SRC_DIR)cpuid.h $(SRC_DIR)apic.h $(SRC_DIR)cpuid_asm.h $(SRC_DIR)uarch.h
@@ -80,7 +82,11 @@ freq_avx512.o: Makefile $(SRC_DIR)freq/freq_avx512.c $(SRC_DIR)freq/freq_avx512.
$(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx512f -pthread $(SRC_DIR)freq/freq_avx512.c -o $@ $(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx512f -pthread $(SRC_DIR)freq/freq_avx512.c -o $@
$(OUTPUT): Makefile $(SOURCE) $(HEADERS) $(OUTPUT): Makefile $(SOURCE) $(HEADERS)
ifeq ($(GIT_VERSION),"")
$(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT) $(CC) $(CFLAGS) $(SANITY_FLAGS) $(SOURCE) -o $(OUTPUT)
else
$(CC) $(CFLAGS) $(SANITY_FLAGS) -DGIT_FULL_VERSION=\"$(GIT_VERSION)\" $(SOURCE) -o $(OUTPUT)
endif
run: $(OUTPUT) run: $(OUTPUT)
./$(OUTPUT) ./$(OUTPUT)

View File

@@ -33,7 +33,9 @@
static const char* OS_STR = "Unknown OS"; static const char* OS_STR = "Unknown OS";
#endif #endif
static const char* VERSION = "1.03"; #ifndef GIT_FULL_VERSION
static const char* VERSION = "1.03";
#endif
void print_help(char *argv[]) { void print_help(char *argv[]) {
const char **t = args_str; const char **t = args_str;
@@ -107,7 +109,11 @@ void print_help(char *argv[]) {
} }
void print_version() { void print_version() {
printf("cpufetch v%s (%s %s)\n",VERSION, OS_STR, ARCH_STR); #ifdef GIT_FULL_VERSION
printf("cpufetch %s (%s %s)\n", GIT_FULL_VERSION, OS_STR, ARCH_STR);
#else
printf("cpufetch v%s (%s %s)\n", VERSION, OS_STR, ARCH_STR);
#endif
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {