Files
breeze/mk/native-objects.mk
waoziandClaude Opus 5.5 3432e0dc43 Regenerate on define changes and write native objects whole
Two stale-build traps cost UI test runs:

- The generated C did not depend on its defines, so building with
  KRYON_TEST_DRIVER after a plain build kept the old C and the UI tests
  stopped with "this build has no test driver". The defines are now
  recorded in build/kryon/generated-defines.txt, rewritten only when they
  change, and the generation depends on it.
- A compile killed part way, as the memory guard does, left an empty
  object newer than its source; make then skipped it and the link failed
  on undefined symbols. Each object is now compiled to a .part file and
  moved into place.

Local tests: make native with and without KRYON_TEST_DRIVER regenerates
once and a repeat build regenerates nothing; desktop-window-test passes
on a private Xvfb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 15:52:45 -03:00

36 lines
1.3 KiB
Makefile

# Compiles every native C source to its own object so a rebuild recompiles
# only sources whose code, headers, or flags changed, and runs in parallel.
# The main Makefile writes $(OBJ_DIR)/inputs.mk (NATIVE_SOURCES and
# NATIVE_CFLAGS) and runs this file with -f; objects mirror each source's
# absolute path under $(OBJ_DIR), and the link reads $(OBJ_DIR)/objects.rsp.
OBJ_DIR ?= build/obj/native
include $(OBJ_DIR)/inputs.mk
NATIVE_OBJECTS := $(foreach source,$(NATIVE_SOURCES),$(OBJ_DIR)$(abspath $(source:.c=.o)))
FLAGS_STAMP := $(OBJ_DIR)/cflags.txt
.PHONY: all
all: $(NATIVE_OBJECTS)
$(file >$(OBJ_DIR)/objects.rsp,$(NATIVE_OBJECTS))
# Rewrite the flags record only when the flags change, so a flag change
# recompiles everything and an unchanged build recompiles nothing.
$(FLAGS_STAMP): FORCE
@mkdir -p $(dir $@)
@printf '%s\n' '$(subst ','"'"',$(NATIVE_CFLAGS))' > $@.new
@if cmp -s $@.new $@; then rm -f $@.new; else mv $@.new $@; fi
# Each object is written beside its final name and moved into place, so a
# compile that is killed part way leaves no empty object that looks current.
$(OBJ_DIR)/%.o: /%.c $(FLAGS_STAMP) mk/native-objects.mk
@mkdir -p $(dir $@)
@printf ' CC %s\n' '$<'
@$(CC) $(NATIVE_CFLAGS) -MMD -MP -MF '$(@:.o=.d)' -MT '$@' -c '$<' -o '[email protected]'
@mv -f '[email protected]' '$@'
.PHONY: FORCE
FORCE:
-include $(NATIVE_OBJECTS:.o=.d)