build the programs the way the modules are built

Each program had its own recipe: a hand-written link list, a cd into
tests/ so its includes would not find the modules' namesakes, and a
renamed output so csc would not overwrite the module sexc.o. Read off
their imports like the modules', and compiled to an object named after
their source, they share one rule; include-relative ends the cd.
This commit is contained in:
2026-10-15 15:18:17 +03:00
parent 20151ece1b
commit 76a521b4b9
3 changed files with 121 additions and 80 deletions

View File

@@ -36,47 +36,38 @@ all: sexc
include eggs.mk
# MODULES, and a line for each naming the modules it imports, read off
# the import forms
# Each program, and the source it is built from
PROGRAMS = sexc=main.scm sextest=tools/sextest/sextest.scm sex-tests=tests/run.scm
# MODULES, the programs' names and objects, and a line for each naming
# what it imports, read off the import forms
include modules.mk
OBJ = $(MODULES:%=%.o)
sexc: $(OBJ) main.scm
$(CHICKEN_C) $(CSC_FLAGS) main.scm -o sexc-tmp -link sexc
# otherwise csc hangs, probably because it tries to compile to sexc.o first
mv sexc-tmp sexc
modules.mk: $(SOURCES) tools/module-deps.scm dependencies.txt
$(CSI) -s tools/module-deps.scm $(PROGRAMS) > $@.tmp
mv $@.tmp $@
#------------------------------------------------------------------
modules.mk: main.scm $(MODULES:%=%.scm) tools/module-deps.scm
$(CSI) -s tools/module-deps.scm main.scm > $@.tmp
mv $@.tmp $@
# Everything is linked with the modules among its prerequisites
LINKS = $(addprefix -link ,$(basename $(filter-out $<,$(filter %.o,$^))))
# A module is one file that declares its own exports, made a module by
# -module. It is linked with the modules among its prerequisites.
comma := ,
empty :=
space := $(empty) $(empty)
LINKS = $(subst $(space),$(comma),$(basename $(filter %.o,$^)))
# -module, except the vendored sex-fmt-c, a (module ...) form of its own
MODULE = -module $*
sex-fmt-c.o: MODULE =
%.o: %.scm
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< -module $* -o $@ -unit $* $(if $(LINKS),-link $(LINKS))
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< $(MODULE) -o $@ -unit $* $(LINKS)
# Vendored, and a (module ...) form of its own
sex-fmt-c.o: sex-fmt-c.scm
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) $< -o $@ -unit sex-fmt-c
# A program's object is named after its source: csc names its own after
# -o, and sexc.o is the module's
$(PROGRAM_OBJ): %.o: %.scm
$(CHICKEN_C) $(CSC_FLAGS) -c $< -o $@
# Both link the modules built here, whose import libraries they find
# with the root on the repository path. The tests are built in their
# own directory, where their includes would otherwise find the modules'
# namesakes
WITH_ROOT_REPO = CHICKEN_REPOSITORY_PATH=$(CURDIR):$(CHICKEN_REPOSITORY_PATH)
sex-tests: $(wildcard tests/*.scm) $(OBJ)
cd tests && $(WITH_ROOT_REPO) $(CHICKEN_C) $(CSC_FLAGS) run.scm -o ../$@ -link sexc
sextest: tools/sextest/sextest.scm reader.o utils.o
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@ -link reader,utils
$(PROGRAM_NAMES):
$(CHICKEN_C) $(CSC_FLAGS) $< -o $@ $(LINKS)
# A program directly in tests/sex-programs is a test; lib/ holds what
# they import
@@ -104,9 +95,9 @@ uninstall:
-rmdir $(DESTDIR)$(sexlibdir)
clean:
rm -f $(OBJ) main.o modules.mk
rm -f $(OBJ) $(PROGRAM_OBJ) modules.mk
rm -f *.import.scm
rm -f *.link
rm -f *.link $(PROGRAM_OBJ:.o=.link)
rm -f sexc sex-tests sextest
.PHONY: all check run-tests install install-strip installdirs uninstall clean