Skip to content

Commit

Permalink
cli & makefile: allow dynamic version generation
Browse files Browse the repository at this point in the history
  • Loading branch information
7Ji committed Nov 10, 2022
1 parent bd4409b commit 16406fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,27 @@ INCLUDES = $(wildcard $(DIR_INCLUDE)/*.h)
_OBJECTS = $(wildcard $(DIR_SOURCE)/*.c)
OBJECTS = $(patsubst $(DIR_SOURCE)/%.c,$(DIR_OBJECT)/%.o,$(_OBJECTS))

ifdef VERSION_CUSTOM
CLI_VERSION := $(VERSION_CUSTOM)
else
VERSION_GIT_TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
VERSION_GIT_TAG_NO_V := $(VERSION_GIT_TAG:v%=%)
VERSION_GIT_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
VERSION_GIT_DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
CLI_VERSION := $(VERSION_GIT_TAG_NO_V)-$(VERSION_GIT_COMMIT)-$(VERSION_GIT_DATE)
endif

ifeq ($(CLI_VERSION),)
CLI_VERSION := unknown
endif

$(BINARY): $(OBJECTS)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)

$(DIR_OBJECT)/cli.o: $(DIR_SOURCE)/cli.c $(INCLUDES)
$(CC) -c -o $@ $< $(CFLAGS) -DCLI_VERSION=\"$(CLI_VERSION)\"


$(DIR_OBJECT)/%.o: $(DIR_SOURCE)/%.c $(INCLUDES)
$(CC) -c -o $@ $< $(CFLAGS)

Expand Down
4 changes: 4 additions & 0 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ struct cli_options cli_options = {

void
cli_version(){
#ifdef CLI_VERSION
fputs("ampart-ng (Amlogic eMMC partition tool) by 7Ji, version "CLI_VERSION"\n", stderr);
#else
fputs("ampart-ng (Amlogic eMMC partition tool) by 7Ji, development version, debug usage only\n", stderr);
#endif
}

size_t
Expand Down

0 comments on commit 16406fe

Please sign in to comment.