-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (63 loc) · 2.85 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
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
# Source paths
SOURCE_SERVER=./cmd/server
SOURCE_CLIENT=./cmd/client
# Binary path and names
BINARY_PATH=bin
BINARY_NAME_SERVER=server
BINARY_NAME_CLIENT=client
# Build flags
BUILD_VERSION=`git rev-parse --short HEAD`
LDFLAGS=-ldflags "-X main.Build=$(BUILD_VERSION)"
# Docker
DOCKER_TAG=flo80/redirect
run_server: build_server
$(BINARY_PATH)/$(BINARY_NAME_SERVER) -s testdata/redirects.json -a localhost --debug
all: test build
test:
$(GOTEST) -v ./...
build: build_server build_client
build_server:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/$(BINARY_NAME_SERVER) -v $(SOURCE_SERVER)
build_client:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/$(BINARY_NAME_CLIENT) -v $(SOURCE_CLIENT)
clean:
$(GOCLEAN)
rm -f $(BINARY_PATH)/$(BINARY_NAME_SERVER)
rm -f $(BINARY_PATH)/$(BINARY_NAME_CLIENT)
# Cross compilation
build_all_architectures: build_linux build_mac build_raspbian3 build_windows
build_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/linux/$(BINARY_NAME_SERVER) -v $(SOURCE_SERVER)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/linux/$(BINARY_NAME_CLIENT) -v $(SOURCE_CLIENT)
build_raspbian3:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/raspbian3/$(BINARY_NAME_SERVER) -v $(SOURCE_SERVER)
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/raspbian3/$(BINARY_NAME_CLIENT) -v $(SOURCE_CLIENT)
build_windows:
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/windows/$(BINARY_NAME_SERVER).exe -v $(SOURCE_SERVER)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/windows/$(BINARY_NAME_CLIENT).exe -v $(SOURCE_CLIENT)
build_mac:
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/mac/$(BINARY_NAME_SERVER) -v $(SOURCE_SERVER)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_PATH)/mac/$(BINARY_NAME_CLIENT) -v $(SOURCE_CLIENT)
clean_cross_compilation:
rm -f $(BINARY_PATH)/linux/$(BINARY_NAME_SERVER)
rm -f $(BINARY_PATH)/linux/$(BINARY_NAME_CLIENT)
rm -f $(BINARY_PATH)/raspbian3/$(BINARY_NAME_SERVER)
rm -f $(BINARY_PATH)/raspbian3/$(BINARY_NAME_CLIENT)
rm -f $(BINARY_PATH)/windows/$(BINARY_NAME_SERVER).exe
rm -f $(BINARY_PATH)/windows/$(BINARY_NAME_CLIENT).exe
rm -f $(BINARY_PATH)/mac/$(BINARY_NAME_SERVER)
rm -f $(BINARY_PATH)/mac/$(BINARY_NAME_CLIENT)
docker_all: docker_clean docker docker_test
docker:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags "-X main.Build=$(BUILD_VERSION) -s" -o $(BINARY_PATH)/docker/$(BINARY_NAME_SERVER) -v $(SOURCE_SERVER)
docker build -t $(DOCKER_TAG) .
docker_test:
docker run -v `pwd`/testdata:/redirects -it -p 80:80 --rm $(DOCKER_TAG)
docker_clean:
rm -f $(BINARY_PATH)/docker/$(BINARY_NAME_SERVER)