#  *** Tetrigram GBA ***
# Franois PESSAUX February 2005
# This program is freeware.
# Use its sources as you whant provided that you leave this copyright unchanged
# and that you drop a small word telling that I'm the author of these sources.
# Thank's a lot.
#   --Francois


# Makefile pour utiliser avec devKitARM.
CROSS = /usr/local/devkitARM_r6/bin/arm-elf-
ARCH = -mthumb -mthumb-interwork
# gba_mb.specs pour le multiboot
SPECS = -specs=gba.specs
CFLAGS	= -I.. \
	 -Wall -fno-common \
	-mcpu=arm7tdmi -mtune=arm7tdmi \
	-fomit-frame-pointer\
	-ffast-math \
	$(ARCH) $(SPECS)


GCC = $(CROSS)gcc
AS = $(CROSS)as
OBJCOPY = $(CROSS)objcopy
LD = $(CROSS)ld

# Uncomment to compile under Windows with devkit installed with Cygwin.
# LIBPREFIX = "C:\Cygwin"

MAP = map.out
LIBS = $(LIBPREFIX)/usr/local/devkitARM_r6/arm-elf/lib/interwork/libc.a \
	$(LIBPREFIX)/usr/local/devkitARM_r6/lib/gcc/arm-elf/3.4.0/interwork/libgcc.a
LDFLAGS = -marmelf -Map $(MAP) -nostartfiles -Tlnkscript

CFILES = \
	debug.c \
	gfx_effects.c \
	it_handlers.c \
	key_control.c \
	load_gfx_data.c \
	intro_gfx.c \
	intro_sprite_gfx.c \
	shapes_sprites_gfx.c \
	cells_gfx.c \
	layout_gfx.c \
	small_digits_gfx.c \
	large_digits_gfx.c \
	shapes_configurations.c \
	shapes.c \
	arrow_sprite_gfx.c \
	finger_sprite_gfx.c \
	shapes_gfx.c \
	lev_sel_gfx.c \
	ihm.c \
	levels_data.c \
	lev_sel.c \
	game_core.c \
	pause_menu_gfx.c \
	goal_gfx.c \
	pause.c \
	abandon_gfx.c \
	wait_screen.c \
	persistent.c \
	wav_dontfit.c \
	wav_fit.c \
	wav_no.c \
	wav_bye_bye.c \
	wav_wow.c \
	eyes_sprite_gfx.c \
	main.c
OBJS = $(CFILES:.c=.o)

.SUFFIXES:
.SUFFIXES: .c .o

all: tetrigram.bin


crt0.o: crt0.S
	$(AS) -o $@ $<


# ELF to GBA conversion.
tetrigram.bin: tetrigram.elf
	$(OBJCOPY) -O binary tetrigram.elf $@

# Final link.
tetrigram.elf: crt0.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ crt0.o $(OBJS) $(LIBS)


test: shapes.h shapes.c make_data.h make_data.c main_test.c
	gcc -DCONSOLE_DEBUG -c shapes.c
	gcc -DCONSOLE_DEBUG -c make_data.c
	gcc -DCONSOLE_DEBUG -c main_test.c
	gcc shapes.o make_data.o main_test.o -o main_test

.c.o:
	$(GCC) $(CFLAGS) -O3 -c $<


# Rgles normales en -O3
debug.o: debug.c
main.o: main.c
shapes.o: shapes.c
it_handlers.o: it_handlers.c
intro_gfx.o: intro_gfx.c
load_gfx_data.o: load_gfx_data.c
layout_gfx.o: layout_gfx.c
small_digits_gfx.o: small_digits_gfx.c
large_digits_gfx.o: large_digits_gfx.c
layout.o: layout.c
key_control.o: key_control.c
intro_sprite_gfx.o: intro_sprite_gfx.c
game_core.o: game_core.c
ihm.o: ihm.c
finger_sprite_gfx.o: finger_sprite_gfx.c
gfx_effects.o: gfx_effects.c
shapes_gfx.o: shapes_gfx.c
shapes_configurations.o: shapes_configurations.c
shapes_sprites_gfx.o: shapes_sprites_gfx.c
cells_gfx.o: cells_gfx.c
levels_data.o: levels_data.c
pause.o: pause.c
pause_menu_gfx.o: pause_menu_gfx.c
arrow_sprite_gfx.o: arrow_sprite_gfx.c
abandon_gfx.o: abandon_gfx.c
wait_screen.o: wait_screen.c
goal_gfx.o: goal_gfx.c
lev_sel_gfx.o: lev_sel_gfx.c
lev_sel.o: lev_sel.c
persistent.o: persistent.c
wav_dontfit.o: wav_dontfit.c
wav_fit.o: wav_fit.c
wav_no.o: wav_no.c
wav_bye_bye.o: wav_bye_bye.c
wav_wow.o: wav_wow.c
eyes_sprite_gfx.o: eyes_sprite_gfx.c



clean:
	rm -f tetrigram.elf tetrigram.bin $(OBJS) crt0.o map.out *~
	rm -f main_test make_data.o main_test.o
