Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219# bootcc build: M2-Planet -> blood-elf -> M1 -> hex2 (ELF amd64)## Uses the vendored M2-Planet + M2libc in vendor/.# Toolchain binaries (M2-Planet, blood-elf, M1, hex2) come from the# live-bootstrap bootstrap `out/` dir by default; override with DIR=/path.
# --- config ---------------------------------------------------------------ARCH ?= amd64DIR ?= $(HOME)/Sources/bootstrap/outM2 ?= $(DIR)/M2-PlanetBLOOD_ELF ?= $(DIR)/blood-elfM1 ?= $(DIR)/M1HEX2 ?= $(DIR)/hex2
# Per-arch constants (from M2-Planet test/env.inc.sh)ifeq ($(ARCH),amd64) WORDSIZE = --64 ENDIAN = --little-endian BASEADDR = 0x00600000 DEFS = $(M2ARCHDIR)/amd64_defs.M1 LIBCM1 = $(M2ARCHDIR)/libc-full.M1 ELFHEAD = $(M2ARCHDIR)/ELF-amd64-debug.hex2endif
M2ARCHDIR = vendor/M2libc/$(ARCH)# in-repo additions to the checksum-gated vendored defs (r8/r9 arg-spill forms)EXTRA_DEFS = $(CURDIR)/tools/amd64_defs_extra.M1
BUILD = build/$(ARCH)BIN = $(BUILD)/bootccEMIT_DIR ?= $(BUILD)/emit
.PHONY: all clean run check-checksums test emit elf
test: $(BIN) sh tests/run-tokenizer-tests.sh sh tests/run-pp-tests.sh sh tests/run-parse-tests.sh sh tests/run-codegen-tests.sh sh tests/run-libtcc-tests.sh sh tests/run-ltcc-so-tests.sh
all: $(BIN)
$(BUILD): mkdir -p $(BUILD)
# integrity gate: refuse to build if vendored sources were tamperedcheck-checksums: sha256sum -c vendor/SHA256SUMS >/dev/null
SRCS = vendor/M2libc/bootstrappable.c src/boot_sym.c src/boot_type.c src/bootcc.c src/boot_reader.c src/boot_pp.c src/libtcc.c src/boot_diag.c
$(BUILD)/bootcc.M1: $(SRCS) check-checksums | $(BUILD) $(M2) \ --expand-includes \ --debug \ --architecture $(ARCH) \ -I $(CURDIR)/vendor/M2libc \ -I $(CURDIR)/include \ $(SRCS) \ -o $@
$(BUILD)/bootcc-footer.M1: $(BUILD)/bootcc.M1 $(BLOOD_ELF) $(WORDSIZE) $(ENDIAN) \ -f $(BUILD)/bootcc.M1 \ --entry _start \ -o $@
$(BUILD)/bootcc.hex2: $(BUILD)/bootcc.M1 $(BUILD)/bootcc-footer.M1 $(M1) \ -f $(DEFS) \ -f $(LIBCM1) \ -f $(BUILD)/bootcc.M1 \ -f $(BUILD)/bootcc-footer.M1 \ $(ENDIAN) \ --architecture $(ARCH) \ -o $@
$(BIN): $(BUILD)/bootcc.hex2 $(HEX2) \ -f $(ELFHEAD) \ -f $(BUILD)/bootcc.hex2 \ $(ENDIAN) \ --architecture $(ARCH) \ --base-address $(BASEADDR) \ -o $@
run: $(BIN) $(BIN)
# ------------------------------------------------------------------# x86-64 codegen + ELF emission (the "static linker runner").## `src.c` is compiled to a standalone M1 assembly object by bootcc -e, then# blood-elf/M1/hex2 statically link that object (with boot's own freestanding# runtime pattern) into a runnable base-address ELF64 executable `elf`.## make elf SRC=tests/codegen/loop_sum.c -> build/amd64/emit/prog.PHONY: emit elf
emit: $(BIN) @test -n "$(SRC)" || (echo "usage: make emit SRC=prog.c [OUT=prog.M1]"; exit 1) @mkdir -p $(EMIT_DIR) $(BIN) -e -o $(if $(OUT),$(OUT),$(EMIT_DIR)/$(notdir $(basename $(SRC))).M1) $(SRC)
elf: $(BIN) @test -n "$(SRC)" || (echo "usage: make elf SRC=prog.c"; exit 1) @mkdir -p "$(EMIT_DIR)" $(BIN) -e -o $(EMIT_DIR)/prog.M1 $(SRC) $(BLOOD_ELF) $(WORDSIZE) $(ENDIAN) -f $(EMIT_DIR)/prog.M1 --entry _start -o $(EMIT_DIR)/prog-f.M1 $(M1) -f $(DEFS) -f $(EXTRA_DEFS) -f $(EMIT_DIR)/prog.M1 -f $(EMIT_DIR)/prog-f.M1 $(ENDIAN) --architecture $(ARCH) -o $(EMIT_DIR)/prog.hex2 $(HEX2) -f $(ELFHEAD) -f $(EMIT_DIR)/prog.hex2 $(ENDIAN) --architecture $(ARCH) --base-address $(BASEADDR) -o $(EMIT_DIR)/prog @chmod +x $(EMIT_DIR)/prog @echo "built executable: $(EMIT_DIR)/prog"
# ------------------------------------------------------------------# bootcc-as-a-library driver (the compiler-as-a-library front half).## The SAME engine sources bootcc's CLI links are compiled into a second binary# whose `main` lives in tests/libtcc/driver.c and goes through the include/# libtcc.h public API (tcc_new/tcc_set_output_type/tcc_compile_string/...)# implemented in src/libtcc.c. Running it compiles an embedded C *string* at# runtime and writes a freestanding M1 program (same as `bootcc -e` would), at# the path given on argv[1] (default bootcc_libtcc.M1). `make test` drives it# through tests/run-libtcc-tests.sh..PHONY: driverDRIVER_SRCS = vendor/M2libc/bootstrappable.c src/boot_sym.c src/boot_type.c src/libtcc.c src/boot_reader.c src/boot_pp.c src/boot_diag.c tests/libtcc/driver.cDRIVER = $(BUILD)/driver
$(BUILD)/driver.M1: $(DRIVER_SRCS) $(SRCS) check-checksums | $(BUILD) $(M2) \ --expand-includes \ --debug \ --architecture $(ARCH) \ -I $(CURDIR)/vendor/M2libc \ -I $(CURDIR)/include \ -I $(CURDIR)/src \ $(DRIVER_SRCS) \ -o $@
$(BUILD)/driver-footer.M1: $(BUILD)/driver.M1 $(BLOOD_ELF) $(WORDSIZE) $(ENDIAN) \ -f $(BUILD)/driver.M1 \ --entry _start \ -o $@
$(BUILD)/driver.hex2: $(BUILD)/driver.M1 $(BUILD)/driver-footer.M1 $(M1) \ -f $(DEFS) \ -f $(LIBCM1) \ -f $(BUILD)/driver.M1 \ -f $(BUILD)/driver-footer.M1 \ $(ENDIAN) \ --architecture $(ARCH) \ -o $@
$(DRIVER): $(BUILD)/driver.hex2 $(HEX2) \ -f $(ELFHEAD) \ -f $(BUILD)/driver.hex2 \ $(ENDIAN) \ --architecture $(ARCH) \ --base-address $(BASEADDR) \ -o $@
# Note: `make driver` builds the binary only; tests/run-libtcc-tests.sh runs# $(DRIVER) itself with explicit snippet + output-M1 paths.driver: $(DRIVER)
# ------------------------------------------------------------------# bootcc-as-a-library as a real `-ltcc`-ABI shared object (`libtcc.so`).## The SAME engine + libtcc.c sources that bootcc's CLI and the M2 driver link# are built by the host gcc into a genuine ELF shared library exporting the# include/libtcc.h subset (tcc_new/tcc_set_output_type/tcc_output_file/# tcc_compile_string/tcc_relocate/tcc_get_symbol/tcc_run + the bootcc-specific# tcc_image_info), so an unmodified TinyCC consumer binary that links `-ltcc`# (pass `-L build/amd64 -ltcc`) or dlopens `libtcc.so` gets the documented# libtcc front-half flow. This is the parity side the QUEUE tail has carried:# no system libtcc.so exists in-tree and the vendored M2 tree's own shared# build still fails, so - per the honest bound - the shared object is produced# by gcc from the SAME M2-subset engine sources (the very sources the m2==gcc# gate proves byte-identical), not by touching the vendored toolchain.## The consumers are built against the shared object only:# $(BUILD)/so_driver tests/libtcc/driver.c linked with `-ltcc`# $(BUILD)/dlopen_driver tests/libtcc/dlopen_driver.c dlopens "libtcc.so"# run by tests/run-ltcc-so-tests.sh (also a `make test` phase)..PHONY: so test-ltcc-soLIBTCC_SO = $(BUILD)/libtcc.soSO_SRCS = vendor/M2libc/bootstrappable.c src/boot_sym.c src/boot_type.c src/libtcc.c src/boot_reader.c src/boot_pp.c src/boot_diag.c
GCC_FLAGS = -D__va_list='void*' -D__builtin_va_list='void*' \ -Dsize_t='unsigned int' -Dwchar_t='int' \ -include $(CURDIR)/vendor/M2libc/gcc_req.h \ -std=gnu89 -w \ -I $(CURDIR)/vendor/M2libc -I $(CURDIR)/include -I $(CURDIR)/src
$(LIBTCC_SO): $(SO_SRCS) check-checksums | $(BUILD) gcc -o $@ -shared -fPIC $(GCC_FLAGS) $(SO_SRCS) @echo "built shared library: $@"
$(BUILD)/so_driver: tests/libtcc/driver.c $(LIBTCC_SO) | $(BUILD) gcc -o $@ $(GCC_FLAGS) tests/libtcc/driver.c \ -L $(CURDIR)/$(BUILD) -ltcc \ -Wl,-rpath,$(CURDIR)/$(BUILD)
$(BUILD)/dlopen_driver: tests/libtcc/dlopen_driver.c $(LIBTCC_SO) | $(BUILD) gcc -o $@ -I $(CURDIR)/include tests/libtcc/dlopen_driver.c -ldl
test-ltcc-so: $(BUILD)/so_driver $(BUILD)/dlopen_driver sh tests/run-ltcc-so-tests.sh
so: $(LIBTCC_SO)
clean: rm -rf build