Makefile (3086B)
1SHELL := /bin/bash 2 3# If you move this project you can change the directory 4# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" 5GBDK_HOME = ../../../ 6LCC = $(GBDK_HOME)bin/lcc 7 8# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets) 9# They can also be built/cleaned individually: "make gg" and "make gg-clean" 10# Possible are: gb gbc pocket megaduck sms gg 11TARGETS=gb pocket megaduck sms gg 12 13# Configure platform specific LCC flags here: 14LCCFLAGS_gb = -Wl-yt0x1B # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) 15LCCFLAGS_pocket = -Wl-yt0x1B # Usually the same as required for .gb 16LCCFLAGS_duck = -Wl-yt0x1B # Usually the same as required for .gb 17LCCFLAGS_gbc = -Wl-yt0x1B -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) 18LCCFLAGS_sms = 19LCCFLAGS_gg = 20 21LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags 22 23LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -autobank -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags 24# LCCFLAGS += -debug # Uncomment to enable debug output 25# LCCFLAGS += -v # Uncomment for lcc verbose output 26 27# You can set the name of the ROM file here 28PROJECTNAME = banks 29 30# EXT?=gb # Only sets extension to default (game boy .gb) if not populated 31SRCDIR = src 32OBJDIR = obj/$(EXT) 33RESDIR = res 34BINDIR = build/$(EXT) 35MKDIRS = $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation 36 37BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) 38CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) 39ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) 40OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) 41 42# Builds all targets sequentially 43all: $(TARGETS) 44 45# Compile .c files in "src/" to .o object files 46$(OBJDIR)/%.o: $(SRCDIR)/%.c 47 $(eval BOFLAG = $(shell echo "$<" | sed -n 's/.*\.bo\([0-9]\+\).*/\-Wf-bo\1/p')) 48 $(eval BAFLAG = $(shell echo "$<" | sed -n 's/.*\.ba\([0-9]\+\).*/\-Wf-ba\1/p')) 49 $(LCC) -v $(CFLAGS) $(BOFLAG) $(BAFLAG) -c -o $@ $< 50 51# Compile .c files in "res/" to .o object files 52$(OBJDIR)/%.o: $(RESDIR)/%.c 53 $(LCC) $(CFLAGS) -c -o $@ $< 54 55# Compile .s assembly files in "src/" to .o object files 56$(OBJDIR)/%.o: $(SRCDIR)/%.s 57 $(LCC) $(CFLAGS) -c -o $@ $< 58 59# If needed, compile .c files i n"src/" to .s assembly files 60# (not required if .c is compiled directly to .o) 61$(OBJDIR)/%.s: $(SRCDIR)/%.c 62 $(LCC) $(CFLAGS) -S -o $@ $< 63 64# Link the compiled object files into a .gb ROM file 65$(BINS): $(OBJS) 66 $(LCC) $(LCCFLAGS) $(CFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(OBJS) 67 68clean: 69 @echo Cleaning 70 @for target in $(TARGETS); do \ 71 $(MAKE) $$target-clean; \ 72 done 73 74# Include available build targets 75include Makefile.targets 76 77 78# create necessary directories after Makefile is parsed but before build 79# info prevents the command from being pasted into the makefile 80ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target 81$(info $(shell mkdir -p $(MKDIRS))) 82endif