-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (46 loc) · 1.61 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
.PHONY: build windows gen clean version run mock
BINARY=openstation
VERSION=$(shell cat ./VERSION)
RELEASE=$(shell date +%Y%m%d%H%M%S)
COMMIT=$(shell git rev-parse --short HEAD)
SRC_DIR=./cmd
DIST_DIR=./build/dist
ASSETS_DIR=./build/assets
BUILD_ARCH=arm arm64 386 amd64 ppc64le riscv64 \
loong64 s390x
BUILD_FLAGS=-s -w -X main.version=$(VERSION) \
-X main.release=$(COMMIT)-$(RELEASE)
BUILD_ARGS=-trimpath
build: clean windows $(BUILD_ARCH)
$(BUILD_ARCH):
@echo "Building Linux $@ ..."
@mkdir -p $(DIST_DIR)/$@
@rm -rf $(DIST_DIR)/$@/*
@CGO_ENABLED=0 GOOS=linux GOARCH=$@ go build -ldflags="$(BUILD_FLAGS)" \
$(BUILD_ARGS) -o $(DIST_DIR)/$@/$(BINARY) $(SRC_DIR)/*.go
@cp -r $(ASSETS_DIR) $(DIST_DIR)/$@
windows:
@echo "Building Windows 32-bit & 64-bit ..."
@mkdir -p $(DIST_DIR)/win32 $(DIST_DIR)/win64
@rm -rf $(DIST_DIR)/win32/* $(DIST_DIR)/win64/*
# @CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="$(BUILD_FLAGS)" \
# $(BUILD_ARGS) -o $(DIST_DIR)/win32/$(BINARY).exe $(SRC_DIR)/*.go
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(BUILD_FLAGS)" \
$(BUILD_ARGS) -o $(DIST_DIR)/win64/$(BINARY).exe $(SRC_DIR)/*.go
@cp -r $(ASSETS_DIR) $(DIST_DIR)/win32
@cp -r $(ASSETS_DIR) $(DIST_DIR)/win64
gen:
ifeq ($(shell command -v gqlgen 2> /dev/null),)
@echo "Installing gqlgen..."
@go get github.com/99designs/gqlgen
@go install github.com/99designs/gqlgen
endif
@gqlgen generate
version:
@go run $(SRC_DIR)/*.go --version
run:
@go run $(SRC_DIR)/*.go --config $(ASSETS_DIR)/config.json
mock:
@go run $(SRC_DIR)/*.go --config $(ASSETS_DIR)/config.json --mock
clean:
@rm -rf $(DIST_DIR)/*