-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
45 lines (37 loc) · 1.08 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
TARGET := netadm
SOURCES := $(shell find . -name "*.go")
PLATFORM ?= $(shell go version | cut -d " " -f 4)
GOOS := $(shell echo $(PLATFORM) | cut -d "/" -f 1)
GOARCH := $(shell echo $(PLATFORM) | cut -d "/" -f 2)
SUFFIX := $(GOOS)-$(GOARCH)
VERSION ?= $(shell git describe --always --tags --dirty)
BUILD_FLAGS := -ldflags="-s -w -X github.com/nicklasfrahm/$(TARGET)/cmd.version=$(VERSION)"
# Adjust the binary name on Windows.
ifeq ($(GOOS),windows)
SUFFIX = $(GOOS)-$(GOARCH).exe
endif
build: bin/$(TARGET)-$(SUFFIX)
bin/$(TARGET)-$(SUFFIX): $(SOURCES)
@mkdir -p $(@D)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(BUILD_FLAGS) -o $@ main.go
ifdef UPX
upx -qq $(UPX) $@
endif
/usr/local/bin/$(TARGET): bin/$(TARGET)-$(SUFFIX)
@sudo cp $^ $@
@sudo chmod 755 $@
.PHONY: install
install: /usr/local/bin/$(TARGET)
.PHONY: uninstall
uninstall:
@sudo rm -f /usr/local/bin/$(TARGET)
.PHONY: docker
docker:
docker build \
-t $(TARGET):latest \
-t $(TARGET):$(VERSION) \
--build-arg VERSION=$(VERSION) \
-f build/package/Dockerfile .
.PHONY: clean
clean:
@rm -rvf bin