##################################################
# Makefile for the Blodrunner GBA demo mini-game
#
# written by Doug Lanford, opus@opusgames.com
# for more info, go to www.opusgames.com
#
# This file is provided as freeware
###################################################

PROJECTNAME = blod

all : blod.bin

# directories to find source files
BOOTDIR = boot
ASMDIR = asm
SRCDIR = src

# compiler/linker flags
BOOTFLAGS = -mthumb-interwork
ASMFLAGS = -mthumb-interwork
CFLAGS = -c -Isrc -O0 -Wall -mthumb-interwork
LDFLAGS = -Wall -mthumb-interwork -nostartfiles -Wl,--script=lnkscript

# BOOT source files
SRCS_BOOT = \
	crt0.s

# ASM source files
SRCS_ASM = \
	mathAsm.s

# C source files
SRCS_C = \
   main.c \
   game.c \
   object.c \
   interrupt.c \
   vblank.c \
   eramHeap.c \
   background.c \
   sprite.c \
   buttons.c \
   math.c \
   world.c \
   collide.c \
   dude.c \
   bullet.c \
   powerup.c \
   text.c \
   dat.c \
   debug.c \

# convert .c and .s files to object files
OBJS = $(SRCS_C:%.c=%.o) $(SRCS_ASM:%.s=%.o)

# compile the boot file
crt0.o: $(BOOTDIR)/crt0.s
	as -o $@ $< $(BOOTFLAGS)

# assemble assembly (*.s) source files
%.o: $(ASMDIR)/%.s
	as -o $@ $< $(ASMFLAGS)

# compile C (*.c) source files
%.o : $(SRCDIR)/%.c
	gcc $(SRCDIR)/$*.c $(CFLAGS)

# link the object files (using the crt0.s and linkscript files)
$(PROJECTNAME).elf : crt0.o $(OBJS)
	gcc -o $(PROJECTNAME).elf $(LDFLAGS) crt0.o $(OBJS)

# copy to binary cartridge format
$(PROJECTNAME).bin : $(PROJECTNAME).elf
	objcopy -O binary $(PROJECTNAME).elf $(PROJECTNAME).bin

