-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
146 lines (123 loc) · 4.3 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright 2021 Andrew 'Diddymus' Rolfe. All rights reserved.
#
# Use of this source code is governed by the license in the LICENSE file
# included with the source code.
#
# The Makefile is not required, a 'go build -o bin/ ./...' works as well :)
#
# Makefile to build WolfMUD. Targets of note:
#
# build - native build (default)
# build-all - build for all supported platforms
# build-race - build with race detector
# build-chroot - build minimal chroot environment
# run - start server with logging to terminal and bin/log
# batch - start server with logging to bin/log only
# race - start server with race detector enabled, logging to terminal and bin/log
# test - run tests
# cover - run tests with coverage collection and display in browser
# doc - start godoc server with notes turned on
# clean - clean bin directory
#
SHELL := /bin/bash
export CGO_ENABLED=0
export GOPROXY=off
export GORACE=history_size=7 halt_on_error=1
export GOCACHE=/tmp/go-build
export TZ=Europe/London
VERSION := $(shell git describe --dirty --always)
LDFLAGS := -ldflags "-X code.wolfmud.org/WolfMUD.git/core.commit=$(VERSION)"
# Standard native build
build: version
go build -o bin/ -v $(LDFLAGS) -gcflags="-e" ./...
build-all: build linux-amd64 linux-386 linux-arm5 linux-arm6 linux-arm7 linux-arm64 windows-amd64 windows-386
# Build targets also used by release/Makefile
linux-amd64: version
GOOS=linux GOARCH=amd64 go build -o bin/linux-amd64/ --trimpath -v $(LDFLAGS) ./...
linux-386: version
GOOS=linux GOARCH=386 go build -o bin/linux-386/ --trimpath -v $(LDFLAGS) ./...
linux-arm5: version
GOOS=linux GOARCH=arm GOARM=5 go build -o bin/linux-arm5/ --trimpath -v $(LDFLAGS) ./...
linux-arm6: version
GOOS=linux GOARCH=arm GOARM=6 go build -o bin/linux-arm6/ --trimpath -v $(LDFLAGS) ./...
linux-arm7: version
GOOS=linux GOARCH=arm GOARM=7 go build -o bin/linux-arm7/ --trimpath -v $(LDFLAGS) ./...
linux-arm64: version
GOOS=linux GOARCH=arm64 go build -o bin/linux-arm64/ --trimpath -v $(LDFLAGS) ./...
windows-amd64: version
GOOS=windows GOARCH=amd64 go build -o bin/windows-amd64/ --trimpath -v $(LDFLAGS) ./...
windows-386: version
GOOS=windows GOARCH=386 go build -o bin/windows-386/ --trimpath -v $(LDFLAGS) ./...
# Run server with logging to terminal and bin/log
run: build bin/log
cd bin ;\
clear ;\
./server 2>&1 | tee log/`date -u +%F-%T`.log
# Run server with logging to terminal only
term: build
cd bin ;\
clear ;\
./server
# Run server with logging to bin/log only
batch: build bin/log
cd bin ;\
clear ;\
./server > log/`date -u +%F-%T`.log 2>&1
# Build with race detector
build-race: version
CGO_ENABLED=1 go build -o ./bin/ -race -trimpath -v $(LDFLAGS) -gcflags -e ./...
# Build minimal chroot environment
build-chroot: build
mkdir -p chroot/bin ;\
mkdir -p chroot/data/players ;\
cp -a bin/server chroot/bin/ ;\
cp -a data/config.wrj chroot/data/ ;\
cp -a data/zones chroot/data/
# Run with race detector and logging to terminal and bin/log
race: build-race bin/log
cd bin ;\
clear ;\
./server 2>&1 | tee log/`date -u +%F-%T`.log
bin/log:
mkdir -p bin/log
# If our git commit ID changes touch version.go so that we relink and detect the
# change even if no source files have actually changed
version: build/version.txt
ifneq "$(shell cat build/version.txt)" "$(VERSION)"
echo $(VERSION) > build/version.txt ;\
touch ./core/version.go;
endif
build/version.txt:
touch build/version.txt
# Display Go environment as seen from the makefile for debugging
env:
go env
vet:
go vet ./...
.PHONY: test
test:
WOLFMUD_DIR="NONE" go test -cover ./...
.PHONY: test-race
test-race:
WOLFMUD_DIR="NONE" CGO_ENABLED=1 go test -race -cover ./...
.PHONY: cover
cover:
WOLFMUD_DIR="NONE" go test -coverprofile bin/cover.out ./...; \
go tool cover -html=bin/cover.out
.PHONY: bench
bench:
WOLFMUD_DIR="NONE" go test -run NONE -timeout 10m -bench "." -benchtime 1s ./...
.PHONY: bench-long
bench-long:
WOLFMUD_DIR="NONE" go test -run NONE -timeout 10m -bench "." -benchtime 10s ./...
.PHONY: doc
doc:
cd $(GOPATH)/src/ ;\
godoc -v -http=:6060 -notes="BUG|TODO|FIXME"
.PHONY: clean
clean:
find bin -type f -executable -delete ;\
find bin/log/ -type f -delete ;\
find bin -name "*prof" -delete ;\
find bin -name "cover.out" -delete ;\
go clean -cache -modcache