-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
45 lines (37 loc) · 1 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
GIT_HOST = github.com/lingxiankong
PWD := $(shell pwd)
BASE_DIR := $(shell basename $(PWD))
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
SOURCES := $(shell find $(DEST) -name '*.go')
GOOS ?= $(shell go env GOOS)
VERSION ?= $(shell git describe --tags --always --abbrev=8)
LDFLAGS := "-w -s -X '${GIT_HOST}/${BASE_DIR}/cmd.version=${VERSION}'"
ifneq ("$(DEST)", "$(PWD)")
$(error Please run 'make' from $(DEST). Current directory is $(PWD))
endif
$(GOBIN):
echo "create gobin"
mkdir -p $(GOBIN)
work: $(GOBIN)
osctl: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o osctl \
main.go
.PHONY: fmt
fmt:
tools/check_gofmt.sh
.PHONY: clean
clean:
rm -rf osctl
.PHONY: realclean
realclean: clean
rm -rf vendor
if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
rm -rf $(GOPATH); \
fi