-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·58 lines (46 loc) · 1.9 KB
/
Makefile
File metadata and controls
executable file
·58 lines (46 loc) · 1.9 KB
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
MAIN_PACKAGE := cmon
BUILT_ON := $(shell date)
GOOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
COMMIT_HASH:=$(shell git log -n 1 --pretty=format:"%H")
PACKAGES:=$(shell go list ./... | grep -v /vendor/)
GO_LINUX := GOOS=linux GOARCH=amd64
GO_OSX := GOOS=darwin GOARCH=amd64
GO_WIN := GOOS=darwin GOARCH=amd64
VER := 1.0
LDFLAGS := '-s -w -X "github.com/perlogix/cmon/config.builtOn=$(BUILT_ON)" -X "github.com/perlogix/cmon/config.commitHash=$(COMMIT_HASH)" -X "github.com/perlogix/cmon/config.version=$(VER)"'
default: build
build:
GOOS=$(GOOS) CGO_ENABLED=0 go build -a -installsuffix cgo -o $(MAIN_PACKAGE) -ldflags $(LDFLAGS) .
osx:
CGO_ENABLED=0 $(GO_OSX) go build -a -installsuffix cgo -o $(MAIN_PACKAGE) -ldflags $(LDFLAGS) .
linux:
CGO_ENABLED=0 $(GO_LINUX) go build -a -installsuffix cgo -o $(MAIN_PACKAGE) -ldflags $(LDFLAGS) .
windows:
CGO_ENABLED=0 $(GO_WIN) go build -a -installsuffix cgo -o $(MAIN_PACKAGE).exe -ldflags $(LDFLAGS) .
clean:
find . -name *_gen.go -type f -delete
rm -f ./$(MAIN_PACKAGE)
rm -f ./*.rpm
rm -f ./*.deb
gofmt:
go fmt ./...
lint: gofmt
$(GOPATH)/bin/staticcheck $(PACKAGES)
$(GOPATH)/bin/golangci-lint run
$(GOPATH)/bin/gosec -quiet -no-fail ./...
run:
go run main.go
update-deps:
go get -u ./...
go mod tidy
docker:
sudo docker build --build-arg GOOS=$(GOOS) -t $(MAIN_PACKAGE)-build .
sudo docker create --name $(MAIN_PACKAGE)-build $(MAIN_PACKAGE)-build
sudo docker cp $(MAIN_PACKAGE)-build:/go/src/github.com/perlogix/$(MAIN_PACKAGE)/$(MAIN_PACKAGE) ./
sudo docker rm -f $(MAIN_PACKAGE)-build
pkgs:
sudo docker build --build-arg VER=$(VER) -t $(MAIN_PACKAGE)-pkgs -f Dockerfile-pkgs .
sudo docker create --name $(MAIN_PACKAGE)-pkgs $(MAIN_PACKAGE)-pkgs
sudo docker cp $(MAIN_PACKAGE)-pkgs:/packaging/$(MAIN_PACKAGE)-$(VER)-amd64.rpm ./
sudo docker cp $(MAIN_PACKAGE)-pkgs:/packaging/$(MAIN_PACKAGE)-$(VER)-amd64.deb ./
sudo docker rm -f $(MAIN_PACKAGE)-pkgs