forked from zerocore-ai/microsandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (191 loc) · 8.32 KB
/
Makefile
File metadata and controls
211 lines (191 loc) · 8.32 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
# =============================================================================
# Microsandbox Makefile - Build and install microsandbox components
# =============================================================================
# -----------------------------------------------------------------------------
# System Detection and Architecture
# -----------------------------------------------------------------------------
OS := $(shell uname -s)
ARCH := $(shell uname -m)
ifeq ($(ARCH),aarch64)
ARCH := arm64
endif
ifeq ($(ARCH),x86_64)
ARCH := x86_64
endif
# -----------------------------------------------------------------------------
# Build Configuration
# -----------------------------------------------------------------------------
DEBUG ?= 0
LTO ?= 0
CARGO_BUILD_MODE := $(if $(filter 1,$(DEBUG)),,--release)
CARGO_TARGET_DIR := target/$(if $(filter 1,$(DEBUG)),debug,release)
# Set CARGO_PROFILE_RELEASE_LTO based on LTO setting
export CARGO_PROFILE_RELEASE_LTO := $(if $(filter 1,$(LTO)),true,off)
# -----------------------------------------------------------------------------
# Installation Paths
# -----------------------------------------------------------------------------
HOME_LIB := $(HOME)/.local/lib
HOME_BIN := $(HOME)/.local/bin
# -----------------------------------------------------------------------------
# Build Paths and Directories
# -----------------------------------------------------------------------------
MSB_BIN := $(CARGO_TARGET_DIR)/msb
MSBRUN_BIN := $(CARGO_TARGET_DIR)/msbrun
MSBSERVER_BIN := $(CARGO_TARGET_DIR)/msbserver
EXAMPLES_DIR := target/release/examples
BENCHES_DIR := target/release
BUILD_DIR := build
SCRIPT_DIR := scripts
ALIASES_DIR := $(SCRIPT_DIR)/aliases
# -----------------------------------------------------------------------------
# Library Detection
# -----------------------------------------------------------------------------
ifeq ($(OS),Darwin)
LIBKRUNFW_FILE := $(shell ls $(BUILD_DIR)/libkrunfw.*.dylib 2>/dev/null | head -n1)
LIBKRUN_FILE := $(shell ls $(BUILD_DIR)/libkrun.*.dylib 2>/dev/null | head -n1)
else
LIBKRUNFW_FILE := $(shell ls $(BUILD_DIR)/libkrunfw.so.* 2>/dev/null | head -n1)
LIBKRUN_FILE := $(shell ls $(BUILD_DIR)/libkrun.so.* 2>/dev/null | head -n1)
endif
# -----------------------------------------------------------------------------
# Phony Targets Declaration
# -----------------------------------------------------------------------------
.PHONY: all build install clean build_libkrun example bench bin _run_example _run_bench _run_bin help uninstall microsandbox _build_aliases
# -----------------------------------------------------------------------------
# Main Targets
# -----------------------------------------------------------------------------
all: build
build: build_libkrun
@$(MAKE) _build_msb
@$(MAKE) _build_aliases
_build_msb: $(MSB_BIN) $(MSBRUN_BIN) $(MSBSERVER_BIN)
@mkdir -p $(BUILD_DIR)
@cp $(MSB_BIN) $(BUILD_DIR)/
@cp $(MSBRUN_BIN) $(BUILD_DIR)/
@cp $(MSBSERVER_BIN) $(BUILD_DIR)/
@echo "Msb build artifacts ($(if $(filter 1,$(DEBUG)),debug,release) mode) copied to $(BUILD_DIR)/"
_build_aliases:
@mkdir -p $(BUILD_DIR)
@cp $(ALIASES_DIR)/msr $(BUILD_DIR)/
@cp $(ALIASES_DIR)/msx $(BUILD_DIR)/
@cp $(ALIASES_DIR)/msi $(BUILD_DIR)/
@echo "Alias scripts copied to $(BUILD_DIR)/"
# -----------------------------------------------------------------------------
# Binary Building
# -----------------------------------------------------------------------------
$(MSB_BIN): build_libkrun
cd microsandbox-core
ifeq ($(OS),Darwin)
RUSTFLAGS="-C link-args=-Wl,-rpath,@executable_path/../lib,-rpath,@executable_path" cargo build $(CARGO_BUILD_MODE) --bin msb --features cli $(FEATURES)
else
RUSTFLAGS="-C link-args=-Wl,-rpath,\$$ORIGIN/../lib,-rpath,\$$ORIGIN" cargo build $(CARGO_BUILD_MODE) --bin msb --features cli $(FEATURES)
endif
$(MSBRUN_BIN): build_libkrun
cd microsandbox-core
ifeq ($(OS),Darwin)
RUSTFLAGS="-C link-args=-Wl,-rpath,@executable_path/../lib,-rpath,@executable_path" cargo build $(CARGO_BUILD_MODE) --bin msbrun --features cli $(FEATURES)
codesign --entitlements microsandbox.entitlements --force -s - $@
else
RUSTFLAGS="-C link-args=-Wl,-rpath,\$$ORIGIN/../lib,-rpath,\$$ORIGIN" cargo build $(CARGO_BUILD_MODE) --bin msbrun --features cli $(FEATURES)
endif
$(MSBSERVER_BIN): build_libkrun
cd microsandbox-core
ifeq ($(OS),Darwin)
RUSTFLAGS="-C link-args=-Wl,-rpath,@executable_path/../lib,-rpath,@executable_path" cargo build $(CARGO_BUILD_MODE) --bin msbserver --features cli $(FEATURES)
else
RUSTFLAGS="-C link-args=-Wl,-rpath,\$$ORIGIN/../lib,-rpath,\$$ORIGIN" cargo build $(CARGO_BUILD_MODE) --bin msbserver --features cli $(FEATURES)
endif
# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------
install: build
@echo "Installing $(if $(filter 1,$(DEBUG)),debug,release) build..."
install -d $(HOME_BIN)
install -d $(HOME_LIB)
install -m 755 $(BUILD_DIR)/msb $(HOME_BIN)/msb
install -m 755 $(BUILD_DIR)/msbrun $(HOME_BIN)/msbrun
install -m 755 $(BUILD_DIR)/msbserver $(HOME_BIN)/msbserver
install -m 755 $(BUILD_DIR)/msr $(HOME_BIN)/msr
install -m 755 $(BUILD_DIR)/msx $(HOME_BIN)/msx
install -m 755 $(BUILD_DIR)/msi $(HOME_BIN)/msi
@if [ -n "$(LIBKRUNFW_FILE)" ]; then \
install -m 755 $(LIBKRUNFW_FILE) $(HOME_LIB)/; \
cd $(HOME_LIB) && ln -sf $(notdir $(LIBKRUNFW_FILE)) libkrunfw.dylib; \
else \
echo "Warning: libkrunfw library not found in build directory"; \
fi
@if [ -n "$(LIBKRUN_FILE)" ]; then \
install -m 755 $(LIBKRUN_FILE) $(HOME_LIB)/; \
cd $(HOME_LIB) && ln -sf $(notdir $(LIBKRUN_FILE)) libkrun.dylib; \
else \
echo "Warning: libkrun library not found in build directory"; \
fi
@echo "Installation of $(if $(filter 1,$(DEBUG)),debug,release) build complete."
# -----------------------------------------------------------------------------
# Maintenance
# -----------------------------------------------------------------------------
clean:
rm -rf $(BUILD_DIR)
cd microsandbox-core && cargo clean && rm -rf build
uninstall:
rm -f $(HOME_BIN)/msb
rm -f $(HOME_BIN)/msbrun
rm -f $(HOME_BIN)/msbserver
rm -f $(HOME_BIN)/msr
rm -f $(HOME_BIN)/msx
rm -f $(HOME_BIN)/msi
rm -f $(HOME_LIB)/libkrunfw.dylib
rm -f $(HOME_LIB)/libkrun.dylib
@if [ -n "$(LIBKRUNFW_FILE)" ]; then \
rm -f $(HOME_LIB)/$(notdir $(LIBKRUNFW_FILE)); \
fi
@if [ -n "$(LIBKRUN_FILE)" ]; then \
rm -f $(HOME_LIB)/$(notdir $(LIBKRUN_FILE)); \
fi
build_libkrun:
./scripts/build_libkrun.sh --no-clean
# Catch-all target to allow example names and arguments
%:
@:
# -----------------------------------------------------------------------------
# Help Documentation
# -----------------------------------------------------------------------------
help:
@echo "Microsandbox Makefile Help"
@echo "======================"
@echo
@echo "Main Targets:"
@echo " make build - Build microsandbox components (release mode, no LTO)"
@echo " make install - Install binaries and libraries to ~/.local/{bin,lib}"
@echo " make uninstall - Remove all installed components"
@echo " make clean - Remove build artifacts"
@echo " make build_libkrun - Build libkrun dependency"
@echo
@echo "Build Modes:"
@echo " make build - Build in release mode (fast, no LTO)"
@echo " make DEBUG=1 build - Build in debug mode"
@echo " make DEBUG=1 install - Install debug build"
@echo
@echo "LTO Control (Link Time Optimization):"
@echo " make LTO=1 build - Enable LTO for smaller binary (slower build)"
@echo " make LTO=1 install - Install with LTO optimization"
@echo " make LTO=0 build - Disable LTO (default, faster build)"
@echo
@echo "Examples:"
@echo " # Standard release build (fast, no LTO)"
@echo " make build"
@echo
@echo " # Optimized build with LTO (slower build, smaller binary)"
@echo " make LTO=1 build"
@echo
@echo " # Debug build for development"
@echo " make DEBUG=1 build"
@echo
@echo " # Install standard release build"
@echo " make install"
@echo
@echo " # Install optimized build with LTO"
@echo " make LTO=1 install"
@echo
@echo "Note: LTO (Link Time Optimization) is now disabled by default for faster builds."
@echo " Enable it with LTO=1 for smaller, more optimized binaries."