-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
65 lines (51 loc) · 1.63 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
# This file is part of GoAddons, which is licensed under the GNU General Public License v3.0.
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
# Makefile for building GoAddons
# The name of the binary to be created
BINARY_NAME=goaddons
# Output directory for binaries
BIN_DIR=./bin
# Full path for the binary
BINARY_PATH=$(BIN_DIR)/$(BINARY_NAME)
# Retrieves the current version from version.go
VERSION=$(shell grep 'Version =' version/Version.go | awk '{ print $$3 }' | tr -d '"')
# Retrieves the latest commit hash of the current branch
COMMIT_HASH=$(shell git rev-parse HEAD)
# Retrieves the current date and time
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOVET=$(GOCMD) vet
GOFMT=gofmt
# Ensure the bin directory exists
.PHONY: prepare
prepare:
mkdir -p $(BIN_DIR)
# Check go fmt
.PHONY: fmt-check
fmt-check:
@echo "Running gofmt"
@test -z $($(GOFMT) -l . | tee /dev/stderr) || (echo "[ERROR] Fix formatting issues with 'gofmt'" && exit 1)
# Vet
.PHONY: vet
vet:
@echo "Running go vet"
@$(GOVET) ./... || (echo "[ERROR] Fix the issues reported by 'go vet' above" && exit 1)
# Build the project
.PHONY: release
release: prepare fmt-check vet
$(GOBUILD) -ldflags "-X goaddons/version.Version=$(VERSION) -X goaddons/version.Commit=$(COMMIT_HASH) -X goaddons/version.BuildDate=$(BUILD_DATE)" -o $(BINARY_PATH) -v
# Clean up binaries
.PHONY: clean
clean:
$(GOCLEAN)
rm -f $(BINARY_PATH)
# Run tests
.PHONY: test
test:
$(GOTEST) -v ./...