@@ -9,7 +9,41 @@ LDFLAGS=-w -s
99
1010CLIENTBUILD=CGO_ENABLED =0 go build -trimpath
1111
12- build-client :
12+ # 自动检测当前平台
13+ CURRENT_OS := $(shell go env GOOS)
14+ CURRENT_ARCH := $(shell go env GOARCH)
15+
16+ # 默认目标:只构建当前平台
17+ .PHONY : default
18+ default : build-current
19+
20+ # 构建当前平台
21+ .PHONY : build-current
22+ build-current :
23+ @echo " Building for current platform: $( CURRENT_OS) /$( CURRENT_ARCH) "
24+ @rm -rf $(BUILDDIR )
25+ @mkdir -p $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH )
26+ @if [ " $( CURRENT_OS) " = " windows" ]; then \
27+ $(CLIENTBUILD ) -ldflags " $( LDFLAGS) -H windowsgui" -o $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH ) /JumpServerClient.exe $(CLIENTSRCFILE ) ; \
28+ $(CLIENTBUILD ) -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH ) /client.exe $(SSHCSRCFILE ) ; \
29+ else \
30+ $(CLIENTBUILD ) -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH ) /JumpServerClient $(CLIENTSRCFILE ) ; \
31+ $(CLIENTBUILD ) -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH ) /client $(SSHCSRCFILE ) ; \
32+ fi
33+ @if [ " $( CURRENT_OS) " = " darwin" ]; then \
34+ cp -R $(BASEPATH ) /Scripts $(BUILDDIR ) /$(CURRENT_OS ) -$(CURRENT_ARCH ) /; \
35+ fi
36+ @mkdir -p $(BASEPATH ) /../src-tauri/resources/bin/
37+ @cp -R $(BUILDDIR ) /* $(BASEPATH ) /../src-tauri/resources/bin/
38+ @cp $(BASEPATH ) /config.json $(BASEPATH ) /../src-tauri/resources/bin/
39+ @if [ " $( CURRENT_OS) " = " windows" ]; then \
40+ cp $(BASEPATH ) /putty.exe $(BASEPATH ) /../src-tauri/resources/bin/windows/; \
41+ cp $(BASEPATH ) /pkg/autoit/* .dll $(BASEPATH ) /../src-tauri/resources/bin/windows/; \
42+ fi
43+
44+ # 构建所有平台
45+ .PHONY : build-all
46+ build-all :
1347 GOARCH=amd64 GOOS=darwin $(CLIENTBUILD ) -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /darwin-amd64/JumpServerClient $(CLIENTSRCFILE )
1448 GOARCH=amd64 GOOS=darwin $(CLIENTBUILD ) -ldflags " $( LDFLAGS) " -o $(BUILDDIR ) /darwin-amd64/client $(SSHCSRCFILE )
1549
@@ -33,3 +67,18 @@ build-client:
3367 cp $(BASEPATH)/config.json $(BASEPATH)/../src-tauri/resources/bin/
3468 cp $(BASEPATH)/putty.exe $(BASEPATH)/../src-tauri/resources/bin/windows/
3569 cp $(BASEPATH)/pkg/autoit/*.dll $(BASEPATH)/../src-tauri/resources/bin/windows/
70+
71+ # 帮助信息
72+ .PHONY : help
73+ help :
74+ @echo " Available targets:"
75+ @echo " make - Build for current platform only (default)"
76+ @echo " make build-client - Build for current platform only"
77+ @echo " make build-all - Build for all platforms (darwin, windows, linux)"
78+ @echo " make help - Show this help message"
79+ @echo " "
80+ @echo " Current platform: $( CURRENT_OS) /$( CURRENT_ARCH) "
81+
82+ # build-client 就是 build-current
83+ .PHONY : build-client
84+ build-client : build-current
0 commit comments