# /* LICENSE:
#   =========================================================================
#     CMPack'03 Source Code Release for OPEN-R SDK v1.0
#     Copyright (C) 2003 Multirobot Lab [Project Head: Manuela Veloso]
#     School of Computer Science, Carnegie Mellon University
#     All rights reserved.
#   ========================================================================= */

C++ := g++

IFLAGS := -I../..

LIBS := 

LFLAGS := `fltk-config --ldflags` -L/usr/X11R6/lib -lX11 -lMagick++ -lMagick

# -Wshadow  -Woverloaded-virtual
#OPT := -O2
DEBUG := -g
#PROFILE :=-pg
CFLAGS := $(DEBUG) $(OPT) $(PROFILE) `fltk-config --cxxflags` -march=pentium -ffast-math -DPLATFORM_LINUX -DVIS_NO_LIBS -Wall -Wstrict-prototypes $(IFLAGS)

SRCS := \
	VisionTrain.cc \
	../../agent/Main/Events.cc \
	../../agent/Motion/Kinematics.cc \
	../../agent/Vision/Vision.cc \
	../../agent/Vision/Radial.cc \
	../../agent/Vision/BWBallDetector.cc \
	../../agent/shared_code/CircBufPacket.cc \
	../../agent/shared_code/Dictionary.cc \
	../../agent/shared_code/FileSystem.cc \
	../shared/image.cc \
	../shared/win.cc \

OBJS := $(SRCS:.cc=.o)
OBJS_PROF := $(SRCS:.cc=_prof.o)

DEPENDS := $(SRCS:%.cc=%.dep)

TARGET := vis_train
TARGET_PROF := vis_train_prof

$(TARGET_PROF) : CFLAGS := $(CFLAGS_PROFILE)
$(OBJS_PROF) : CFLAGS := $(CFLAGS_PROFILE)

all: $(TARGET)
	(cd ../bin; \rm -rf $(TARGET);ln -s ../vision_train/$(TARGET))

profile: $(TARGET_PROF)

$(TARGET): $(OBJS) $(LIBS)
	$(C++) -o $@ $(CFLAGS) $^ $(LFLAGS)

$(TARGET_PROF): $(OBJS_PROF) $(LIBS)
	$(C++) -o $@ $(CFLAGS) $^ $(LFLAGS)

clean:
	rm -f $(OBJS)
	rm -f $(TARGET)
	rm -f $(DEPENDS)
	rm -f ../bin/$(TARGET)

dep: depend

depend:
	rm -f $(DEPENDS)

include $(DEPENDS)

%.o: %.cc
	$(C++) -c -o $@ $< $(CFLAGS)

%_prof.o: %.cc
	$(C++) -c -o $@ $< $(CFLAGS)

%.dep: %.cc
	$(C++) -M $(CFLAGS) $< > $@.tmp
	echo -n "$@ $(<:.cc=_prof.o) " >$@
	perl -pe 's&$(<F:.cc=.o)&$(<:.cc=.o)&' $@.tmp >>$@
	rm $@.tmp
