-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
117 lines (96 loc) · 3.09 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
export GO111MODULE = on
export CGO_ENABLED = 0
export GOPROXY = https://proxy.golang.org
ORGNAME := wabarc
PROJECT := screenshot
BINDIR ?= ./build/binary
PACKDIR ?= ./build/package
LDFLAGS := $(shell echo "-X '${PROJECT}/version.Version=`git describe --tags --abbrev=0`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${PROJECT}/version.Commit=`git rev-parse --short HEAD`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${PROJECT}/version.BuildDate=`date +%FT%T%z`'")
GOBUILD ?= go build -trimpath --ldflags "-s -w ${LDFLAGS} -buildid=" -v
GOFILES ?= $(wildcard ./cmd/${PROJECT}/*.go)
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | sed -e 's/v//g')
PACKAGES ?= $(shell go list ./...)
HOMEDIR ?= /go/src/github.com/${ORGNAME}
DOCKER ?= $(shell which docker || which podman)
IMAGE := wabarc/golang-chromium:dev
NAME := ${PROJECT}
PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
linux-386 \
linux-amd64 \
linux-arm64
WINDOWS_ARCH_LIST = \
windows-386 \
windows-amd64
.PHONY: \
darwin-386 \
darwin-amd64 \
linux-386 \
linux-amd64 \
linux-arm64 \
windows-386 \
windows-amd64 \
all-arch \
tar_releases \
zip_releases \
releases \
clean \
test \
fmt \
vet
darwin-amd64:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
darwin-arm64:
GOARCH=arm64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
linux-386:
GOARCH=386 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
linux-amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
linux-arm64:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
windows-386:
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe $(GOFILES)
windows-amd64:
GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe $(GOFILES)
ifeq ($(TARGET),)
tar_releases := $(addsuffix .gz, $(PLATFORM_LIST))
zip_releases := $(addsuffix .zip, $(WINDOWS_ARCH_LIST))
else
ifeq ($(findstring windows,$(TARGET)),windows)
zip_releases := $(addsuffix .zip, $(TARGET))
else
tar_releases := $(addsuffix .gz, $(TARGET))
endif
endif
$(tar_releases): %.gz : %
chmod +x $(BINDIR)/$(NAME)-$(basename $@)
tar -czf $(PACKDIR)/$(NAME)-$(basename $@)-$(VERSION).tar.gz --transform "s/.*\///g" $(BINDIR)/$(NAME)-$(basename $@)
$(zip_releases): %.zip : %
zip -m -j $(PACKDIR)/$(NAME)-$(basename $@)-$(VERSION).zip $(BINDIR)/$(NAME)-$(basename $@).exe
all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
releases: $(tar_releases) $(zip_releases)
fmt:
@echo "-> Running go fmt"
@go fmt ./...
run:
@echo "-> Running docker container"
$(DOCKER) run --memory="500m" -ti --rm -v ${PWD}/../:${HOMEDIR} ${IMAGE} sh -c "\
cd ${HOMEDIR}/${PROJECT} && \
go get -v && \
sh"
test:
@echo "-> Running go test"
$(DOCKER) run -ti --rm -v ${PWD}/../:${HOMEDIR} ${IMAGE} sh -c "\
cd ${HOMEDIR}/${PROJECT} && \
CGO_ENABLED=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic -parallel=1 ./..."
@go tool cover -func=coverage.out
vet:
@echo "-> Running go vet"
@go vet ./...
clean:
@echo "-> Cleaning..."
@rm -rf *.png *.jpg *.jpe* *.pdf *.htm* *.har
@rm -rf build/binary/* build/package/*