-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
62 lines (43 loc) · 1.62 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
# products
PRODUCT=urlenc
# build and packaging
MAIN := ./cmd/urlenc
BIN = $(PWD)/bin
SRC = $(shell find cmd -name \*.go -print)
# fix our gopath
GOPATH := $(GOPATH):$(PWD)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# build and packaging for release
GITHASH := $(shell git log --pretty=format:'%h' -n 1)
VERSION ?= $(GITHASH)
RELEASE_BUILD = $(PWD)/target
RELEASE_TARGETS = $(PWD)/target/$(GOOS)_$(GOARCH)
RELEASE_PRODUCT = $(PRODUCT)-$(GITHASH)
RELEASE_ARCHIVE = $(RELEASE_PRODUCT)-$(GOOS)-$(GOARCH).tgz
RELEASE_PACKAGE = $(RELEASE_TARGETS)/$(RELEASE_ARCHIVE)
RELEASE_BASE = $(RELEASE_TARGETS)/$(RELEASE_PRODUCT)/bin
TEST_PKGS ?= encode/...
.PHONY: all test urlenc install release build archive clean
all: build
# build and install
PREFIX ?= /usr/local
.PHONY: all encode decode
all: urlenc
$(TARGETS):
mkdir -p $(TARGETS)
urlenc: $(BIN)/$(PRODUCT)
$(BIN)/$(PRODUCT): $(TARGETS) $(SRC)
go build -ldflags "-X main.mode=enc -X main.version=$(VERSION) -X main.githash=$(GITHASH)" -o $(BIN)/$(PRODUCT) $(MAIN)
install: urlenc ## Build and install
@echo "Using sudo to install; you may be prompted for a password..."
sudo install -m 0755 $(BIN)/$(PRODUCT) $(PREFIX)/bin
$(RELEASE_BASE)/$(PRODUCT): $(SRC)
go build -ldflags "-X main.mode=enc -X main.version=$(VERSION) -X main.githash=$(GITHASH)" -o $(RELEASE_BASE)/$(PRODUCT) $(MAIN)
$(RELEASE_PACKAGE): $(RELEASE_BASE)/$(PRODUCT)
(cd $(RELEASE_TARGETS) && tar -zcf $(RELEASE_ARCHIVE) $(RELEASE_PRODUCT))
archive: $(RELEASE_PACKAGE)
test: ## Run tests
go test $(TEST_PKGS)
clean: ## Delete the built product and any generated files
rm -rf $(BIN) $(RELEASE_BUILD)