-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
71 lines (58 loc) · 2.28 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
VERSION=$(shell grep -e 'const Version' rivescript.go | head -n 1 | cut -d '"' -f 2)
BUILD=$(shell git describe --always)
CURDIR=$(shell pwd)
# Inject the build version (commit hash) into the executable.
LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
# `make setup` to set up git submodules
.PHONY: setup
setup:
git submodule init
git submodule update
# `make build` to build the binary
.PHONY: build
build:
go build $(LDFLAGS) -o bin/rivescript cmd/rivescript/main.go
# `make run` to run the rivescript cmd
.PHONY: run
run:
go run $(LDFLAGS) cmd/rivescript/main.go eg/brain
# `make debug` to run the rivescript cmd in debug mode
.PHONY: debug
debug:
go run $(LDFLAGS) cmd/rivescript/main.go -debug eg/brain
# `make fmt` to run gofmt
.PHONY: fmt
fmt:
gofmt -w .
# `make test` to run unit tests
.PHONY: test
test:
go test
# `make clean` cleans up everything
.PHONY: clean
clean:
rm -rf bin dist
################################################################################
## Below are commands for shipping distributable binaries for each platfomr. ##
################################################################################
PLATFORMS := linux/amd64 linux/386 darwin/amd64
WIN32 := windows/amd64 windows/386
release: $(PLATFORMS) $(WIN32)
.PHONY: release $(PLATFORMS)
# Handy variables to pull OS and arch from $PLATFORMS.
temp = $(subst /, ,$@)
os = $(word 1, $(temp))
arch = $(word 2, $(temp))
$(PLATFORMS):
mkdir -p dist/rivescript-$(VERSION)-$(os)-$(arch)
cp -r README.md LICENSE Changes.md eg dist/rivescript-$(VERSION)-$(os)-$(arch)/
GOOS=$(os) GOARCH=$(arch) go build $(LDFLAGS) -v -i -o bin/rivescript cmd/rivescript/main.go
cp bin/rivescript dist/rivescript-$(VERSION)-$(os)-$(arch)/
cd dist; tar -czvf ../rivescript-$(VERSION)-$(os)-$(arch).tar.gz rivescript-$(VERSION)-$(os)-$(arch)
$(WIN32):
mkdir -p dist/rivescript-$(VERSION)-$(os)-$(arch)
cp -r README.md LICENSE Changes.md eg dist/rivescript-$(VERSION)-$(os)-$(arch)/
GOOS=$(os) GOARCH=$(arch) go build $(LDFLAGS) -v -i -o bin/rivescript.exe cmd/rivescript/main.go
cp bin/rivescript.exe dist/rivescript-$(VERSION)-$(os)-$(arch)/
echo -e "@echo off\nrivescript eg/brain" > dist/rivescript-$(VERSION)-$(os)-$(arch)/example.bat
cd dist; zip -r ../rivescript-$(VERSION)-$(os)-$(arch).zip rivescript-$(VERSION)-$(os)-$(arch)