-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
46 lines (38 loc) · 1.16 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
GOOS := linux
GOARCH := amd64
CGO_ENABLED := 1
TAGS := -tags 'netgo'
BINARY := sonic-confidb-utils-$(GOOS)-$(GOARCH)
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
# gnu date format iso-8601 is parsable with Go RFC3339
BUILDDATE := $(shell date --iso-8601=seconds)
VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD))
ifeq ($(CGO_ENABLED),1)
ifeq ($(GOOS),linux)
LINKMODE := -linkmode external -extldflags '-static -s -w'
TAGS := -tags 'osusergo netgo static_build'
endif
endif
LINKMODE := $(LINKMODE) \
-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'
.PHONY: all
all: test test-generate build
.PHONY: build
build:
go build \
$(TAGS) \
-ldflags \
"$(LINKMODE)" \
-o bin/$(BINARY) \
github.com/metal-stack/sonic-configdb-utils
md5sum bin/$(BINARY) > bin/$(BINARY).md5
.PHONY: test
test:
go test ./...
.PHONY: test-generate
test-generate:
./tests/test.sh