# Makefile for libs/tools/sloader
# Satofumi KAMIMURA
# $Id$

# Compile options
CC = g++
CXXFLAGS = -g -O0 -Wall -Werror ${INCLUDES} `sdl-config --cflags` -DMONITOR
INCLUDES = -I../../common -I../../connection -I../sh2writer
LDFLAGS =
LDLIBS = `sdl-config --libs` -lSDL_net -lboost_regex

SH_ARC = sh-coff
SH_INCLUDES = -I../../sh7045

# Target
TARGET = \
	sloader \

all : ${TARGET} sh45mon.rom

clean :
	${RM} *.o ${TARGET} tcpipLog_send.txt tcpipLog_recv.txt sloader.tag
	${RM} -rf doxygen_html/

depend :
	makedepend -Y -- ${INCLUDES} -- ${wildcard *.h *.c *.cpp}

html :
	doxygen

.PHONY : all clean depend
######################################################################
REQUIRE_LIBS = ../../connection/connection.a ../../common/common.a
${REQUIRE_LIBS} :
	cd ${@D}/ && ${MAKE} ${@F}
OBJS = SFormatHandler.o FZtatHandler.o LoaderTargetSimulator.o write_rom_host.o

FZtatHandler.o : ../sh2writer/FZtatHandler.cpp
	${CXX} ${CXXFLAGS} -c $<
SFormatHandler.o : ../sh2writer/SFormatHandler.cpp
	${CXX} ${CXXFLAGS} -c $<
write_rom_host.o : ../sh2writer/write_rom.c
	${CXX} ${CXXFLAGS} -c $< -o $@

sloader : ${OBJS} ${REQUIRE_LIBS}


SH_INCLUDES = -I../sh2writer -I../../sh7045
SH_OBJS = sh45mon.o tiny_sci.o write_rom.o

sh45mon.o : sh45mon.c
	${SH_ARC}-gcc -O2 -m2 -Wall -Werror ${SH_INCLUDES} -c $<
tiny_sci.o : ../sh2writer/tiny_sci.c
	${SH_ARC}-gcc -O2 -m2 -Wall -Werror ${SH_INCLUDES} -c $< -o $@
write_rom.o : ../sh2writer/write_rom.c
	${SH_ARC}-gcc -O2 -m2 -Wall -Werror ${SH_INCLUDES} -c $< -o $@

sh45mon.rom : ${SH_OBJS} sh45rom_min.x
	${SH_ARC}-gcc -nostartfiles ../../sh7045/crt0.S -T sh45rom_min.x -O2 -m2 -Wall -Werror ${SH_INCLUDES} $^ -o $@.tmp
	${SH_ARC}-objcopy --adjust-vma=0 --srec-forceS3 -O srec $@.tmp $@
	@${RM} $@.tmp
	@chmod a-x $@

# DO NOT DELETE

sh45mon.o: ../sh2writer/tiny_sci.h ../sh2writer/write_rom.h
LoaderTargetSimulator.o: LoaderTargetSimulator.h ../sh2writer/FZtatHandler.h
LoaderTargetSimulator.o: LoaderTargetPort.h ../../connection/TcpipCtrl.h
LoaderTargetSimulator.o: ../../connection/ConnectionInterface.h
LoaderTargetSimulator.o: ../../connection/TcpipAccept.h
LoaderTargetSimulator.o: ../../common/ThreadCreator.h
LoaderTargetSimulator.o: ../sh2writer/write_rom.h
LoaderTargetSimulator.o: ../../connection/ConnectionLogger.h
sloader.o: ../../common/DetectOS.h ../sh2writer/SFormatHandler.h
sloader.o: ../sh2writer/FZtatHandler.h ../../connection/ConnectionInterface.h
sloader.o: ../../common/StandardInput.h ../../common/FileToArgs.h
sloader.o: ../../common/SearchFilePath.h
