From 7d995e2321a3dcdb74cb3833ad6d3921587e1792 Mon Sep 17 00:00:00 2001 From: "mingang.he" Date: Sat, 2 Mar 2024 03:46:35 +0000 Subject: [PATCH] Update Makefile VERSION assignment to avoid errors when not in a git repository Simplify the VERSION assignment to prevent the "fatal: not a git repository (or any of the parent directories): .git" error when building from a source archive. The VERSION variable now checks if the Makefile is within a git working tree before attempting to use git tags. If not, it defaults to "v0.7", avoiding errors in non-git environments. --- Makefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5e074ad..03e8c0e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # "Makefile" for graftcp. -# Copyright (C) 2016, 2018, 2020, 2021, 2023 Hmgle +# Copyright (C) 2016, 2018, 2020, 2021, 2023, 2024 Hmgle # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,8 @@ ifneq ($(KERNEL), Linux) $(error only support Linux now.) endif -VERSION = $(shell git describe --tags --always) +VERSION = $(shell git rev-parse --is-inside-work-tree 1>/dev/null 2>&1 && \ + git describe --tags --always || echo "v0.7") # CROSS_COMPILE can be set on the command line # make CROSS_COMPILE=arm-linux-gnueabi- @@ -45,9 +46,6 @@ else CFLAGS += -O2 -DNDEBUG endif -ifneq ($(shell echo $(VERSION) | head -c 1), v) - VERSION=v0.7 -endif CFLAGS += -DVERSION=\"$(VERSION)\" SRC := $(wildcard *.c)