Makefile (3986B)
1# If you move this project you can change the directory 2# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" 3GBDK_HOME = ../../../ 4LCC = $(GBDK_HOME)bin/lcc 5PNG2ASSET = $(GBDK_HOME)/bin/png2asset 6 7# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets) 8# They can also be built/cleaned individually: "make gg" and "make gg-clean" 9# Possible are: gb gbc pocket megaduck sms gg 10TARGETS=gb pocket megaduck sms gg 11 12# Configure platform specific LCC flags here: 13LCCFLAGS_gb = -Wl-yt0x1B # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) 14LCCFLAGS_pocket = -Wl-yt0x1B # Usually the same as required for .gb 15LCCFLAGS_duck = -Wl-yt0x1B # Usually the same as required for .gb 16LCCFLAGS_gbc = -Wl-yt0x1B -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) 17LCCFLAGS_sms = 18LCCFLAGS_gg = 19 20LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags 21 22LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -autobank -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags 23# LCCFLAGS += -debug # Uncomment to enable debug output 24# LCCFLAGS += -v # Uncomment for lcc verbose output 25 26# Add directory where platform specific meta tile sprites get converted into (obj/<platform ext>/src) 27# So they can be included with "#include <res/somefile.h>" 28CFLAGS += -I$(OBJDIR) 29 30# You can set the name of the ROM file here 31PROJECTNAME = metasprites 32 33SRCDIR = src 34OBJDIR = obj/$(EXT) 35RESOBJSRC = obj/$(EXT)/res 36RESDIR = res 37BINDIR = build/$(EXT) 38MKDIRS = $(OBJDIR) $(BINDIR) $(RESOBJSRC) # See bottom of Makefile for directory auto-creation 39 40BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) 41# For png2asset: converting metasprite source pngs -> .c -> .o 42METAPNGS = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.png))) 43METASRCS = $(METAPNGS:%.png=$(RESOBJSRC)/%.c) 44METAOBJS = $(METASRCS:$(RESOBJSRC)/%.c=$(OBJDIR)/%.o) 45 46CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) 47ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) 48OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) 49 50 51# Builds all targets sequentially 52all: $(TARGETS) 53 54# Use png2asset to convert the png into C formatted metasprite data 55# -sh 48 : Sets sprite height to 48 (width remains automatic) 56# -spr8x16 : Use 8x16 hardware sprites 57# -c ... : Set C output file 58# Convert metasprite .pngs in res/ -> .c files in obj/<platform ext>/src/ 59$(RESOBJSRC)/%.c: $(RESDIR)/%.png 60 $(PNG2ASSET) $< -sh 48 -spr8x16 -noflip -c $@ 61 62# Compile the Metasprite pngs that were converted to .c files 63# .c files in obj/<platform ext>/src/ -> .o files in obj/ 64$(OBJDIR)/%.o: $(RESOBJSRC)/%.c 65 $(LCC) $(CFLAGS) -c -o $@ $< 66 67# Compile .c files in "src/" to .o object files 68$(OBJDIR)/%.o: $(SRCDIR)/%.c 69 $(LCC) $(CFLAGS) -c -o $@ $< 70 71# Compile .c files in "res/" to .o object files 72$(OBJDIR)/%.o: $(RESDIR)/%.c 73 $(LCC) $(CFLAGS) -c -o $@ $< 74 75# Compile .s assembly files in "src/" to .o object files 76$(OBJDIR)/%.o: $(SRCDIR)/%.s 77 $(LCC) $(CFLAGS) -c -o $@ $< 78 79# If needed, compile .c files i n"src/" to .s assembly files 80# (not required if .c is compiled directly to .o) 81$(OBJDIR)/%.s: $(SRCDIR)/%.c 82 $(LCC) $(CFLAGS) -S -o $@ $< 83 84# Convert and build MetaSprites first so they're available when compiling the main sources 85$(OBJS): $(METAOBJS) 86 87# Link the compiled object files into a .gb ROM file 88$(BINS): $(OBJS) 89 $(LCC) $(LCCFLAGS) $(CFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(METAOBJS) $(OBJS) 90 91clean: 92 @echo Cleaning 93 @for target in $(TARGETS); do \ 94 $(MAKE) $$target-clean; \ 95 done 96 97# Include available build targets 98include Makefile.targets 99 100 101# create necessary directories after Makefile is parsed but before build 102# info prevents the command from being pasted into the makefile 103ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target 104$(info $(shell mkdir -p $(MKDIRS))) 105endif