-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
107 lines (88 loc) · 3.3 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
96
97
98
99
100
101
102
103
104
105
106
107
#
# A Makefile that compiles all .c and .s files in "src" and "res"
# subdirectories and places the output in a "obj" subdirectory
#
# If you move this project you can change the directory
# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/"
GBDK_HOME = /opt/gbdk/
LCC = $(GBDK_HOME)bin/lcc
TARGETS = gb gb_tpp1 pocket gg
EXT_gb = gb
EXT_gb_tpp1 = gb
EXT_pocket = pocket
EXT_gg = gg
PLATDIR_gb = platform_gb
PLATDIR_gb_tpp1 = platform_gb
PLATDIR_pocket = platform_gb
PLATDIR_gg = platform_gg
LCCFLAGS_gb = -Wm-yt27 -DSM83 -D__GB__
LCCFLAGS_gb_tpp1 = -Wm-yt27 -DSM83 -D__GB__ -D__TPP1__
LCCFLAGS_pocket = -Wm-yt27 -DSM83 -D__POCKET__
LCCFLAGS_gg = -DZ80 -D__GG__
# You can set flags for LCC here
# For example, you can uncomment the line below to turn on debug output
LCCFLAGS = -debug -Wm-ya16 -Wm-yo4
# optimizations
LCCFLAGS += -Wf--max-allocs-per-node50000 -Wf--opt-code-speed
# profiling
# LCCFLAGS += -DPROFILING -Wf--profile
# ASM
LCCFLAGS += -Wa-I$(GBDK_HOME)lib/sm83/ -Wa-l
# GBC
LCCFLAGS += -Wm-yc -Wm-ys -Wm-yngbzoo
EXT = $(EXT_$(TARGET))
PLATDIR = $(PLATDIR_$(TARGET))
LCCFLAGS += $(LCCFLAGS_$(TARGET)) -I$(SRCDIR)/$(PLATDIR) -I$(SRCDIR)
# You can set the name of the .gb ROM file here
PROJECTNAME = gbzoo
SRCDIR = src
OBJDIR = obj/$(TARGET)
RESDIR = res
MKDIRS = $(OBJDIR)
BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT)
CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) \
$(foreach dir,$(SRCDIR)/elements,$(notdir $(wildcard $(dir)/*.c))) \
$(foreach dir,$(SRCDIR)/$(PLATDIR),$(notdir $(wildcard $(dir)/*.c))) \
$(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c)))
ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) \
$(foreach dir,$(SRCDIR)/elements,$(notdir $(wildcard $(dir)/*.s))) \
$(foreach dir,$(SRCDIR)/$(PLATDIR),$(notdir $(wildcard $(dir)/*.s)))
OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o)
all: $(TARGETS)
make.bat: Makefile
@echo "REM Automatically generated from Makefile" > make.bat
@make -sn | sed y/\\//\\\\/ | grep -v make >> make.bat
# Compile .c files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(LCC) $(LCCFLAGS) -c -o $@ $<
# Compile .c files in "src/elements/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/elements/%.c
$(LCC) $(LCCFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/$(PLATDIR)/%.c
$(LCC) $(LCCFLAGS) -c -o $@ $<
# Compile .c files in "res/" to .o object files
$(OBJDIR)/%.o: $(RESDIR)/%.c
$(LCC) $(LCCFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.s
$(LCC) $(LCCFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/$(PLATDIR)/%.s
$(LCC) $(LCCFLAGS) -c -o $@ $<
# If needed, compile .c files i n"src/" to .s assembly files
# (not required if .c is compiled directly to .o)
$(OBJDIR)/%.s: $(SRCDIR)/%.c
$(LCC) $(LCCFLAGS) -S -o $@ $<
# Link the compiled object files into a .gb ROM file
$(BINS): $(OBJS)
$(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS)
clean:
@echo Cleaning
@for target in $(TARGETS); do \
$(MAKE) $$target-clean; \
done
include Makefile.targets
# create necessary directories after Makefile is parsed but before build
# info prevents the command from being pasted into the makefile
ifneq ($(strip $(TARGET)),) # Only make the directories if EXT has been set by a target
$(info $(shell mkdir -p $(MKDIRS)))
endif