-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
95 lines (69 loc) · 2.42 KB
/
Makefile
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
BUILDDIR := build
PROGRAM := $(BUILDDIR)/chip8.prg
SOURCES := source
INCLUDES := include
LIBS :=
OBJDIR := obj
DEBUGDIR := $(BUILDDIR)
DISTDIR := dist
DISTPRG := $(DISTDIR)/chip8.prg
DISK := $(DISTDIR)/chip8.d64
LABELSFILE := $(BUILDDIR)/chip8.labels
LINKCFG := cfg/c64-linker.cfg
ASFLAGS := -t c64
LDFLAGS = -C$(LINKCFG) \
-m $(DEBUGDIR)/$(notdir $(basename $@)).map \
-Ln $(DEBUGDIR)/$(notdir $(basename $@)).labels -vm
VICE := x64
VICEDEBUGFLAGS := -moncommands $(LABELSFILE)
################################################################################
LD := ld65
AS := ca65
MKDIR := mkdir
RM := rm -f
RMDIR := rm -rf
################################################################################
ofiles :=
sfiles := $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s))
incfiles := $(foreach dir,$(INCLUDES),$(wildcard $(dir)/*.s))
extra_includes := $(foreach i, $(INCLUDES), -I $i)
define depend
my_obj := $$(addprefix $$(OBJDIR)/, $$(addsuffix .o, $$(notdir $$(basename $(1)))))
ofiles += $$(my_obj)
$$(my_obj): $(1) $(incfiles)
$$(AS) -g -l $$(addprefix $$(OBJDIR)/, $$(addsuffix .lst, $$(notdir $$(basename $(1))))) -o $$@ $$(ASFLAGS) $(extra_includes) $$<
endef
################################################################################
.SUFFIXES:
.PHONY: all disk release run run-ntsc run-pal debug debug-pal debug-ntsc clean
all: $(PROGRAM)
$(foreach file,$(sfiles),$(eval $(call depend,$(file))))
$(OBJDIR):
[ -d $@ ] || mkdir -p $@
$(BUILDDIR):
[ -d $@ ] || mkdir -p $@
$(PROGRAM): $(BUILDDIR) $(OBJDIR) $(ofiles)
$(LD) $(LDFLAGS) $(ofiles) $(LIBS) -o $@
$(DISTDIR):
[ -d $@ ] || mkdir -p $@
$(DISTPRG): $(DISTDIR) $(PROGRAM)
exomizer sfx basic $(PROGRAM) -o $(DISTPRG)
disk: $(DISTPRG)
c1541 -format chip8,ks d64 $(DISK) -attach $(DISK) -write $(DISTPRG) chip8
release: $(DISTPRG) disk
run: $(PROGRAM)
$(VICE) $(VICEFLAGS) $(PROGRAM)
run-ntsc: $(PROGRAM)
$(VICE) -ntsc $(VICEFLAGS) $(PROGRAM)
run-pal: $(PROGRAM)
$(VICE) -pal $(VICEFLAGS) $(PROGRAM)
debug: $(PROGRAM)
$(VICE) $(VICEFLAGS) $(VICEDEBUGFLAGS) $(PROGRAM)
debug-ntsc: $(PROGRAM)
$(VICE) -ntsc $(VICEFLAGS) $(VICEDEBUGFLAGS) $(PROGRAM)
debug-pal: $(PROGRAM)
$(VICE) -pal $(VICEFLAGS) $(VICEDEBUGFLAGS) $(PROGRAM)
clean:
$(RM) $(OBJDIR)/*
$(RM) $(BUILDDIR)/*
$(RM) $(DISTDIR)/*