forked from codefreshdemo/cf-example-golang-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (41 loc) · 1.29 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
DIST := dist
IMPORT := github.com/nuveo/prest
LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')"
OUT := 'prest'
TARGETS ?= linux/*,darwin/*,windows/*
EXECUTABLE := $(OUT)
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(OUT).exe
endif
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
SOURCES ?= $(shell find . -name "*.go" -type f)
.PHONY: errcheck
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
.PHONY: install
install: $(wildcard *.go)
go install -v -ldflags '-s -w $(LDFLAGS)'
.PHONY: build
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -ldflags '-s -w $(LDFLAGS)' -o $@
.PHONY: release
release: release-dirs release-build release-check
.PHONY: release-dirs
release-dirs:
mkdir -p $(DIST)/binaries
.PHONY: release-build
release-build:
@which xgo > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/karalabe/xgo; \
fi
xgo -dest $(DIST)/binaries -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE) $(IMPORT)
ifeq ($(CI),drone)
mv /build/* $(DIST)/binaries
endif
.PHONY: release-check
release-check:
cd $(DIST)/binaries; $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)