-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (47 loc) · 1.38 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
-include .env
COMMIT := $(shell git rev-parse --short HEAD)
VERSION := $(shell git describe --tags ${COMMIT})
PROJECTNAME := $(shell basename "$(PWD)")
IMG ?= xerac/paper-soccer-judge:${VERSION}
# Go related variables.
GOBASE := $(shell pwd)
GOFILES := $(shell find $(GOBASE) -type f -name "*.go")
GOMAIN := $(GOBASE)/cmd/judge/main.go
BINDIR := $(GOBASE)/bin
# Use linker flags to provide version/build settings
LDFLAGS=-ldflags '-X=main.Version=$(VERSION) -X=main.Build=$(COMMIT) -extldflags="-static"'
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
.PHONY: fmt dep get test clean build run exec
fmt:
@echo ">>> Formatting project"
go fmt ./...
dep:
@echo ">>> Add missing and remove unused modules..."
go mod tidy
get: dep
@echo ">>> Checking if there is any missing dependencies..."
go get -u ./...
test: build clean
@echo ">>> Testing..."
go test ./...
clean:
@echo ">>> Cleaning build cache"
-rm -r $(BINDIR) 2> /dev/null
go clean ./...
build:
@echo ">>> Building binary..."
mkdir -p $(BINDIR) 2> /dev/null
go build $(LDFLAGS) -o $(BINDIR)/$(PROJECTNAME) $(GOMAIN)
run:
@echo ">>> Running..."
go run $(GOMAIN)
exec: build
@echo ">>> Executing binary..."
@$(BINDIR)/$(PROJECTNAME)
docker-build: build
@echo ">>> Building docker image..."
docker build -t $(IMG) .
docker-push: docker-build
@echo ">>> Pushing docker image..."
docker push $(IMG)