Makefile (1773B)
1# 2# A Makefile that compiles all .c and .s files in "src" and "res" 3# subdirectories and places the output in a "obj" subdirectory 4# 5 6# If you move this project you can change the directory 7# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" 8GBDK_HOME = ../../../ 9 10LCC = $(GBDK_HOME)bin/lcc 11 12# You can set flags for LCC here 13# For example, you can uncomment the line below to turn on debug output 14# LCCFLAGS = -debug 15 16# You can set the name of the .gb ROM file here 17PROJECTNAME = Example 18 19SRCDIR = src 20OBJDIR = obj 21RESDIR = res 22BINS = $(OBJDIR)/$(PROJECTNAME).gb 23CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) 24ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) 25OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) 26 27all: prepare $(BINS) 28 29compile.bat: Makefile 30 @echo "REM Automatically generated from Makefile" > compile.bat 31 @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat 32 33# Compile .c files in "src/" to .o object files 34$(OBJDIR)/%.o: $(SRCDIR)/%.c 35 $(LCC) $(LCCFLAGS) -c -o $@ $< 36 37# Compile .c files in "res/" to .o object files 38$(OBJDIR)/%.o: $(RESDIR)/%.c 39 $(LCC) $(LCCFLAGS) -c -o $@ $< 40 41# Compile .s assembly files in "src/" to .o object files 42$(OBJDIR)/%.o: $(SRCDIR)/%.s 43 $(LCC) $(LCCFLAGS) -c -o $@ $< 44 45# If needed, compile .c files i n"src/" to .s assembly files 46# (not required if .c is compiled directly to .o) 47$(OBJDIR)/%.s: $(SRCDIR)/%.c 48 $(LCC) $(LCCFLAGS) -S -o $@ $< 49 50# Link the compiled object files into a .gb ROM file 51$(BINS): $(OBJS) 52 $(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS) 53 54prepare: 55 mkdir -p $(OBJDIR) 56 57clean: 58# rm -f *.gb *.ihx *.cdb *.adb *.noi *.map 59 rm -f $(OBJDIR)/*.* 60