1
1
# !/usr/bin/make -f
2
2
3
- GO_VERSION =1.22
4
- GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
5
- REQUIRE_GO_VERSION = $(GO_VERSION )
3
+ # Go version and build settings
4
+ GO_VERSION := 1.22
5
+ GO_SYSTEM_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
6
+ REQUIRE_GO_VERSION := $(GO_VERSION )
7
+ ENABLED_FLAGS :=
6
8
7
- WEAVE_VERSION =v0.0.1
9
+ # Project version
10
+ WEAVE_VERSION := v0.0.1
8
11
12
+ # Build directory
9
13
BUILDDIR ?= $(CURDIR ) /build
10
- BUILD_TARGETS = build
11
14
12
- release_version =$(filter-out $@ ,$(MAKECMDGOALS ) )
15
+ # Build targets
16
+ BUILD_TARGETS := build install test
13
17
18
+ # Version check
14
19
check_version :
15
- ifneq ($(GO_SYSTEM_VERSION ) , $(REQUIRE_GO_VERSION ) )
16
- @echo "ERROR: Go version ${REQUIRE_GO_VERSION} is required for Weave."
17
- exit 1
18
- endif
19
-
20
- build : BUILD_ARGS=-o $(BUILDDIR ) /
20
+ @if [ " $( GO_SYSTEM_VERSION) " != " $( REQUIRE_GO_VERSION) " ]; then \
21
+ echo " ERROR: Go version $( REQUIRE_GO_VERSION) is required for Weave." ; \
22
+ exit 1; \
23
+ fi
21
24
22
- $(BUILD_TARGETS ) : check_version go.sum $(BUILDDIR ) /
23
- ifeq ($(OS ) ,Windows_NT)
24
- exit 1
25
- else
26
- go $@ -mod=readonly -ldflags "-X github.com/initia-labs/weave/cmd.Version=$(WEAVE_VERSION)" .
27
- endif
25
+ # Build settings
26
+ LDFLAGS := -X github.com/initia-labs/weave/cmd.Version=$(WEAVE_VERSION ) \
27
+ -X github.com/initia-labs/weave/flags.EnabledFlags=$(ENABLED_FLAGS )
28
28
29
- $(BUILDDIR ) / :
30
- mkdir -p $(BUILDDIR ) /
29
+ # Build targets
30
+ build : check_version $(BUILDDIR )
31
+ go build -mod=readonly -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /weave .
31
32
32
- install :
33
- go install -ldflags " -X github.com/initia-labs/weave/cmd.Version= $( WEAVE_VERSION ) " .
33
+ install : check_version
34
+ go install -ldflags " $( LDFLAGS ) " .
34
35
35
- test :
36
+ test : check_version
36
37
go test -v ./...
37
38
39
+ # Release process
38
40
release :
39
41
@if [ -z " $( release_version) " ]; then \
40
42
echo " ERROR: You must provide a release version. Example: make release v0.0.15" ; \
@@ -44,5 +46,6 @@ release:
44
46
git push origin $(release_version )
45
47
gh release create $(release_version ) --title " $( release_version) " --notes " Release notes for version $( release_version) "
46
48
49
+ # Catch-all target
47
50
% :
48
51
@:
0 commit comments