Skip to content

Commit 16406fe

Browse files
committed
cli & makefile: allow dynamic version generation
1 parent bd4409b commit 16406fe

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,27 @@ INCLUDES = $(wildcard $(DIR_INCLUDE)/*.h)
1414
_OBJECTS = $(wildcard $(DIR_SOURCE)/*.c)
1515
OBJECTS = $(patsubst $(DIR_SOURCE)/%.c,$(DIR_OBJECT)/%.o,$(_OBJECTS))
1616

17+
ifdef VERSION_CUSTOM
18+
CLI_VERSION := $(VERSION_CUSTOM)
19+
else
20+
VERSION_GIT_TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
21+
VERSION_GIT_TAG_NO_V := $(VERSION_GIT_TAG:v%=%)
22+
VERSION_GIT_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
23+
VERSION_GIT_DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
24+
CLI_VERSION := $(VERSION_GIT_TAG_NO_V)-$(VERSION_GIT_COMMIT)-$(VERSION_GIT_DATE)
25+
endif
26+
27+
ifeq ($(CLI_VERSION),)
28+
CLI_VERSION := unknown
29+
endif
30+
1731
$(BINARY): $(OBJECTS)
1832
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
1933

34+
$(DIR_OBJECT)/cli.o: $(DIR_SOURCE)/cli.c $(INCLUDES)
35+
$(CC) -c -o $@ $< $(CFLAGS) -DCLI_VERSION=\"$(CLI_VERSION)\"
36+
37+
2038
$(DIR_OBJECT)/%.o: $(DIR_SOURCE)/%.c $(INCLUDES)
2139
$(CC) -c -o $@ $< $(CFLAGS)
2240

src/cli.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ struct cli_options cli_options = {
7575

7676
void
7777
cli_version(){
78+
#ifdef CLI_VERSION
79+
fputs("ampart-ng (Amlogic eMMC partition tool) by 7Ji, version "CLI_VERSION"\n", stderr);
80+
#else
7881
fputs("ampart-ng (Amlogic eMMC partition tool) by 7Ji, development version, debug usage only\n", stderr);
82+
#endif
7983
}
8084

8185
size_t

0 commit comments

Comments
 (0)