-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
88 lines (75 loc) · 3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
.DEFAULT_GOAL:=local_or_with_proxy
USE_PROXY=GOPROXY=https://goproxy.io
VERSION:=$(shell git describe --abbrev=7 --dirty --always --tags)
LDFLAGS="-s -w -X github.com/nknorg/nconnect/config.Version=$(VERSION)"
BUILD=CGO_ENABLED=1 go build -ldflags $(LDFLAGS)
MAIN=./bin
XGO_MODULE=github.com/nknorg/nconnect/bin
XGO_BUILD=xgo -ldflags $(LDFLAGS) --targets=$(XGO_TARGET) $(XGOFLAGS)
BUILD_DIR=build
BIN_NAME=nConnect
ifdef GOARM
BIN_DIR=$(GOOS)-$(GOARCH)v$(GOARM)
XGO_TARGET=$(GOOS)/$(GOARCH)-$(GOARM)
else
BIN_DIR=$(GOOS)-$(GOARCH)
XGO_TARGET=$(GOOS)/$(GOARCH)
endif
LOCAL_EXT=$(EXT)
ifeq ($(OS),Windows_NT)
ifeq ($(LOCAL_EXT),)
LOCAL_EXT=.exe
endif
endif
web/dist: $(shell find web/src -type f -not -path "web/src/node_modules/*" -not -path "web/src/dist/*")
-@cd web/src && yarn && yarn generate && rm -rf ./dist/index.html.html && rm -rf ../dist && cp -a ./dist ../dist
.PHONY: local
local: web/dist
$(BUILD) -o $(BIN_NAME)$(LOCAL_EXT) $(MAIN)
.PHONY: local_with_proxy
local_with_proxy: web/dist
$(USE_PROXY) ${MAKE} local
.PHONY: local_or_with_proxy
local_or_with_proxy:
${MAKE} local || ${MAKE} local_with_proxy
.PHONY: build
build: web/dist
rm -rf $(BUILD_DIR)/$(BIN_DIR)
mkdir -p $(BUILD_DIR)/$(BIN_DIR)
cd $(BUILD_DIR)/$(BIN_DIR) && $(XGO_BUILD) -out $(BIN_NAME) $(XGO_MODULE) && mv $(BIN_NAME)* $(BIN_NAME)$(EXT)
mkdir -p $(BUILD_DIR)/$(BIN_DIR)/web/
@cp -a web/dist $(BUILD_DIR)/$(BIN_DIR)/web/
${MAKE} tar
.PHONY: tar
tar:
cd $(BUILD_DIR) && rm -f $(BIN_DIR).tar.gz && tar --exclude ".DS_Store" --exclude "__MACOSX" -czvf $(BIN_DIR).tar.gz $(BIN_DIR)
.PHONY: zip
zip:
cd $(BUILD_DIR) && rm -f $(BIN_DIR).zip && zip --exclude "*.DS_Store*" --exclude "*__MACOSX*" -r $(BIN_DIR).zip $(BIN_DIR)
.PHONY: all
all:
${MAKE} build GOOS=darwin GOARCH=amd64
${MAKE} build GOOS=linux GOARCH=amd64
${MAKE} build GOOS=linux GOARCH=arm64
${MAKE} build GOOS=linux GOARCH=arm GOARM=5
${MAKE} build GOOS=linux GOARCH=arm GOARM=6
${MAKE} build GOOS=linux GOARCH=arm GOARM=7
${MAKE} build GOOS=windows GOARCH=amd64 EXT=.exe
${MAKE} build GOOS=windows GOARCH=386 EXT=.exe
.PHONY: docker
docker:
${MAKE} build GOOS=linux GOARCH=amd64
docker build -f docker/Dockerfile --build-arg build_dir="./build/linux-amd64" -t nknorg/nconnect:latest-amd64 .
${MAKE} build GOOS=linux GOARCH=arm GOARM=7
docker build -f docker/Dockerfile --build-arg build_dir="./build/linux-armv7" --build-arg base="arm32v7/" -t nknorg/nconnect:latest-arm32v7 .
${MAKE} build GOOS=linux GOARCH=arm64
docker build -f docker/Dockerfile --build-arg build_dir="./build/linux-arm64" --build-arg base="arm64v8/" -t nknorg/nconnect:latest-arm64v8 .
.PHONY: docker_publish
docker_publish:
docker push nknorg/nconnect:latest-amd64
docker push nknorg/nconnect:latest-arm32v7
docker push nknorg/nconnect:latest-arm64v8
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create nknorg/nconnect:latest nknorg/nconnect:latest-amd64 nknorg/nconnect:latest-arm32v7 nknorg/nconnect:latest-arm64v8 --amend
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate nknorg/nconnect:latest nknorg/nconnect:latest-arm32v7 --os linux --arch arm --variant v7
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate nknorg/nconnect:latest nknorg/nconnect:latest-arm64v8 --os linux --arch arm64
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push -p nknorg/nconnect:latest