-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
36 lines (27 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
IMPORT_PATH=$(shell cat go.mod | head -n 1 | awk '{print $$2}')
BIN_NAME=$(notdir $(IMPORT_PATH))
default: build/$(BIN_NAME)
GIT_COMMIT_ID = $(shell git rev-parse --short HEAD)
VERSION=$(GIT_COMMIT_ID)-$(shell date +"%Y%m%d.%H%M%S")
GO_SOURCES = $(shell find . -type f -name '*.go' -print)
run: build/$(BIN_NAME)
build/$(BIN_NAME) -vvvv -i example.yaml run --dry-run -- cat 'hey something'
## Binary build
build/$(BIN_NAME): build/release///$(BIN_NAME)
cp $< $@
## Multi platform
release: build/release/linux/amd64/$(BIN_NAME)
release: build/release/linux/arm/$(BIN_NAME)
release: build/release/windows/amd64/$(BIN_NAME)
build/release/%/$(BIN_NAME): export GOOS=$(subst /,,$(dir $*))
build/release/%/$(BIN_NAME): export GOARCH=$(notdir $*)
build/release/%/$(BIN_NAME): $(GO_SOURCES)
@echo --------------------------BUILD $$GOOS $$GOARCH-----------------------------
go build -v \
-ldflags "-X main.VERSION=$(VERSION)" \
-o $@ .
@echo Build DONE
clean:
rm -rf build/
go clean
.PHONY: default run release clean