-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (90 loc) · 3.4 KB
/
Copy pathMakefile
File metadata and controls
98 lines (90 loc) · 3.4 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
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
96
97
98
GO ?= go
CC ?= cc
XZ ?= xz
GO_BUILD_FLAGS ?= -trimpath
GO_LD_FLAGS ?= -s -w
GO_BUILD_ARGS := $(GO_BUILD_FLAGS) -ldflags "$(GO_LD_FLAGS)"
SFX_MARKER ?= GO_HARNESS_SFX_PAYLOAD_V1_7d3fe19aab2c4f90
GOBIN := $(shell $(GO) env GOBIN)
ifeq ($(strip $(GOBIN)),)
GOBIN := $(shell $(GO) env GOPATH)/bin
endif
INSTALL_DIR ?= $(GOBIN)
.PHONY: build
build:
mkdir -p bin/filesystem bin/shell bin/git
$(GO) build $(GO_BUILD_ARGS) -o bin/go-harness-agent ./cmd/go-harness
$(GO) build $(GO_BUILD_ARGS) -o bin/go-harness ./cmd/go-harness-launcher
$(GO) build $(GO_BUILD_ARGS) -o bin/filesystem/filesystem ./cmd/filesystem
$(GO) build $(GO_BUILD_ARGS) -o bin/shell/shell ./cmd/shell
$(GO) build $(GO_BUILD_ARGS) -o bin/git/git ./cmd/git
os="$$(uname -s 2>/dev/null || echo Windows_NT)"; \
case "$$os" in \
Darwin*) platform="macos"; ext="" ;; \
Linux*) platform="linux"; ext="" ;; \
MINGW*|MSYS*|CYGWIN*|Windows_NT*) platform="windows"; ext=".exe" ;; \
*) platform="unknown"; ext="" ;; \
esac; \
if ! command -v "$(UPX)" >/dev/null 2>&1; then \
echo "UPX not installed; skipping compression"; \
exit 0; \
fi; \
for bin in \
"$(INSTALL_DIR)/go-harness-agent$$ext" \
"$(INSTALL_DIR)/go-harness$$ext" \
"$(INSTALL_DIR)/go-harness-filesystem$$ext" \
"$(INSTALL_DIR)/go-harness-shell$$ext" \
"$(INSTALL_DIR)/go-harness-git$$ext"; do \
if [ ! -f "$$bin" ]; then \
continue; \
fi; \
backup="$$bin.before-upx"; \
cp "$$bin" "$$backup"; \
case "$$platform" in \
macos) \
if [ "$(UPX_MACOS)" != "1" ]; then \
echo "macOS detected; skipping UPX for $$bin. Use UPX_MACOS=1 to force."; \
rm -f "$$backup"; \
continue; \
fi; \
"$(UPX)" $(UPX_FLAGS) $(UPX_MACOS_FLAGS) "$$bin" || { mv "$$backup" "$$bin"; exit 1; }; \
"$(CODESIGN)" --force --sign - "$$bin" || { mv "$$backup" "$$bin"; exit 1; }; \
"$$bin" --help >/dev/null 2>&1 || { echo "packed macOS binary failed smoke test; restoring $$bin"; mv "$$backup" "$$bin"; exit 1; }; \
;; \
linux) \
"$(UPX)" $(UPX_FLAGS) $(UPX_LINUX_FLAGS) "$$bin" || { mv "$$backup" "$$bin"; exit 1; }; \
"$$bin" --help >/dev/null 2>&1 || { echo "packed Linux binary failed smoke test; restoring $$bin"; mv "$$backup" "$$bin"; exit 1; }; \
;; \
windows) \
"$(UPX)" $(UPX_FLAGS) $(UPX_WINDOWS_FLAGS) "$$bin" || { mv "$$backup" "$$bin"; exit 1; }; \
;; \
*) \
echo "unsupported platform $$os; skipping compression for $$bin"; \
rm -f "$$backup"; \
continue; \
;; \
esac; \
rm -f "$$backup"; \
done
.PHONY: install
install: install-harness install-providers
@echo "installed binaries to $(INSTALL_DIR)"
@echo "make sure $(INSTALL_DIR) is in your PATH"
.PHONY: install-harness
install-harness:
mkdir -p "$(INSTALL_DIR)"
$(GO) build $(GO_BUILD_ARGS) -o "$(INSTALL_DIR)/go-harness-agent" ./cmd/go-harness
$(GO) build $(GO_BUILD_ARGS) -o "$(INSTALL_DIR)/go-harness" ./cmd/go-harness-launcher
.PHONY: install-providers
install-providers:
mkdir -p "$(INSTALL_DIR)"
$(GO) build $(GO_BUILD_ARGS) -o "$(INSTALL_DIR)/go-harness-filesystem" ./cmd/filesystem
$(GO) build $(GO_BUILD_ARGS) -o "$(INSTALL_DIR)/go-harness-shell" ./cmd/shell
$(GO) build $(GO_BUILD_ARGS) -o "$(INSTALL_DIR)/go-harness-git" ./cmd/git
.PHONY: uninstall
uninstall:
rm -f "$(INSTALL_DIR)/go-harness"
rm -f "$(INSTALL_DIR)/go-harness-agent"
rm -f "$(INSTALL_DIR)/go-harness-filesystem"
rm -f "$(INSTALL_DIR)/go-harness-shell"
rm -f "$(INSTALL_DIR)/go-harness-git"