-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (68 loc) · 1.73 KB
/
Makefile
File metadata and controls
83 lines (68 loc) · 1.73 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Makefile for Nox
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
# Binary name
BINARY_NAME=nox
# Build flags
VERSION=1.0.0
BUILD_TIME=$(shell date +%F_%T)
GIT_COMMIT=$(shell git rev-parse HEAD)
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT)"
# Default target
.PHONY: all
all: clean fmt vet test build
# Build the binary
.PHONY: build
build:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) cmd/nox.go
# Run tests
.PHONY: test
test:
$(GOTEST) -v ./...
# Format code
.PHONY: fmt
fmt:
$(GOFMT) ./...
# Run go vet
.PHONY: vet
vet:
$(GOVET) ./...
# Clean build files
.PHONY: clean
clean:
rm -f $(BINARY_NAME)
$(GOCLEAN)
# Cross compilation
.PHONY: build-linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)_linux_amd64 cmd/nox.go
.PHONY: build-windows
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)_windows_amd64.exe cmd/nox.go
.PHONY: build-darwin
build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)_darwin_amd64 cmd/nox.go
# Build all platforms
.PHONY: build-all
build-all: build-linux build-windows build-darwin
# Install binary
.PHONY: install
install: build
mv $(BINARY_NAME) $(GOPATH)/bin/
# Help target
.PHONY: help
help:
@echo "Available targets:"
@echo " all : Clean, format, test and build"
@echo " build : Build binary"
@echo " test : Run tests"
@echo " fmt : Format code"
@echo " vet : Run go vet"
@echo " clean : Clean build files"
@echo " build-all : Build for all platforms"
@echo " install : Install binary"