aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: f6ce2bb7101cb0e2a4c860b427d9c57f53ce4605 (plain)
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
.DEFAULT_GOAL := bin/game

# Get all .scm modules (excluding game.scm)
MODULE_FILES := $(wildcard src/*.scm)
MODULE_FILES := $(filter-out src/game.scm, $(MODULE_FILES))
MODULE_NAMES := $(patsubst src/%.scm,%,$(MODULE_FILES))
OBJECT_FILES := $(patsubst %,bin/%.o,$(MODULE_NAMES))

# Main target - compile game.o with -uses flags, then link all .o files
bin/game: bin/game.o $(OBJECT_FILES)
	csc bin/game.o $(OBJECT_FILES) -o bin/game

# Compile game.scm to game.o (declare that it uses the modules)
bin/game.o: src/game.scm $(OBJECT_FILES) | bin
	csc -c src/game.scm -o bin/game.o -I bin $(patsubst %,-uses %,$(MODULE_NAMES))

bin:
	@mkdir -p $@

# Pattern rule: compile each module as a library unit (unique C toplevel name)
# so linking multiple .o files doesn't cause "multiple definition of C_toplevel".
bin/%.o bin/%.import.scm: src/%.scm | bin
	csc -c -J -unit $* src/$*.scm -o bin/$*.o
	mv $*.import.scm bin/
.PHONY: clean
clean:
	rm -rf bin
	rm -f *.import.scm game
	rm -f *.so