-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (52 loc) · 1.51 KB
/
Makefile
File metadata and controls
69 lines (52 loc) · 1.51 KB
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
-include .env
VERSION := $(shell git describe --tags)
BUILD := $(shell git rev-parse --short HEAD)
PROJECTNAME := $(shell basename "$(PWD)")
# Go related variables.
GOFILES := $(wildcard cmd/*.go)
# Use linker flags to provide version/build settings
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)"
# Redirect error output to a file, so we can show it in development mode.
STDERR := /tmp/.$(PROJECTNAME)-stderr.txt
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
## compile: Compile the binary.
compile:
@-touch $(STDERR)
@-rm $(STDERR)
@-$(MAKE) -s go-compile 2> $(STDERR)
@cat $(STDERR)
## install: Install missing dependencies. Runs `go get` internally. e.g; make install get=github.com/foo/bar
install: go-get
## run: Run the application
run:
@-$(MAKE) go-run
## clean: Clean build files. Runs `go clean` internally.
clean:
@-rm ./bin/$(PROJECTNAME) 2> /dev/null
@-$(MAKE) go-clean
go-compile: go-get go-build
go-build:
@echo " > Building binary..."
go build $(LDFLAGS) -o ./bin/$(PROJECTNAME) $(GOFILES)
go-generate:
@echo " > Generating dependency files..."
go generate $(generate)
go-get:
@echo " > Checking if there is any missing dependencies..."
go get $(get) -v all
go-install:
go install $(GOFILES)
go-run:
go run $(LDFLAGS) $(GOFILES)
go-clean:
@echo " > Cleaning build cache"
go clean
.PHONY: help
all: help
help: Makefile
@echo
@echo " Choose a command run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo