-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
79 lines (63 loc) · 2.81 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
# Application version encoded in all the binaries.
VERSION = 0.0.0
# Base go module name.
MODULE := $(shell cat go.mod | grep -m1 module | awk '{print $$2}')
# Git revision.
REVISION := $(shell git rev-parse HEAD)
# Some sane defaults
SHELL = /usr/bin/env bash
BINDIR := $(CURDIR)/bin
BINNAME ?= dogkat
PREFIX = $(HOME)/bin
# Sources for building
SOURCES := $(shell find . -type f -name *.go) go.mod go.sum
# Golang info
GOPATH := $(shell go env GOPATH)
GOBIN := $(if $(shell go env GOBIN),$(shell go env GOBIN),$(GOPATH)/bin)
# Some flags for the build to set revision and versions
FLAGS=-trimpath -ldflags "-X $(MODULE)/pkg/constants.Version=$(VERSION) -X $(MODULE)/pkg/constants.Revision=$(REVISION)"
# The targets to build
TARGET_BINARIES := dogkat-linux-amd64 dogkat-linux-arm64 dogkat-darwin-amd64 dogkat-darwin-arm64 dogkat-windows-amd64 dogkat-windows-arm64
.PHONY: all
all: $(TARGET_BINARIES) # Make all depend on the binaries
# Create output directories (this can be simplified)
$(BINDIR):
mkdir -p $@
# Build linux-amd64
.PHONY: dogkat-linux-amd64
dogkat-linux-amd64: $(SOURCES) | $(BINDIR)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/$@ cmd/dogkat/main.go
# Build linux-arm64
.PHONY: dogkat-linux-arm64
dogkat-linux-arm64: $(SOURCES) | $(BINDIR)
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/$@ cmd/dogkat/main.go
# Build darwin-amd64
.PHONY: dogkat-darwin-amd64
dogkat-darwin-amd64: $(SOURCES) | $(BINDIR)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/$@ cmd/dogkat/main.go
# Build darwin-arm64
.PHONY: dogkat-darwin-arm64
dogkat-darwin-arm64: $(SOURCES) | $(BINDIR)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/$@ cmd/dogkat/main.go
# Build windows-amd64
.PHONY: dogkat-windows-amd64
dogkat-windows-amd64: $(SOURCES) | $(BINDIR)
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/[email protected] cmd/dogkat/main.go
# Build windows-arm64
.PHONY: dogkat-windows-arm64
dogkat-windows-arm64: $(SOURCES) | $(BINDIR)
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build $(FLAGS) -o $(BINDIR)/[email protected] cmd/dogkat/main.go
.PHONY: install
install:
@case $$(uname -s)-$$(uname -m) in \
Darwin-x86_64) sudo install -o root -g root -m 0755 $(BINDIR)/dogkat-darwin-amd64 $(PREFIX)/dogkat ;; \
Linux-x86_64) sudo install -o root -g root -m 0755 $(BINDIR)/dogkat-linux-amd64 $(PREFIX)/dogkat ;; \
Linux-aarch64) sudo install -o root -g root -m 0755 $(BINDIR)/dogkat-linux-arm64 $(PREFIX)/dogkat ;; \
MINGW64_NT-*) sudo install -o root -g root -m 0755 $(BINDIR)/dogkat-windows-amd64.exe $(PREFIX)/dogkat.exe ;; \
*) echo "Unsupported platform: $$(uname -s)-$$(uname -m)" ; exit 1 ;; \
esac
# Perform license checking.
# This must pass or you will be denied by CI.
.PHONY: license
license:
go run hack/check_license/main.go