-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
59 lines (43 loc) · 1.2 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
# OS-specific variables
UNAME=$(shell uname)
ifeq ($(UNAME),Darwin)
SORT_BIN=gsort
HEAD_BIN=ghead
else
SORT_BIN=sort
HEAD_BIN=head
endif
# Build variables
BUILD_DIR=_build
LAST_TAG=$(shell git tag | $(SORT_BIN) -V | tail -n 1)
HASH_HEAD=$(shell git show-ref --head | head -1 | awk '{print $$1}')
HASH_LAST_TAG=$(shell git rev-list -n 1 $(LAST_TAG))
GIT_TAG=$(shell if [ $(HASH_HEAD) = $(HASH_LAST_TAG) ]; then echo $(LAST_TAG); else echo "head"; fi)
BIN=owl-${GIT_TAG}
LDFLAGS="-X github.com/algolia/owl/info.GitTag=${GIT_TAG}"
NEED_FORMATTING=$(shell for dir in $(shell glide nv -x | ${HEAD_BIN} -n -1); do goimports -l $$dir; done)
all: install
# Build and install
install:
go install
build: clean-build linux-amd64 mac-amd64
linux-amd64:
GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o $(BUILD_DIR)/$@/$(BIN)
mac-amd64:
GOOS=darwin GOARCH=amd64 go build -ldflags ${LDFLAGS} -o $(BUILD_DIR)/$@/$(BIN)
deps:
glide install
check-formatting:
ifneq ($(NEED_FORMATTING),)
@echo $(NEED_FORMATTING)
@exit 1
endif
test: test-unit
test-unit:
@echo '> Run unit tests'
go test -v $(shell glide novendor)
clean: clean-build
clean-build:
go clean
rm -rf $(BUILD_DIR)
.PHONY: install build test clean