11# Default target
22build :
33
4- # Project metadata (note: to package, VERSION *must* be set by the caller)
4+ # Project metadata
5+ # By default, the project version is automatically determined using
6+ # 'git describe'. If you would like to set the version manually, set the
7+ # 'VERSION' variable to the desired version string.
58NAME := git-bundle-server
6- VERSION :=
7- PACKAGE_REVISION := 1
89
910# Installation information
1011INSTALL_ROOT := /
@@ -22,6 +23,7 @@ GOARCH := $(shell go env GOARCH)
2223# Packaging information
2324SUPPORTED_PACKAGE_GOARCHES := amd64 arm64
2425PACKAGE_ARCH := $(GOARCH )
26+ PACKAGE_REVISION := 1
2527
2628# Guard against environment variables
2729APPLE_APP_IDENTITY =
@@ -30,18 +32,39 @@ APPLE_KEYCHAIN_PROFILE =
3032E2E_FLAGS =
3133INTEGRATION_FLAGS =
3234
35+ # General targets
36+ .PHONY : FORCE
37+
38+ ifdef VERSION
39+ # If the version is set by the user, don't bother with regenerating the version
40+ # file.
41+ .PHONY : VERSION-FILE
42+ else
43+ # If the version is not set by the user, we need to generate the version file
44+ # and load it.
45+ VERSION-FILE : FORCE
46+ @scripts/generate-version.sh --version-file=" $@ "
47+ -include VERSION-FILE
48+ endif
49+
3350# Build targets
51+ LDFLAGS += -X '$(shell go list -m) /cmd/utils.Version=$(VERSION ) '
52+
3453.PHONY : build
3554build :
3655 $(RM ) -r $(BINDIR )
3756 @mkdir -p $(BINDIR )
38- GOOS=" $( GOOS) " GOARCH=" $( GOARCH) " go build -o $(BINDIR ) ./...
57+ GOOS=" $( GOOS) " GOARCH=" $( GOARCH) " go build -o $(BINDIR ) -ldflags " $( LDFLAGS ) " ./...
3958
4059.PHONY : doc
4160doc :
4261 @scripts/make-docs.sh --docs=" $( CURDIR) /docs/man" \
4362 --output=" $( DOCDIR) "
4463
64+ .PHONY : vet
65+ vet :
66+ GOOS=" $( GOOS) " GOARCH=" $( GOARCH) " go vet ./...
67+
4568# Testing targets
4669.PHONY : test
4770test : build
@@ -193,6 +216,7 @@ endif
193216.PHONY : clean
194217clean :
195218 go clean ./...
219+ $(RM ) -r VERSION-FILE
196220 $(RM ) -r $(BINDIR )
197221 $(RM ) -r $(DISTDIR )
198222 $(RM ) -r $(DOCDIR )
0 commit comments