# PokeMini Makefile for SDL

CC = gcc
LD = gcc
STRIP = strip
POKEROOT = ./
BUILD = Build
TARGET = PokeMini

CFLAGS =  -O -Wall `$(SDL_BASE)sdl-config --cflags` $(INCLUDE)
SLFLAGS =  -O `$(SDL_BASE)sdl-config --libs` -lm -lz

INCDIRS = source sourcex resource freebios dependencies/minizip

OBJS = \
 PokeMini_SDL.o	\
 sourcex/KeybSDLMap.o	\
 freebios/freebios.o	\
 source/PMCommon.o	\
 source/PokeMini.o	\
 source/Multicart.o	\
 source/Hardware.o	\
 source/ExportBMP.o	\
 source/ExportWAV.o	\
 source/Video.o	\
 source/Video_x6.o	\
 source/Video_x8.o	\
 source/CommandLine.o	\
 source/MinxCPU.o	\
 source/MinxCPU_XX.o	\
 source/MinxCPU_CE.o	\
 source/MinxCPU_CF.o	\
 source/MinxCPU_SP.o \
 source/MinxTimers.o	\
 source/MinxIO.o	\
 source/MinxIRQ.o	\
 source/MinxPRC.o	\
 source/MinxColorPRC.o	\
 source/MinxLCD.o	\
 source/MinxAudio.o	\
 source/UI.o	\
 source/Joystick.o	\
 source/Keyboard.o	\
 dependencies/minizip/unzip.o	\
 dependencies/minizip/ioapi.o	\
 resource/PokeMini_ColorPal.o	\
 resource/PokeMini_Font12.o	\
 resource/PokeMini_Icons12.o	\
 resource/PokeMini_BG6.o	\
 resource/PokeMini_BG8.o

DEPENDS = \
 sourcex/KeybSDLMap.h	\
 freebios/freebios.h	\
 source/IOMap.h	\
 source/PMCommon.h	\
 source/PokeMini.h	\
 source/PokeMini_Version.h	\
 source/Multicart.h	\
 source/Hardware.h	\
 source/ExportBMP.h	\
 source/ExportWAV.h	\
 source/Video.h	\
 source/Video_x6.h	\
 source/Video_x8.h	\
 source/CommandLine.h	\
 source/MinxCPU.h	\
 source/MinxTimers.h	\
 source/MinxIO.h	\
 source/MinxIRQ.h	\
 source/MinxPRC.h	\
 source/MinxColorPRC.h	\
 source/MinxLCD.h	\
 source/MinxAudio.h	\
 source/UI.h	\
 source/Joystick.h	\
 source/Keyboard.h	\
 dependencies/minizip/unzip.h	\
 dependencies/minizip/ioapi.h	\
 resource/PokeMini_ColorPal.h	\
 resource/PokeMini_Font12.h	\
 resource/PokeMini_Icons12.h	\
 resource/PokeMini_BG6.h	\
 resource/PokeMini_BG8.h

BUILDOBJS = $(addprefix $(BUILD)/, $(notdir $(OBJS)))
DEPENDSHDR = $(addprefix $(POKEROOT), $(DEPENDS))
INCLUDE = $(foreach inc, $(INCDIRS), -I$(POKEROOT)$(inc))
VPATH = $(addprefix $(POKEROOT),$(INCDIRS))

.PHONY: all install uninstall clean

all: $(BUILD) $(TARGET)

$(BUILD):
	@[ -d @ ] || mkdir -p $@

$(BUILD)/%.o: %.c $(DEPENDSHDR)
	$(CC) $(CFLAGS) -o $@ -c $<

$(TARGET): $(BUILDOBJS)
	$(LD) -o $(TARGET) $(BUILDOBJS) $(SLFLAGS)
	$(STRIP) $(TARGET)

install:
	mkdir -p ${DESTDIR}/opt/pokemini
	cp -a PokeMini ${DESTDIR}/opt/pokemini
	chmod 755 ${DESTDIR}/opt/pokemini/PokeMini
	chmod 777 ${DESTDIR}/opt/pokemini
	@test -d ${DESTDIR}/usr/share/applications/hildon/ || mkdir -p ${DESTDIR}/usr/share/applications/hildon/
	@test -d ${DESTDIR}/usr/share/icons/hicolor/64x64/apps/ || mkdir -p ${DESTDIR}/usr/share/icons/hicolor/64x64/apps/
	cp data/pokemini.desktop ${DESTDIR}/usr/share/applications/hildon/
	cp data/PokeMini64x64.png ${DESTDIR}/usr/share/icons/hicolor/64x64/apps/pokemini.png

uninstall:
	rm ${DESTDIR}/opt/pokemini/PokeMini
	rm ${DESTDIR}/opt/pokemini
	rm ${DESTDIR}/usr/share/dbus-1/services/pokemini.service
	rm ${DESTDIR}/usr/share/applications/hildon/pokemini.desktop
	rm ${DESTDIR}/usr/share/icons/hicolor/64x64/apps/pokemini.png

clean:
	-rm -f $(BUILDOBJS) $(TARGET)
	-rmdir --ignore-fail-on-non-empty $(BUILD)
