# Makefile for runCtrl/tRunCtrl
# Satofumi KAMIMURA
# $Id$

# Compile options
RUBY = ruby
SH7045DIR = ../sh7045f

ARCH = sh-coff
LD_LOAD = $(SH7045DIR)/sh45load.x
LD_ROM = $(SH7045DIR)/sh45rom.x
#ARCH = sh-hitachi-elf
#LD_LOAD = $(SH7045DIR)/sh45load_elf.x
#LD_ROM = $(SH7045DIR)/sh45rom_elf.x

include $(SH7045DIR)/rules.mk
CFLAGS = -O2 -m2 -D$(TYPE) -Wall -W -Werror $(INCLUDES)
INCLUDES = -I. -I$(SH7045DIR)
START_UP_FILES = $(SH7045DIR)/crt0.S
LDFLAGS = -nostartfiles $(START_UP_FILES)
LDLIBS =


# Target
MATH_LIB = math.a
MATH_CREATES = isincos.h isincos.c iatan2.c
DEVICE_LIB = device.a
FRAMEWORK_LIB = framework.a
CONTROL_LIB = control.a
MANAGE_LIB = manage.a
NETWORK_LIB = network.a
SH7045LIB = $(SH7045DIR)/sh7045lib.a
RUN_SIM_CPP_LIB =
TARGET =
TYPE = beego

all : $(TARGET) $(MATH_CREATES)
	$(MAKE) "TYPE=beego" rom

test : allTest
	./allTest

clean : rom_clean
	$(RM) $(TARGET) allTest *.rom *.o

depend :
	makedepend -Y -- $(INCLUDES) -- $(wildcard *.c *.cpp *.h)

roms :
	$(MAKE) "TYPE=beego" rom
	$(MAKE) "TYPE=M1" rom
	$(MAKE) "TYPE=CQ" rom

rom : rom_clean tRunCtrl_$(TYPE).rom

.PHONY : all clean depend
######################################################################
$(SH7045LIB) $(RUN_SIM_CPP_LIB) $(UTILC_CPP_LIB) $(RUN_CPP_LIB) :
	cd $(@D) && $(MAKE) $(@F)

SH_LIBS = $(DEVICE_LIB) $(FRAMEWORK_LIB) $(CONTROL_LIB) $(MANAGE_LIB) $(NETWORK_LIB) $(MATH_LIB) $(SH7045LIB)

rom_clean :
	$(RM) tRunCtrl_$(TYPE).rom *.o *.cof *.a
tRunCtrl.rom : tRunCtrl.o taskCtrl.o $(SH_LIBS)
tRunCtrl_$(TYPE).rom : tRunCtrl.rom
	mv $< $@

$(SH7045LIB) : $(wildcard $(SH7045DIR)/*.[ch])

isincos.c : create_isincos.rb
	$(RUBY) $< > $@ || $(RM) $@
isincos.h : create_isincos.rb
	$(RUBY) $< header > $@ || $(RM) $@
isincos.o : isincos.h
iatan2.c : create_iatan2.rb
	$(RUBY) $< > $@ || $(RM) $@
iatan2.o : iatan2.h

movingAverage.o : movingAverage.c
	$(CC_FOR_BUILD) $(CFLAGS) -c $< -o $@

ringBuffer.o : ringBuffer.c
	$(CC_FOR_BUILD) $(CFLAGS) -c $< -o $@

$(MATH_LIB) : \
	$(MATH_LIB)(isincos.o) \
	$(MATH_LIB)(isqrt.o) \
	$(MATH_LIB)(iatan2.o) \

$(DEVICE_LIB) : \
	$(DEVICE_LIB)(encCtrl.o) \
	$(DEVICE_LIB)(motorCtrl.o) \
	$(DEVICE_LIB)(directDeviceCtrl.o) \

$(FRAMEWORK_LIB) : \
	$(FRAMEWORK_LIB)(wheelCtrl.o) \
	$(FRAMEWORK_LIB)(directWheelCtrl.o) \
	$(FRAMEWORK_LIB)(bodyCtrl.o) \
	$(FRAMEWORK_LIB)(bodyPosition.o) \
	$(FRAMEWORK_LIB)(velocityInfo.o) \
	$(FRAMEWORK_LIB)(movingAverage.o) \
	$(FRAMEWORK_LIB)(coordinateCtrl_target.o) \

$(CONTROL_LIB) : \
	$(CONTROL_LIB)(velocityCtrl.o) \

$(MANAGE_LIB) : \
	$(MANAGE_LIB)(modeCtrl.o) \
	$(MANAGE_LIB)(emergencyCtrl.o) \

$(NETWORK_LIB) : \
	$(NETWORK_LIB)(nodeAccess.o) \
	$(NETWORK_LIB)(transferCtrl.o) \
	$(NETWORK_LIB)(packetHandleTarget.o) \

allTest.o : ../../unittest/allTest.cpp
	$(CXX) $(CXXFLAGS) $< -c -o $@
isincos_cpp.o : isincos.c
	$(CXX) $(CXXFLAGS) $< -c -o $@
IsincosTest.o : IsincosTest.cpp
	$(CXX) $(CXXFLAGS) $< -c -o $@
PacketHandleTargetTest.o : PacketHandleTargetTest.cpp
	$(CXX) $(CXXFLAGS) $< -c -o $@

allTest : allTest.o \
	isincos_cpp.o IsincosTest.o \
	movingAverage.o \
	PacketHandleTargetTest.o \
	$(RUN_SIM_CPP_LIB) $(RUN_CPP_LIB) $(UTILC_CPP_LIB)
	$(CXX) $(CXXFLAGS) $^ `cppunit-config --libs` -o $@


# DO NOT DELETE

bodyCtrl.o: bodyCtrl.h wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h
bodyCtrl.o: math_util.h detect_os.h
bodyPosition.o: bodyPosition.h coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h
bodyPosition.o: motorCtrl.h robotParams.h encCtrl.h math_util.h detect_os.h
bodyPosition.o: isincos.h
coordinateCtrl_target.o: coordinateCtrl_target.h isincos.h
directDeviceCtrl.o: directDeviceCtrl.h motorCtrl.h robotParams.h
directWheelCtrl.o: directWheelCtrl.h wheelCtrl.h motorCtrl.h robotParams.h
directWheelCtrl.o: encCtrl.h math_util.h detect_os.h
emergencyCtrl.o: emergencyCtrl.h
encCtrl.o: encCtrl.h robotParams.h
iatan2.o: iatan2.h
isincos.o: isincos.h
isqrt.o: isqrt.h
modeCtrl.o: modeCtrl.h velocityCtrl.h velocityInfo.h bodyPosition.h
modeCtrl.o: coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h motorCtrl.h
modeCtrl.o: robotParams.h encCtrl.h math_util.h detect_os.h
motorCtrl.o: motorCtrl.h robotParams.h encCtrl.h tRunCtrl.h
movingAverage.o: movingAverage.h
nodeAccess.o: nodeAccess.h
packetHandleTarget.o: packetHandleTarget.h structTables.h directDeviceCtrl.h
packetHandleTarget.o: motorCtrl.h robotParams.h directWheelCtrl.h wheelCtrl.h
packetHandleTarget.o: encCtrl.h math_util.h detect_os.h modeCtrl.h
packetHandleTarget.o: velocityCtrl.h velocityInfo.h bodyPosition.h
packetHandleTarget.o: coordinateCtrl_target.h bodyCtrl.h nodeAccess.h
packetHandleTarget.o: transferCtrl.h tRunCtrl.h
tRunCtrl.o: tRunCtrl.h taskCtrl.h structTables.h directDeviceCtrl.h
tRunCtrl.o: motorCtrl.h robotParams.h directWheelCtrl.h wheelCtrl.h encCtrl.h
tRunCtrl.o: math_util.h detect_os.h modeCtrl.h velocityCtrl.h velocityInfo.h
tRunCtrl.o: bodyPosition.h coordinateCtrl_target.h bodyCtrl.h nodeAccess.h
tRunCtrl.o: transferCtrl.h ../sh7045f/sh7045lib.h ../sh7045f/sci_init.h
tRunCtrl.o: packetHandleTarget.h
taskCtrl.o: taskCtrl.h structTables.h directDeviceCtrl.h motorCtrl.h
taskCtrl.o: robotParams.h directWheelCtrl.h wheelCtrl.h encCtrl.h math_util.h
taskCtrl.o: detect_os.h modeCtrl.h velocityCtrl.h velocityInfo.h
taskCtrl.o: bodyPosition.h coordinateCtrl_target.h bodyCtrl.h nodeAccess.h
taskCtrl.o: packetHandleTarget.h ../sh7045f/sh7045lib.h ../sh7045f/sci_init.h
taskCtrl.o: emergencyCtrl.h
transferCtrl.o: tRunCtrl.h transferCtrl.h ../sh7045f/sh7045lib.h
transferCtrl.o: ../sh7045f/sci_init.h
velocityCtrl.o: velocityCtrl.h velocityInfo.h bodyPosition.h
velocityCtrl.o: coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h motorCtrl.h
velocityCtrl.o: robotParams.h encCtrl.h math_util.h detect_os.h isqrt.h
velocityCtrl.o: iatan2.h isincos.h
velocityInfo.o: velocityInfo.h bodyPosition.h coordinateCtrl_target.h
velocityInfo.o: bodyCtrl.h wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h
velocityInfo.o: math_util.h detect_os.h movingAverage.h
wheelCtrl.o: wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h math_util.h
wheelCtrl.o: detect_os.h
IsincosTest.o: IsincosTest.h isincos.h
PacketHandleTargetTest.o: PacketHandleTargetTest.h packetHandleTarget.h
PacketHandleTargetTest.o: structTables.h directDeviceCtrl.h motorCtrl.h
PacketHandleTargetTest.o: robotParams.h directWheelCtrl.h wheelCtrl.h
PacketHandleTargetTest.o: encCtrl.h math_util.h detect_os.h modeCtrl.h
PacketHandleTargetTest.o: velocityCtrl.h velocityInfo.h bodyPosition.h
PacketHandleTargetTest.o: coordinateCtrl_target.h bodyCtrl.h
bodyCtrl.o: wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h math_util.h
bodyCtrl.o: detect_os.h
bodyPosition.o: coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h motorCtrl.h
bodyPosition.o: robotParams.h encCtrl.h math_util.h detect_os.h
directDeviceCtrl.o: motorCtrl.h robotParams.h
directWheelCtrl.o: wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h
directWheelCtrl.o: math_util.h detect_os.h
encCtrl.o: robotParams.h
math_util.o: detect_os.h
modeCtrl.o: velocityCtrl.h velocityInfo.h bodyPosition.h
modeCtrl.o: coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h motorCtrl.h
modeCtrl.o: robotParams.h encCtrl.h math_util.h detect_os.h
motorCtrl.o: robotParams.h
packetHandleTarget.o: structTables.h directDeviceCtrl.h motorCtrl.h
packetHandleTarget.o: robotParams.h directWheelCtrl.h wheelCtrl.h encCtrl.h
packetHandleTarget.o: math_util.h detect_os.h modeCtrl.h velocityCtrl.h
packetHandleTarget.o: velocityInfo.h bodyPosition.h coordinateCtrl_target.h
packetHandleTarget.o: bodyCtrl.h
structTables.o: directDeviceCtrl.h motorCtrl.h robotParams.h
structTables.o: directWheelCtrl.h wheelCtrl.h encCtrl.h math_util.h
structTables.o: detect_os.h modeCtrl.h velocityCtrl.h velocityInfo.h
structTables.o: bodyPosition.h coordinateCtrl_target.h bodyCtrl.h
taskCtrl.o: structTables.h directDeviceCtrl.h motorCtrl.h robotParams.h
taskCtrl.o: directWheelCtrl.h wheelCtrl.h encCtrl.h math_util.h detect_os.h
taskCtrl.o: modeCtrl.h velocityCtrl.h velocityInfo.h bodyPosition.h
taskCtrl.o: coordinateCtrl_target.h bodyCtrl.h nodeAccess.h
velocityCtrl.o: velocityInfo.h bodyPosition.h coordinateCtrl_target.h
velocityCtrl.o: bodyCtrl.h wheelCtrl.h motorCtrl.h robotParams.h encCtrl.h
velocityCtrl.o: math_util.h detect_os.h
velocityInfo.o: bodyPosition.h coordinateCtrl_target.h bodyCtrl.h wheelCtrl.h
velocityInfo.o: motorCtrl.h robotParams.h encCtrl.h math_util.h detect_os.h
wheelCtrl.o: motorCtrl.h robotParams.h encCtrl.h math_util.h detect_os.h
