SOCCER_LIB_DIR=../soccer_library
SOCCERLIB_CONFIG=$(SOCCER_LIB_DIR)/soccerlib-config --prefix=$(SOCCER_LIB_DIR)

#CC     = `$(SOCCERLIB_CONFIG) --cc`
#CXX    = `$(SOCCERLIB_CONFIG) --c++`
#CC     = gcc -ansi -pedantic -Wall
#CXX    = g++ -ansi -pedantic -Wall
CC      = gcc -Wall
CXX     = g++ -Wall
MAKE_AR = `$(SOCCERLIB_CONFIG) --make-ar`
PRCS    = prcs
CHDIR   = cd
RM      = rm

DEBUG_SERVER_DIR  = ../debug_server
SOCCER_VIEW_LIBRARY_DIR = ../viewer_library
GTK_EXTENTION_DIR = $(SOCCER_VIEW_LIBRARY_DIR)/gtk_extention

INCLUDES = -I$(DEBUG_SERVER_DIR) \
	   -I$(SOCCER_VIEW_LIBRARY_DIR) -I$(GTK_EXTENTION_DIR)

CFLAGS   = -g `gtkmm-config --cflags` \
	      `$(SOCCERLIB_CONFIG) --cflags` \
	      $(INCLUDES) $(CCXXOPTFLAGS) $(COPTFLAGS) \
	      $(CCXXADDITIONALFLAGS) $(CADDITIONALFLAGS)

CXXFLAGS = -g `gtkmm-config --cflags` \
	      `$(SOCCERLIB_CONFIG) --cflags` \
	      $(INCLUDES) $(CCXXOPTFLAGS) $(CXXOPTFLAGS) \
	      $(CCXXADDITIONALFLAGS) $(CXXADDITIONALFLAGS)

LDFLAGS = -L. -lsoccer_viewer \
	  -L$(SOCCER_VIEW_LIBRARY_DIR) -lsoccer_view \
	  -L$(GTK_EXTENTION_DIR) -lgtk_extention \
	  `gtkmm-config --libs` \
	  -L$(DEBUG_SERVER_DIR) -ldebug_server \
	  `$(SOCCERLIB_CONFIG) --libs` -lm $(LDADDITIONALFLAGS)

OBJS = view_config.o time_controller.o \
       soccer_viewer.o view_controll_panel.o config_window.o \
       step_controller.o field_view.o viewer_field_canvas.o \
       soccer_viewer_option_analyser.o

all: soccer_viewer

library: libviewermodel.a
library-only: library
	$(RM) -f *.o

soccer_viewer-only: soccer_viewer
	$(RM) -f *.o *.core core
	($(CHDIR) $(GTK_EXTENTION_DIR) && $(MAKE) clean)
	($(CHDIR) $(DEBUG_SERVER_DIR) && $(MAKE) clean)

soccer_viewer: $(DEBUG_SERVER_DIR)/libdebug_server.a \
	       $(GTK_EXTENTION_DIR)/libgtk_extention.a \
	       $(SOCCER_VIEW_LIBRARY_DIR)/libsoccer_view.a \
	       libsoccer_viewer.a \
	       main.o
	$(RM) -f soccer_viewer
	$(CXX) -o soccer_viewer $(CXXFLAGS) main.o $(LDFLAGS)

libsoccer_viewer.a: $(OBJS)
	$(MAKE_AR) libsoccer_viewer.a $(OBJS)

$(GTK_EXTENTION_DIR)/libgtk_extention.a:
	$(CHDIR) $(GTK_EXTENTION_DIR) && $(MAKE) libgtk_extention.a

$(SOCCER_VIEW_LIBRARY_DIR)/libsoccer_view.a:
	$(CHDIR) $(SOCCER_VIEW_LIBRARY_DIR) && $(MAKE) libsoccer_view.a

$(DEBUG_SERVER_DIR)/libdebug_server.a:
	$(CHDIR) $(DEBUG_SERVER_DIR) && $(MAKE) libdebug_server.a

rebuild:
	$(RM) -f soccer_viewer
	$(MAKE) soccer_viewer

clean:
	$(RM) -f *.o *.core core libsoccer_viewer.a soccer_viewer


#
# Revision Control
#
diff:
	@$(CHDIR) .. && $(PRCS) diff || true

populate:
	@$(CHDIR) .. && $(PRCS) populate

checkin:
	@$(CHDIR) .. && $(PRCS) checkin && $(RM) -f .*.prcs_aux


##
view_config.o: view_config.h view_config.cc

time_controller.o: time_controller.h time_controller.cc \
		   $(DEBUG_SERVER_DIR)/active_repository.h \
		   $(DEBUG_SERVER_DIR)/view_snapshot.h \
		   $(DEBUG_SERVER_DIR)/monitor_view_data.h \
		   $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
		   $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h

viewer_field_canvas.o: viewer_field_canvas.h viewer_field_canvas.cc \
		       $(SOCCER_VIEW_LIBRARY_DIR)/field_canvas.h \
		       $(SOCCER_VIEW_LIBRARY_DIR)/team_config.h \
		       $(DEBUG_SERVER_DIR)/active_repository.h \
		       $(DEBUG_SERVER_DIR)/view_snapshot.h \
		       $(DEBUG_SERVER_DIR)/monitor_view_data.h \
		       $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
		       $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h

field_view.o: field_view.h field_view.cc \
	      $(SOCCER_VIEW_LIBRARY_DIR)/field_canvas.h \
	      $(SOCCER_VIEW_LIBRARY_DIR)/team_config.h \
	      view_config.h \
	      view_controll_panel.h \
	      $(DEBUG_SERVER_DIR)/active_repository.h \
	      $(DEBUG_SERVER_DIR)/active_repository.h \
	      $(DEBUG_SERVER_DIR)/view_snapshot.h \
	      $(DEBUG_SERVER_DIR)/monitor_view_data.h \
	      $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
	      $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h \
	      $(GTK_EXTENTION_DIR)/coordinate_view_pixmap.h \
	      $(GTK_EXTENTION_DIR)/transparent_pixmap.h \
	      $(GTK_EXTENTION_DIR)/gdk_gc_wrapper.h

config_window.o: config_window.h config_window.cc \
		 view_config.h soccer_viewer.h

view_controll_panel.o: view_controll_panel.h view_controll_panel.cc \
		       $(DEBUG_SERVER_DIR)/active_repository.h \
		       $(DEBUG_SERVER_DIR)/view_snapshot.h \
		       $(DEBUG_SERVER_DIR)/monitor_view_data.h \
		       $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
		       $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h \
		       step_controller.h \
		       config_window.h view_config.h soccer_viewer.h \
		       $(GTK_EXTENTION_DIR)/quit_button.h

step_controller.o: step_controller.h step_controller.cc \
		   $(DEBUG_SERVER_DIR)/active_repository.h \
		   $(DEBUG_SERVER_DIR)/view_snapshot.h \
		   $(DEBUG_SERVER_DIR)/monitor_view_data.h \
		   $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
		   $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h

soccer_viewer_option_analyser.o: \
		soccer_viewer_option_analyser.h \
		soccer_viewer_option_analyser.cc \
		$(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h

soccer_viewer.o: soccer_viewer.h soccer_viewer.cc \
		 $(DEBUG_SERVER_DIR)/active_repository.h \
		 $(DEBUG_SERVER_DIR)/view_snapshot.h \
		 $(DEBUG_SERVER_DIR)/monitor_view_data.h \
		 $(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
		 $(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h \
		 view_controll_panel.h config_window.h view_config.h \
		 soccer_viewer.h \
		 step_controller.h \
		 field_view.h \
		 $(SOCCER_VIEW_LIBRARY_DIR)/field_canvas.h \
		 $(SOCCER_VIEW_LIBRARY_DIR)/game_info_mode_line.h \
		 $(SOCCER_VIEW_LIBRARY_DIR)/team_config.h \
		 view_config.h view_controll_panel.h \
		 $(GTK_EXTENTION_DIR)/coordinate_view_pixmap.h \
		 $(GTK_EXTENTION_DIR)/transparent_pixmap.h \
		 $(GTK_EXTENTION_DIR)/gdk_gc_wrapper.h \
		 $(GTK_EXTENTION_DIR)/quit_button.h

main.o: main.cc \
	active_repository_updater.h \
	$(DEBUG_SERVER_DIR)/active_repository.h \
	$(DEBUG_SERVER_DIR)/view_snapshot.h \
	$(DEBUG_SERVER_DIR)/monitor_view_data.h \
	$(DEBUG_SERVER_DIR)/debug_client_field_recog.h \
	$(DEBUG_SERVER_DIR)/sserver_monitor_log_format.h \
	soccer_viewer_option_analyser.h \
	view_controll_panel.h config_window.h view_config.h soccer_viewer.h \
	step_controller.h \
	field_view.h \
	$(SOCCER_VIEW_LIBRARY_DIR)/field_canvas.h \
	$(SOCCER_VIEW_LIBRARY_DIR)/game_info_mode_line.h \
	$(SOCCER_VIEW_LIBRARY_DIR)/team_config.h \
	view_config.h \
	$(GTK_EXTENTION_DIR)/coordinate_view_pixmap.h \
	$(GTK_EXTENTION_DIR)/transparent_pixmap.h \
	$(GTK_EXTENTION_DIR)/gdk_gc_wrapper.h \
	$(GTK_EXTENTION_DIR)/quit_button.h
