-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
98 lines (76 loc) · 2.72 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
NAME := go209
PKG := github.com/xntrik/go209
REPO := xntrik
SHELL := /bin/bash
PREFIX?=$(shell pwd)
BUILDDIR := ${PREFIX}/cross
PLUGINDIR := ${PREFIX}/pkg/go209/modules
PLUGINS := $(wildcard $(PLUGINDIR)/*.go)
PLUGINSOUT := $(patsubst $(PLUGINDIR)/%.go, $(PREFIX)/%.so, $(PLUGINS))
.DEFAULT_GOAL := help
GO := go
all: clean fmt lint vet build ## Clean, fmt, lint, vet and build!
.PHONY: pluginsget
pluginsget: # run go get in the plugins folder before building
@echo "Fetching plugin dependencies"
cd $(PLUGINDIR); $(GO) get -d
.PHONY: buildplugins
buildplugins: pluginsget $(PLUGINSOUT) ## Build .so files from contents of pkg/go209/modules/*.go
$(PREFIX)/%.so: $(PLUGINDIR)/%.go
@echo "+ $@"
ifndef STATIC_BUILD
$(GO) build -buildmode=plugin -o $@ $<
else
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(GO) build -buildmode=plugin -a -tags netgo -ldflags '-w' -o $@ $<
endif
.PHONY: build
build: buildplugins $(NAME) ## Builds the binary and plugins
static: # Build a static executable - don't forget to build the plugins statically as well
@echo "+ $@"
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(GO) build -a -tags netgo -ldflags '-w'
$(NAME): $(wildcard *.go) $(wildcard */*.go)
@echo "+ $@"
$(GO) build -o $(NAME) .
.PHONY: fmt
fmt: ## Verifies all files have been `gofmt`ed.
@echo "+ $@"
@if [[ ! -z "$(shell gofmt -s -l . | grep -v '.pb.go:' | grep -v '.twirp.go:' | grep -v vendor | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: lint
lint: ## Verifies `golint` passes.
@echo "+ $@"
@if [[ ! -z "$(shell golint ./... | grep -v '.pb.go:' | grep -v '.twirp.go:' | grep -v vendor | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: vet
vet: ## Verifies `go vet` passes.
@echo "+ $@"
@if [[ ! -z "$(shell $(GO) vet $(shell $(GO) list ./... | grep -v vendor | grep -v pkg/go209/modules) | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: image
image: clean ## Create docker image from the Dockerfile
@docker build --rm --force-rm -t $(NAME) .
.PHONY: imagepush
imagepush: clean ## Create a fresh docker image and push to the configured repo
@docker build --rm --force-rm -t $(REPO)/$(NAME):latest .
@docker push $(REPO)/$(NAME)
.PHONY: docker-compose-build
docker-compose-build: clean ## Build the docker compose
@docker-compose build
.PHONY: docker-compose-up
docker-compose-up: ## Start the docker compose
@docker-compose up
.PHONY: docker-compose-upd
docker-compose-upd: ## Start the docker compose in background mode
@docker-compose up -d
.PHONY: clean
clean: ## Cleanup any build binaries or packages
@echo "+ $@"
$(RM) $(NAME)
$(RM) -r $(BUILDDIR)
$(RM) *.so
.PHONY: help
help:
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"