-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (40 loc) · 1006 Bytes
/
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
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOGET = $(GOCMD) get
BINARY_NAME = metrics-gen
BINARY_UNIX = $(BINARY_NAME)_unix
OUTPUT_DIR = bin
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
all: clean format build build-example
build:
mkdir -p $(OUTPUT_DIR)
$(GOBUILD) -o $(OUTPUT_DIR)/$(BINARY_NAME) -v
clean:
$(GOCLEAN)
rm -rf $(OUTPUT_DIR)
test:
$(GOTEST) -v ./...
run:
$(GOBUILD) -o $(BINARY_NAME) -v
./$(BINARY_NAME)
deps:
$(GOGET) github.com/example/dependency
# Cross compilation for Linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v
format:
gofumpt -l -w . && \
golines -m 90 -w .
gen-example: clean build
for d in examples/*/ ; do \
$(ROOT_DIR)/$(OUTPUT_DIR)/$(BINARY_NAME) generate -d $$d -i ; \
done
build-example: gen-example
for d in examples/*/ ; do \
pushd $$d && \
go build -o $(ROOT_DIR)/$(OUTPUT_DIR)/$$(basename $$d) && \
popd ; \
done