-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
224 lines (188 loc) · 6.46 KB
/
Copy pathMakefile
File metadata and controls
224 lines (188 loc) · 6.46 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
GO=go
BIN=$(CURDIR)/bin
BUILD=$(CURDIR)/build
DEPS?=true
STATIC?=false
LDFLAGS=
WEBROOT_DIR=$(CURDIR)/webroot
DIST_APPS_DIR=$(WEBROOT_DIR)/apps
GO_DIRS=./overlord/... ./cmd/...
PY_FILES=$(shell find py -name "*.py")
# Supported architectures for ghost binary
GHOST_ARCHS=amd64 386 arm64 arm
GHOST_LINUX_BINS=$(addprefix $(BIN)/ghost.linux., $(GHOST_ARCHS))
GHOST_DARWIN_ARCHS=amd64 arm64
GHOST_DARWIN_BINS=$(addprefix $(BIN)/ghost.darwin., $(GHOST_DARWIN_ARCHS))
# Get list of apps with package.json
APP_DIRS=$(shell find apps -maxdepth 1 -mindepth 1 \
-type d -exec test -f '{}/package.json' \; -print | sed 's|apps/||')
APP_TARGETS=$(addprefix $(DIST_APPS_DIR)/,$(APP_DIRS))
# Output formatting
cmd_msg = @echo " $(1) $(2)"
ifeq ($(STATIC), true)
LDFLAGS=-a -tags netgo -installsuffix netgo \
-ldflags '-s -w -extldflags "-static"'
else
LDFLAGS=-ldflags '-s -w'
endif
.PHONY: all \
build build-go build-py build-apps \
ghost ghost-all overlordd \
go-fmt go-lint go-test \
py-lint py-format py-format-check \
pre-submit \
clean clean-apps \
install
all: build
build: build-go build-py build-apps
deps:
@mkdir -p $(BIN)
@if $(DEPS); then \
cd $(CURDIR); \
$(GO) get ./...; \
fi
overlordd: deps
$(call cmd_msg,GO,cmd/$@)
@GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
@rm -f $(BIN)/webroot
@ln -s $(WEBROOT_DIR) $(BIN)/webroot
ghost: deps
$(call cmd_msg,GO,cmd/$@)
@GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
$(BIN)/ghost.linux.%.sha1: $(BIN)/ghost.linux.%
$(call cmd_msg,SHA1,$(notdir $<))
@cd $(BIN) && sha1sum $(notdir $<) | awk '{ print $$1 }' > $(notdir $@)
$(BIN)/ghost.linux.%:
$(call cmd_msg,GO,$(notdir $@))
@GOOS=linux GOARCH=$* $(GO) build $(LDFLAGS) -o $@ $(CURDIR)/cmd/ghost
ghost-linux: $(GHOST_LINUX_BINS) $(GHOST_LINUX_BINS:=.sha1)
$(BIN)/ghost.darwin.%.sha1: $(BIN)/ghost.darwin.%
$(call cmd_msg,SHA1,$(notdir $<))
@cd $(BIN) && sha1sum $(notdir $<) | awk '{ print $$1 }' > $(notdir $@)
# Map Go GOARCH to osxcross CC prefix
OSXCROSS_CC_amd64=o64-clang
OSXCROSS_CXX_amd64=o64-clang++
OSXCROSS_CC_arm64=oa64-clang
OSXCROSS_CXX_arm64=oa64-clang++
$(BIN)/ghost.darwin.%:
$(call cmd_msg,GO,$(notdir $@))
@PATH="/osxcross/bin:$$PATH" \
LD_LIBRARY_PATH="/osxcross/lib:$$LD_LIBRARY_PATH" \
CC=$(OSXCROSS_CC_$*) CXX=$(OSXCROSS_CXX_$*) \
MACOSX_DEPLOYMENT_TARGET=10.8 \
CGO_ENABLED=1 \
GOOS=darwin GOARCH=$* $(GO) build $(LDFLAGS) -o $@ $(CURDIR)/cmd/ghost
ghost-darwin: $(GHOST_DARWIN_BINS) $(GHOST_DARWIN_BINS:=.sha1)
ifeq ($(STATIC), true)
$(call cmd_msg,VERIFY,macOS binaries)
@echo "Verifying macOS ghost binaries..."
@for binary in $(GHOST_DARWIN_BINS); do \
if [ -f "$$binary" ]; then \
echo "Checking $$binary:"; \
file "$$binary" | grep -q "Mach-O" && \
echo "✓ $$binary is a Mach-O executable (macOS binary)" || \
(echo "WARNING: Could not verify $$binary format" && file "$$binary"); \
fi; \
done
endif
# Verify static linking when STATIC=true
verify-static:
ifeq ($(STATIC), true)
$(call cmd_msg,VERIFY,binary linking)
@echo "Verifying ghost binary linking..."
@for binary in $(GHOST_LINUX_BINS); do \
if [ -f "$$binary" ]; then \
echo "Checking $$binary (Linux):"; \
if ldd "$$binary" 2>/dev/null | grep -q "=>"; then \
echo "ERROR: $$binary is dynamically linked!"; \
ldd "$$binary"; \
exit 1; \
else \
echo "✓ $$binary is statically linked"; \
fi; \
fi; \
done
@if [ -f "$(BIN)/ghost" ]; then \
echo "Checking $(BIN)/ghost (local platform):"; \
if [ "$$(uname)" = "Darwin" ]; then \
echo "✓ $(BIN)/ghost built for macOS (dynamic linking expected)"; \
else \
if ldd "$(BIN)/ghost" 2>/dev/null | grep -q "=>"; then \
echo "ERROR: $(BIN)/ghost is dynamically linked!"; \
ldd "$(BIN)/ghost"; \
exit 1; \
else \
echo "✓ $(BIN)/ghost is statically linked"; \
fi; \
fi; \
fi
@echo "Ghost binary linking verified successfully!"
endif
build-go: overlordd ghost ghost-linux verify-static
build-py:
@ln -sf ../py/ghost.py bin
$(call cmd_msg,SHA1,ghost.py)
@sha1sum py/ghost.py | awk '{ print $$1 }' > bin/ghost.py.sha1
@mkdir -p $(BUILD)
$(call cmd_msg,VENV,creating virtualenv)
@rm -rf $(BUILD)/.venv
@python -m venv $(BUILD)/.venv
$(call cmd_msg,PIP,installing requirements)
@cd $(BUILD); \
. $(BUILD)/.venv/bin/activate; \
pip install -q -r $(CURDIR)/py/requirements.txt; \
pip install -q pyinstaller
$(call cmd_msg,GEN,ovl.pybin)
@cd $(BUILD); . $(BUILD)/.venv/bin/activate; \
pyinstaller --onefile $(CURDIR)/py/ovl.py > /dev/null;
@mv $(BUILD)/dist/ovl $(BIN)/ovl.pybin
$(call cmd_msg,SHA1,ovl.pybin)
@cd $(BIN) && sha1sum ovl.pybin | awk '{ print $$1 }' > ovl.pybin.sha1
$(call cmd_msg,GEN,ghost.pybin)
@cd $(BUILD); . $(BUILD)/.venv/bin/activate; \
pyinstaller --onefile $(CURDIR)/py/ghost.py > /dev/null
@mv $(BUILD)/dist/ghost $(BIN)/ghost.pybin
$(call cmd_msg,SHA1,ghost.pybin)
@cd $(BIN) && sha1sum ghost.pybin | awk '{ print $$1 }' > ghost.pybin.sha1
go-fmt:
$(call cmd_msg,FMT,$(GO_DIRS))
@$(GO) fmt $(GO_DIRS)
go-lint:
$(call cmd_msg,GOLANGCI-LINT,$(GO_DIRS))
@which golangci-lint > /dev/null || (echo "Installing golangci-lint v1.62.0..." && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.62.0)
@golangci-lint run ./overlord/... ./cmd/...
go-test:
$(call cmd_msg,TEST,$(GO_DIRS))
@$(GO) test ./overlord/... ./cmd/...
py-lint:
$(call cmd_msg,PYLINT,$(PY_FILES))
@pylint --rcfile=.pylintrc $(PY_FILES)
py-format:
$(call cmd_msg,YAPF,$(PY_FILES))
@yapf -i $(PY_FILES)
py-format-check:
$(call cmd_msg,YAPF-CHECK,$(PY_FILES))
@yapf --diff $(PY_FILES) | tee /tmp/yapf.diff && test ! -s /tmp/yapf.diff || \
(echo "Python files need formatting. Run 'make py-format' locally." && exit 1)
# Pattern rule for building individual apps
$(DIST_APPS_DIR)/%:
$(call cmd_msg,NPM,$*)
@mkdir -p $(DIST_APPS_DIR)
@cd apps/$* && npm install --silent && npm run build --silent
@cp -r apps/$*/dist $(DIST_APPS_DIR)/$*
build-apps: $(APP_TARGETS)
@cp $(DIST_APPS_DIR)/dashboard/index.html $(WEBROOT_DIR)
pre-submit: go-fmt go-lint go-test py-format-check py-lint
clean-apps:
$(call cmd_msg,RM,apps)
@rm -rf $(DIST_APPS_DIR)
@rm -rf $(WEBROOT_DIR)/index.html
clean: clean-apps
$(call cmd_msg,RM,build artifacts)
@rm -rf $(BIN)/ghost* $(BIN)/overlordd $(BUILD) \
$(BIN)/ghost.pybin $(BIN)/ovl.pybin \
$(DIST_APPS_DIR)