-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
103 lines (79 loc) · 2.67 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
PROJECT := github.com/nokia/ntt
# Common GNU installation folders
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= ${PREFIX}/bin
LIBEXECDIR ?= ${PREFIX}/libexec
MANDIR ?= ${PREFIX}/share/man
DATADIR ?= ${PREFIX}/share/ntt
ETCDIR ?= /etc
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
# Commands
GO ?= go
# Go specific stuff
export GO111MODULE=off
export GOPROXY=https://proxy.golang.org
GO_BUILD=$(GO) build
# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
unexport GOBIN
endif
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
GOPKGDIR := $(FIRST_GOPATH)/src/$(PROJECT)
GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)")
GOBIN := $(shell $(GO) env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(FIRST_GOPATH)/bin
endif
# Go module support: set `-mod=vendor` to force use the vendored sources
ifeq ($(shell $(GO) help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
endif
GIT_COMMIT ?= $(shell git rev-parse HEAD 2> /dev/null || true)
VERSION = $(shell git describe HEAD 2> /dev/null || echo v0)
DATE_FMT = %c
ifdef SOURCE_DATE_EPOCH
BUILD_INFO ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
else
BUILD_INFO ?= $(shell date "+$(DATE_FMT)")
endif
NTT_LDFLAGS = -X 'main.version=$(VERSION)'
NTT_LDFLAGS += -X 'main.commit=$(GIT_COMMIT)'
NTT_LDFLAGS += -X 'main.date=$(BUILD_INFO)'
NTT_LDFLAGS += -X 'main.prefix=$(PREFIX)'
.PHONY: all ## build whole project (default)
all: build
# It's common practice to provide a help target describing available targets.
# This script greps through the Makefile and displays all phony-targets with a
# `##` help string.
.PHONY: help
help:
@echo Available targets:
@perl -ne 'printf("\t%-10s\t%s\n", $$1, $$2) if /^\.PHONY:\s*(.*)\s*##\s*(.*)$$/' <$(MAKEFILE_LIST)
.PHONY: build ## build everything
build: bin/ntt
.PHONY: check ## run tests
check:
$(GO) test ./...
.PHONY: install ## install NTT
install: build
install -d -m 755 $(DESTDIR)$(BINDIR)
install -m 755 bin/ntt $(DESTDIR)$(BINDIR)/ntt
install -d -m 755 $(DESTDIR)$(DATADIR)/cmake
install -m 644 cmake/FindNTT.cmake $(DESTDIR)$(DATADIR)/cmake
.PHONY: clean ## delete build artifacts
clean:
rm -f bin/ntt
rmdir bin
.PHONY: bin/ntt ## build ntt CLI
bin/ntt:
$(GO_BUILD) -ldflags="$(NTT_LDFLAGS)" -o $@ .
.PHONY: generate ## run code generators
generate:
$(GO) generate -x ./...
.PHONY: vendor ## vendor dependencies (works only with module support)
vendor:
GO111MODULE=on $(GO) mod tidy
GO111MODULE=on $(GO) mod vendor