-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
95 lines (72 loc) · 2.63 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
89
90
91
92
93
94
95
NAME=kael
BUILDDIR=build
BASEPATH := $(shell pwd)
BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
BUILD := $(shell git rev-parse --short HEAD)
KAELSRCFILE := $(BASEPATH)/cmd/kael/
VERSION ?= $(BRANCH)-$(BUILD)
BuildTime:= $(shell date -u '+%Y-%m-%d %I:%M:%S%p')
COMMIT:= $(shell git rev-parse HEAD)
GOVERSION:= $(shell go version)
GOOS:=$(shell go env GOOS)
GOARCH:=$(shell go env GOARCH)
UIDIR=ui
YARNINSTALL=yarn install
YARNBUILD=yarn build
LDFLAGS=-w -s
KAELLDFLAGS+=-X 'main.Buildstamp=$(BuildTime)'
KAELLDFLAGS+=-X 'main.Githash=$(COMMIT)'
KAELLDFLAGS+=-X 'main.Goversion=$(GOVERSION)'
KAELBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(KAELLDFLAGS) ${LDFLAGS}"
define make_artifact_full
GOOS=$(1) GOARCH=$(2) $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$(1)-$(2) $(KAELSRCFILE)
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)/$(UIDIR)/dist/
cp $(BUILDDIR)/$(NAME)-$(1)-$(2) $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)/$(NAME)
-cp config_example.yml $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)/config_example.yml
cp -r $(UIDIR)/dist/* $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2)/$(UIDIR)/dist/
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$(1)-$(2).tar.gz $(NAME)-$(VERSION)-$(1)-$(2)
rm -rf $(BUILDDIR)/$(NAME)-$(VERSION)-$(1)-$(2) $(BUILDDIR)/$(NAME)-$(1)-$(2)
endef
build:
@echo "build kael"
GOARCH=$(GOARCH) GOOS=$(GOOS) $(KAELBUILD) -o $(BUILDDIR)/$(NAME) $(KAELSRCFILE)
all: kael-ui
$(call make_artifact_full,darwin,amd64)
$(call make_artifact_full,darwin,arm64)
$(call make_artifact_full,linux,amd64)
$(call make_artifact_full,linux,arm64)
$(call make_artifact_full,linux,mips64le)
$(call make_artifact_full,linux,ppc64le)
$(call make_artifact_full,linux,s390x)
$(call make_artifact_full,linux,riscv64)
local: kael-ui
$(call make_artifact_full,$(shell go env GOOS),$(shell go env GOARCH))
darwin-amd64: kael-ui
$(call make_artifact_full,darwin,amd64)
darwin-arm64: kael-ui
$(call make_artifact_full,darwin,arm64)
linux-amd64: kael-ui
$(call make_artifact_full,linux,amd64)
linux-arm64: kael-ui
$(call make_artifact_full,linux,arm64)
linux-loong64: kael-ui
$(call make_artifact_full,linux,loong64)
linux-mips64le: kael-ui
$(call make_artifact_full,linux,mips64le)
linux-ppc64le: kael-ui
$(call make_artifact_full,linux,ppc64le)
linux-s390x: kael-ui
$(call make_artifact_full,linux,s390x)
linux-riscv64: kael-ui
$(call make_artifact_full,linux,riscv64)
kael-ui:
@echo "build ui"
@cd $(UIDIR) && $(YARNINSTALL) && $(YARNBUILD)
.PHONY: docker
docker:
@echo "build docker images"
docker buildx build --build-arg VERSION=$(VERSION) -t jumpserver/kael .
.PHONY: clean
clean:
-rm -rf $(BUILDDIR)
-rm -rf $(UIDIR)/dist/*