#
# Copyright 2002 Sony Corporation 
#
# Permission to use, copy, modify, and redistribute this software for
# non-commercial use is hereby granted.
#
# This software is provided "as is" without warranty of any kind,
# either expressed or implied, including but not limited to the
# implied warranties of fitness for a particular purpose.
#

# Configuration options
#
# Uncomment to enable (presently unfinished) global map functionality
#GLOBAL_MAP=-DWANT_GLOBAL_MAP

# Sources

COMBO=\
	MMComboStub.cc \
	MMCombo.cc \

SHARED=\
	../Shared/get_time.cc \
	../Shared/TimeET.cc \
	../Shared/Profiler.cc \
	../Shared/WorldState.cc \
	../Shared/WorldStateSerializer.cc \
	../Shared/LoadSave.cc \
	../Shared/Config.cc \

WIRELESS=\
	../Wireless/Wireless.cc \
	../Wireless/Socket.cc \
	../Wireless/TextCmdHandler.cc \

EVENTS=\
	../Events/EventBase.cc \
	../Events/EventRouter.cc \

BEHAVIORS=\
	../Behaviors/BehaviorBase.cc \
	../Behaviors/StartupBehavior.cc \
	../Behaviors/Controller.cc \
	../Behaviors/ChaseBallBehavior.cc \
	../Behaviors/StareAtBallBehavior.cc \
	../Behaviors/FollowHeadBehavior.cc \
	../Behaviors/EvtRptBehavior.cc \
	../StateMachine/StateNode.cc \
	../StateMachine/PaceTargetsMachine.cc \
	../StateMachine/WalkToTargetMachine.cc \
	../StateMachine/Transition.cc \

CONTROLS=\
	../Controls/ControlBase.cc \
	../Controls/MenuControl.cc \
	../Controls/EventLogger.cc \

MOTION=\
	../Motion/JointCmd.cc \
	../Motion/MotionManager.cc \
	../Motion/LedEngine.cc \
	../Motion/PostureEngine.cc \
	../Motion/EmergencyStopMC.cc \
	../Motion/HeadPointerMC.cc \
	../Motion/WalkMC.cc \
	../Motion/MotionSequenceMC.cc \
	../Motion/Kinematics.cc \

VISION=\
	../Vision/Vision.cc \
	../Vision/VisionSerializer.cc \

WORLDMODEL=\
	../WorldModel/WorldModel.cc \
	../WorldModel/WorldModelSerializer.cc \

WORLDMODEL2=\



SRCS:=$(COMBO) $(SHARED) $(WIRELESS) $(EVENTS) $(BEHAVIORS) $(CONTROLS) $(MOTION) $(VISION) $(WORLDMODEL) $(WORLDMODEL2)

OBJS=${SRCS:.cc=.o}
DEPENDS=${SRCS:.cc=.d}

PREFIX=/usr/local/OPEN_R_SDK
INSTALLDIR=../ms
CXX=$(PREFIX)/bin/mipsel-linux-g++
STRIP=$(PREFIX)/bin/mipsel-linux-strip
MKBIN=$(PREFIX)/OPEN_R/bin/mkbin
STUBGEN=$(PREFIX)/OPEN_R/bin/stubgen2
FILTERSYSWARN=../tools/filtersyswarn/filtersyswarn
MKBINFLAGS=-p $(PREFIX)
LIBS=-lObjectComm -lOPENR -lInternet -lantMCOOP
CXXFLAGS= \
	-g \
	-Wall -W -Wshadow -Wlarger-than-8192 -Wpointer-arith -Wcast-qual \
	-Wunreachable-code -Woverloaded-virtual -Weffc++ -Winline -Wdeprecated \
	-I. -I.. -isystem $(PREFIX)/OPEN_R/include/MCOOP \
	-isystem $(PREFIX)/OPEN_R/include/R4000 -isystem $(PREFIX)/OPEN_R/include \
	-DPLATFORM_APERIOS -DDEBUG -DOPENR_DEBUG -DCONSOLE_VT100 $(GLOBAL_MAP) \


all: mmcombo.bin

.PHONY: all install clean

%.o: %.cc %.d $(FILTERSYSWARN)
	@echo Compiling $< into $@...
	@$(CXX) $(CXXFLAGS) -o $@ -c $< &> $*.log; \
	retval=$$?; \
	cat $*.log | $(FILTERSYSWARN); \
	test $$retval -eq 0;

MMComboStub.cc: stub.cfg
	$(STUBGEN) stub.cfg	

mmcombo.bin: $(OBJS) MMCombo.ocf
	$(MKBIN) $(MKBINFLAGS) -o $@ $^ $(LIBS)
	$(STRIP) $@

$(INSTALLDIR)/open-r/mw/objs/mainobj.bin: mmcombo.bin
	sed 's/MMCombo/MainObj/g;s/mmcombo/mainobj/g' mmcombo.bin | gzip -c > $@

$(INSTALLDIR)/open-r/mw/objs/motoobj.bin: mmcombo.bin
	sed 's/MMCombo/MotoObj/g;s/mmcombo/motoobj/g' mmcombo.bin | gzip -c > $@

%.d : %.cc
	@echo Building $@ for $<
	@$(CXX) $(CXXFLAGS) -MP -MG -MT $@ -MT $*.o -MM $< > $@

$(FILTERSYSWARN):
	(cd ../tools && $(MAKE));

-include $(DEPENDS)

install: $(INSTALLDIR)/open-r/mw/objs/mainobj.bin $(INSTALLDIR)/open-r/mw/objs/motoobj.bin

clean:
	rm -f $(OBJS) *.bin *.elf *.snap.cc $(DEPENDS) ${SRCS:.cc=.log} *~
	rm -f *.o MMComboStub.* def.h entry.h
	rm -f $(INSTALLDIR)/open-r/mw/objs/mainobj.bin $(INSTALLDIR)/open-r/mw/objs/motoobj.bin
