-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (44 loc) · 1.63 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
.PHONY: test build
GIT_PATH=github.com/derricw/dsim
BIN_NAME=dsim
REPO_NAME=dsim
BIN_DIR := $(CURDIR)/bin
INSTALL_DIR := $${HOME}/.local/bin
VERSION := $(shell git describe --abbrev=0 --tags)
GIT_COMMIT= $(shell git rev-parse HEAD)
BUILD_DATE= $(shell date '+%Y-%m-%d-%H:%M:%S')
GOFMT := gofmt
GO = go
default: fmt test build
test:
go test -v -coverprofile "cov.cov" -covermode=count ./...
go tool cover -func=cov.cov
go tool cover -html=cov.cov -o coverage.html
$(BIN_DIR):
@mkdir -p $@
$(INSTALL_DIR):
@mkdir -p $@
build: $(BIN_DIR)
go build -v \
-ldflags "-X ${GIT_PATH}/${REPO_NAME}/version.GitCommit=${GIT_COMMIT} -X ${GIT_PATH}/${REPO_NAME}/version.BuildDate=${BUILD_DATE}" \
-o $(BIN_DIR)/$(BIN_NAME)
build_linux: $(BIN_DIR)
GOOS=linux go build -v \
-ldflags "-X ${GIT_PATH}/${REPO_NAME}/version.GitCommit=${GIT_COMMIT} -X ${GIT_PATH}/${REPO_NAME}/version.BuildDate=${BUILD_DATE}" \
-o $(BIN_DIR)/$(BIN_NAME)
build_darwin: $(BIN_DIR)
GOOS=darwin go build -v \
-ldflags "-X ${GIT_PATH}/${REPO_NAME}/version.GitCommit=${GIT_COMMIT} -X ${GIT_PATH}/${REPO_NAME}/version.BuildDate=${BUILD_DATE}" \
-o $(BIN_DIR)/$(BIN_NAME)
fmt: ; $(info running gofmt...) @ ## Run gofmt on all source files
@ret=0 && for d in $$($(GO) list -f '{{.Dir}}' ./...); do \
$(GOFMT) -l -w $$d/*.go || ret$$? ; \
done ; exit $$ret
install: build $(INSTALL_DIR)
cp ${BIN_DIR}/${BIN_NAME} ${INSTALL_DIR}/${BIN_NAME}
release_linux: build_linux
mkdir -p dist
tar czf dist/${BIN_NAME}-${VERSION}-linux-amd64.tar.gz bin/${BIN_NAME}
release_darwin: build_darwin
mkdir -p dist
tar czf dist/${BIN_NAME}-${VERSION}-darwin-amd64.tar.gz bin/${BIN_NAME}