-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (168 loc) · 7.51 KB
/
Copy pathMakefile
File metadata and controls
198 lines (168 loc) · 7.51 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
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 OpenBlink All Rights Reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Makefile for OpenBlink WebIDE
# Builds both mrbc (mruby bytecode compiler) and mrubyc (mruby/c VM) for WebAssembly
# ============================================================================
# mruby/c WebAssembly Module Build Configuration
# ============================================================================
# Directories
MRUBYC_DIR = vendor/mrubyc
MRUBYC_SRC_DIR = $(MRUBYC_DIR)/src
SRC_DIR = src
HAL_DIR = $(SRC_DIR)/lib/mrubyc
BUILD_DIR = public_html
# Build type: "release" (default) omits Emscripten runtime checks for speed
# and size; "debug" (WASM_BUILD=debug) enables assertions and stack checks.
WASM_BUILD ?= release
export WASM_BUILD
# Emscripten compiler
CC = emcc
RUBY ?= ruby
RUBY_BINDIR ?= $(dir $(shell command -v $(RUBY) 2>/dev/null))
# Compiler flags
MRUBYC_CFLAGS = -O3 \
-flto \
-Wall \
-I$(MRUBYC_SRC_DIR) \
-I$(HAL_DIR) \
-DMRBC_SCHEDULER_EXIT=1 \
-DMRBC_USE_FLOAT=2 \
-DMRBC_USE_MATH=1 \
-DMAX_VM_COUNT=5 \
-DMRBC_MEMORY_SIZE=131072
# Emscripten specific flags
MRUBYC_EMFLAGS = -s WASM=1 \
-s STRICT=1 \
-s EXPORTED_RUNTIME_METHODS='["ccall","HEAPU8","addFunction","removeFunction"]' \
-s EXPORTED_FUNCTIONS='["_mrbc_wasm_init","_mrbc_wasm_stop","_mrbc_wasm_run","_mrbc_wasm_print_statistics","_malloc","_free","_mrbc_wasm_get_class_object","_mrbc_wasm_define_class","_mrbc_wasm_define_method","_mrbc_wasm_get_int_arg","_mrbc_wasm_get_float_arg","_mrbc_wasm_is_numeric_arg","_mrbc_wasm_set_return_bool","_mrbc_wasm_set_return_nil","_mrbc_wasm_set_return_int","_mrbc_wasm_set_return_float","_mrbc_wasm_instance_new","_mrbc_wasm_set_global_const","_mrbc_wasm_free_instance"]' \
-s ALLOW_TABLE_GROWTH=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_HEAP=16777216 \
-s MAXIMUM_MEMORY=33554432 \
-s STACK_SIZE=1048576 \
-s MALLOC=dlmalloc \
-s ABORTING_MALLOC=1 \
-s ASYNCIFY=1 \
-s ASYNCIFY_STACK_SIZE=65536 \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME='createMrubycModule' \
-s FILESYSTEM=0 \
-s ENVIRONMENT='web' \
-s EXIT_RUNTIME=0 \
-s DYNAMIC_EXECUTION=0 \
-s TEXTDECODER=2 \
-s INCOMING_MODULE_JS_API='["locateFile","print","printErr"]' \
--no-entry
ifeq ($(WASM_BUILD),debug)
MRUBYC_EMFLAGS += -s ASSERTIONS=1 \
-s STACK_OVERFLOW_CHECK=1 \
-s CHECK_NULL_WRITES=1
endif
# mruby/c source files
MRUBYC_SRCS = $(MRUBYC_SRC_DIR)/alloc.c \
$(MRUBYC_SRC_DIR)/c_array.c \
$(MRUBYC_SRC_DIR)/c_hash.c \
$(MRUBYC_SRC_DIR)/c_math.c \
$(MRUBYC_SRC_DIR)/c_numeric.c \
$(MRUBYC_SRC_DIR)/c_object.c \
$(MRUBYC_SRC_DIR)/c_proc.c \
$(MRUBYC_SRC_DIR)/c_range.c \
$(MRUBYC_SRC_DIR)/c_string.c \
$(MRUBYC_SRC_DIR)/class.c \
$(MRUBYC_SRC_DIR)/console.c \
$(MRUBYC_SRC_DIR)/error.c \
$(MRUBYC_SRC_DIR)/global.c \
$(MRUBYC_SRC_DIR)/keyvalue.c \
$(MRUBYC_SRC_DIR)/load.c \
$(MRUBYC_SRC_DIR)/mrblib.c \
$(MRUBYC_SRC_DIR)/rrt0.c \
$(MRUBYC_SRC_DIR)/symbol.c \
$(MRUBYC_SRC_DIR)/value.c \
$(MRUBYC_SRC_DIR)/vm.c
# HAL source files
HAL_SRCS = $(HAL_DIR)/hal.c
# Main source files
MAIN_SRCS = $(SRC_DIR)/main.c
# All source files for mruby/c
SRCS = $(MRUBYC_SRCS) $(HAL_SRCS) $(MAIN_SRCS)
# Output files for mruby/c
MRUBYC_OUTPUT_DIR = $(BUILD_DIR)/mrubyc
MRUBYC_OUTPUT_JS = $(MRUBYC_OUTPUT_DIR)/mrubyc.js
MRUBYC_OUTPUT_WASM = $(MRUBYC_OUTPUT_DIR)/mrubyc.wasm
# ============================================================================
# Build Targets
# ============================================================================
# Default target: build both mrbc and mrubyc
all: mrbc mrubyc codemirror
check-emcc:
@command -v $(CC) >/dev/null 2>&1 || { echo "emcc was not found. Run: source vendor/emsdk/emsdk_env.sh" >&2; exit 1; }
check-ruby-autogen:
@PATH="$(RUBY_BINDIR):$(PATH)" ruby -rripper -e 'exit RUBY_VERSION.split(".").first.to_i >= 3 ? 0 : 1' || { echo "Ruby 3.x or newer with Ripper is required for mruby/c autogen. Set RUBY=/path/to/ruby." >&2; exit 1; }
# Build mrbc (mruby bytecode compiler)
mrbc: check-emcc
@echo "Building mrbc (mruby bytecode compiler)..."
cd vendor/mruby && PATH="$(RUBY_BINDIR):$(PATH)" rake MRUBY_CONFIG=../../mruby_build_config.rb
@echo "mrbc build complete. Output: public_html/mrbc/"
# Build mrubyc (mruby/c VM)
mrubyc: check-emcc mrubyc-autogen $(MRUBYC_OUTPUT_DIR) $(MRUBYC_OUTPUT_JS)
@echo "mrubyc build complete. Output: public_html/mrubyc/"
# Build CodeMirror and app bundles
codemirror:
@echo "Building CodeMirror and app bundles..."
npm run build
@echo "Bundle build complete. Output: public_html/codemirror/, public_html/js/app.js"
# Generate mrubyc auto-generated files
mrubyc-autogen: check-ruby-autogen
@echo "Generating mrubyc auto-generated files..."
PATH="$(RUBY_BINDIR):$(PATH)" $(MAKE) -C vendor/mrubyc autogen
@echo "mrubyc auto-generated files complete."
# Create build directory
$(MRUBYC_OUTPUT_DIR):
mkdir -p $(MRUBYC_OUTPUT_DIR)
# Build WebAssembly module
$(MRUBYC_OUTPUT_JS): $(SRCS) Makefile | $(MRUBYC_OUTPUT_DIR)
$(CC) $(MRUBYC_CFLAGS) $(MRUBYC_EMFLAGS) $(SRCS) -o $(MRUBYC_OUTPUT_JS)
# Clean build artifacts
clean: clean-mrbc clean-mrubyc clean-codemirror
clean-all: clean
@echo "Cleaning all mrubyc artifacts including auto-generated files..."
cd vendor/mrubyc && make clean
clean-mrbc:
@echo "Cleaning mrbc build artifacts..."
cd vendor/mruby && make clean || true
rm -rf build/mrbc
clean-mrubyc:
@echo "Cleaning mrubyc build artifacts..."
rm -f $(MRUBYC_OUTPUT_JS) $(MRUBYC_OUTPUT_WASM)
cd vendor/mrubyc/src && rm -f _autogen_*.h
clean-codemirror:
@echo "Cleaning bundle build artifacts..."
rm -rf public_html/codemirror
rm -f public_html/js/app.js public_html/js/compiler-worker.js
# Rebuild
rebuild: clean-all all
# Help
help:
@echo "OpenBlink WebIDE Build System"
@echo ""
@echo "Targets:"
@echo " all - Build both mrbc and mrubyc (default)"
@echo " check-emcc - Verify emcc is available"
@echo " check-ruby-autogen - Verify Ruby can run mruby/c generators"
@echo " mrbc - Build mrbc (mruby bytecode compiler)"
@echo " mrubyc - Build mrubyc (mruby/c VM for simulator)"
@echo " codemirror - Build CodeMirror and app bundles from npm"
@echo " mrubyc-autogen - Generate mrubyc auto-generated files"
@echo " clean - Remove all build artifacts"
@echo " clean-mrbc - Remove mrbc build artifacts"
@echo " clean-mrubyc - Remove mrubyc build artifacts"
@echo " clean-codemirror - Remove CodeMirror build artifacts"
@echo " clean-all - Remove all build artifacts including auto-generated files"
@echo " rebuild - Clean and rebuild all"
@echo " help - Show this help message"
@echo ""
@echo "Before building, make sure to activate Emscripten:"
@echo " source vendor/emsdk/emsdk_env.sh"
.PHONY: all check-emcc check-ruby-autogen mrbc mrubyc codemirror mrubyc-autogen clean clean-mrbc clean-mrubyc clean-codemirror clean-all rebuild help