Files
Sprinter-SDCC/libbgi/Makefile
T
snark13 786836e2e7 libc+libbgi: fast-версии собираются с --max-allocs-per-node 100000
Идея из mdview2 (memory/mdview2_size_budget): большее время компиляции
покупает более агрессивную регистровую аллокацию SDCC.  Применено к
fast-вариантам обеих библиотек (sprinter.lib, bgi256.lib); safe-версии
остаются на дефолте — быстрая пересборка для отладки.

Замер (47 программ, роста нет): solidt -507, filetest -506, fbench
-461, bgi_img -339, bgitest -316, gfx_dbuf -316, fdmax -278, errno
-179, gfx_demo -173, accfill -143, ptime -128, stattest -117, cbl* -53,
остальные до -28.  Время сборки: libc fast 17с -> 68с, libbgi 43с
(обе) — терпимо.  MAME: filetest + bgitest зелёные.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 22:24:50 +03:00

100 lines
4.2 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Build lib/bgi256.lib + lib/bgi256_safe.lib — Sprinter BGI graphics driver (320×256×256).
#
# libbgi/ — самостоятельная графическая библиотека, отделённая от libc.
# Две driver-библиотеки собираются из одной исходной базы:
# bgi256.lib = common/*.rel + bgi256/*.rel (fast, без bounds-check)
# bgi256_safe.lib = common/*.rel + bgi256/*.rel (safe, с bounds-check)
# common/ — mode-agnostic: .rel компилируется в ОБЕ версии параллельно.
# bgi256/ — mode-specific leaf'ы.
#
# Каждый .c — отдельный .rel в архиве (1 публичная функция = 1 модуль);
# линкер тянет только нужные .rel → DCE на уровне файлов.
#
# make build lib/bgi256.lib + lib/bgi256_safe.lib (обе)
# make fast build только lib/bgi256.lib
# make safe build только lib/bgi256_safe.lib
# make BUILD_SAFE=1 build только lib/bgi256_safe.lib (legacy)
# make clean remove build/ + обе библиотеки
#
PROJ_ROOT := $(abspath $(CURDIR)/..)
SDCC_BIN := $(PROJ_ROOT)/third_party/sdcc/bin
SDCC := $(SDCC_BIN)/sdcc
SDAR := $(SDCC_BIN)/sdar
INC := -I$(CURDIR)/include -I$(PROJ_ROOT)/libc/include
BUILD := $(CURDIR)/build
COMMON_C := $(wildcard $(CURDIR)/common/*.c)
BGI256_C := $(wildcard $(CURDIR)/bgi256/*.c)
COMMON_FAST_RELS := $(patsubst $(CURDIR)/common/%.c,$(BUILD)/fast/common/%.rel,$(COMMON_C))
BGI256_FAST_RELS := $(patsubst $(CURDIR)/bgi256/%.c,$(BUILD)/fast/bgi256/%.rel,$(BGI256_C))
COMMON_SAFE_RELS := $(patsubst $(CURDIR)/common/%.c,$(BUILD)/safe/common/%.rel,$(COMMON_C))
BGI256_SAFE_RELS := $(patsubst $(CURDIR)/bgi256/%.c,$(BUILD)/safe/bgi256/%.rel,$(BGI256_C))
LIB_DIR := $(PROJ_ROOT)/lib
LIB_FAST := $(LIB_DIR)/bgi256.lib
LIB_SAFE := $(LIB_DIR)/bgi256_safe.lib
all: fast safe
fast: $(LIB_FAST)
safe: $(LIB_SAFE)
# --- Fast version: -DGFX_NOCHECK (guard'и выключены) ---
$(BUILD)/fast/common/%.rel: $(CURDIR)/common/%.c
@mkdir -p $(dir $@)
$(SDCC) -mz80 --no-std-crt0 --std-c99 --opt-code-size -DGFX_NOCHECK --max-allocs-per-node 100000 $(INC) -c -o $@ $<
$(BUILD)/fast/bgi256/%.rel: $(CURDIR)/bgi256/%.c
@mkdir -p $(dir $@)
$(SDCC) -mz80 --no-std-crt0 --std-c99 --opt-code-size -DGFX_NOCHECK --max-allocs-per-node 100000 $(INC) -c -o $@ $<
# --- Safe version: guard'и включены (по умолчанию) ---
$(BUILD)/safe/common/%.rel: $(CURDIR)/common/%.c
@mkdir -p $(dir $@)
$(SDCC) -mz80 --no-std-crt0 --std-c99 --opt-code-size $(INC) -c -o $@ $<
$(BUILD)/safe/bgi256/%.rel: $(CURDIR)/bgi256/%.c
@mkdir -p $(dir $@)
$(SDCC) -mz80 --no-std-crt0 --std-c99 --opt-code-size $(INC) -c -o $@ $<
# --- Archive: fast ---
$(BUILD)/fast/.have: $(COMMON_FAST_RELS) $(BGI256_FAST_RELS)
@find $(BUILD)/fast -name '*.rel' -print | sort > $@ 2>/dev/null || true
@printf '%s\n' $(COMMON_FAST_RELS) $(BGI256_FAST_RELS) | sort > $(BUILD)/fast/.want
@comm -23 $(BUILD)/fast/.have $(BUILD)/fast/.want | while read f; do \
echo " stale: $$f — rm"; \
rm -f "$$f" "$${f%.rel}.asm" "$${f%.rel}.lst" "$${f%.rel}.sym"; \
done
$(LIB_FAST): $(COMMON_FAST_RELS) $(BGI256_FAST_RELS) $(BUILD)/fast/.have
rm -f $@
$(SDAR) -rcs $@ $(COMMON_FAST_RELS) $(BGI256_FAST_RELS)
@echo " Built $@ with $$(( $$(echo "$(words $(COMMON_FAST_RELS))") + $$(echo "$(words $(BGI256_FAST_RELS))") )) modules."
# --- Archive: safe ---
$(BUILD)/safe/.have: $(COMMON_SAFE_RELS) $(BGI256_SAFE_RELS)
@find $(BUILD)/safe -name '*.rel' -print | sort > $@ 2>/dev/null || true
@printf '%s\n' $(COMMON_SAFE_RELS) $(BGI256_SAFE_RELS) | sort > $(BUILD)/safe/.want
@comm -23 $(BUILD)/safe/.have $(BUILD)/safe/.want | while read f; do \
echo " stale: $$f — rm"; \
rm -f "$$f" "$${f%.rel}.asm" "$${f%.rel}.lst" "$${f%.rel}.sym"; \
done
$(LIB_SAFE): $(COMMON_SAFE_RELS) $(BGI256_SAFE_RELS) $(BUILD)/safe/.have
rm -f $@
$(SDAR) -rcs $@ $(COMMON_SAFE_RELS) $(BGI256_SAFE_RELS)
@echo " Built $@ with $$(( $$(echo "$(words $(COMMON_SAFE_RELS))") + $$(echo "$(words $(BGI256_SAFE_RELS))") )) modules."
clean:
rm -rf $(BUILD) $(LIB_FAST) $(LIB_SAFE)
.PHONY: all fast safe clean