-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
59 lines (47 loc) · 1.29 KB
/
Makefile
File metadata and controls
59 lines (47 loc) · 1.29 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
# Environment
CC=go
BUILD=build
# Set the extension and compiler options
# We need to set CGO if we want to compile for windows from linux
# Running under windows
ifeq ($(OS),Windows_NT)
OS=windows
PREFIX=.exe
CGO=CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc
endif
# Compiling for windows
ifeq ($(OS), windows)
PREFIX=.exe
CGO=CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc
endif
# If compiling for linux we remove
ifeq ($(OS), linux)
undefine PREFIX
undefine CGO
endif
# Executable names
SERVERNAME=gochatd$(PREFIX)
CLIENTNAME=gochat$(PREFIX)
# Versioning
VERSION:=$(shell date +%s)
.PHONY: clean
all: $(BUILD)/$(SERVERNAME) $(BUILD)/$(CLIENTNAME)
server: $(BUILD)/$(SERVERNAME)
client: $(BUILD)/$(CLIENTNAME)
# Create build folder if it doesn't exist
$(BUILD):
if ! [ -d "./$(BUILD)" ]; then mkdir $(BUILD); fi
# We check the OS environment varible for the .exe extension
$(BUILD)/$(SERVERNAME): $(BUILD)
GOOS=$(OS) GOARCH=$(ARCH) $(CGO) \
$(CC) build -o $(BUILD)/$(SERVERNAME) \
-ldflags "-X main.serverBuild=$(VERSION)" \
./server
$(BUILD)/$(CLIENTNAME): $(BUILD)
GOOS=$(OS) GOARCH=$(ARCH) $(CGO) \
$(CC) build -o $(BUILD)/$(CLIENTNAME) \
-ldflags "-X main.clientBuild=$(VERSION)" \
./client
# Clean build folder
clean: $(BUILD)
rm -r $(BUILD)