# -*- Mode: makefile -*-
#      CVS: $Id: Makefile,v 1.15 2005/12/30 22:34:53 rijsman Exp $
#      Tag: $name$
#     Info: $CVSROOT/Copyright.txt

target: install

ifndef IDEA_DIR
   IDEA_DIR= ./../
endif 

include $(IDEA_DIR)/ideaMakeOptions.imake

INCLUDE_DIRS += -I$(ACE_ROOT)
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/Agent/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/PlanServer/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/Planner/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/ReactivePlanner/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/Utilities/Includes
INCLUDE_DIRS += -I./Includes

LIBS_SH += -L$(ACE_ROOT)/ace 
LIBS_SH += -lACE

LIBS_SH += -L$(INSTALL_LIB_DIR) 
LIBS_SH += -lutils$(IDEA_EXT) 
LIBS_SH += -lplanserver$(IDEA_EXT) 
LIBS_SH += -lplanner$(IDEA_EXT) 
LIBS_SH += -lreactiveplanner$(IDEA_EXT) 
LIBS_SH += -lagent$(IDEA_EXT)

# not truly static!
LIBS_ST += -L$(ACE_ROOT)/ace/ 
LIBS_ST += -lACE

LIBS_ST += $(INSTALL_LIB_DIR)/libagent$(IDEA_EXT).a
LIBS_ST += $(INSTALL_LIB_DIR)/libreactiveplanner$(IDEA_EXT).a
LIBS_ST += $(INSTALL_LIB_DIR)/libplanner$(IDEA_EXT).a
LIBS_ST += $(INSTALL_LIB_DIR)/libplanserver$(IDEA_EXT).a
LIBS_ST += $(INSTALL_LIB_DIR)/libutils$(IDEA_EXT).a

INCLUDE_DIR :=./Includes

BINARY_SH := agentrunner_sh$(IDEA_EXT)
BINARY_ST := agentrunner_st$(IDEA_EXT)

SOURCES := $(wildcard *.cc) 
OBJECTS := $(SOURCES:.cc=$(IDEA_EXT).o)

CFLAGS += $(INCLUDE_DIRS)

$(OBJECTS): %$(IDEA_EXT).o : %.cc
	$(CCC) $(CFLAGS) -c $< -o $@

$(BINARY_SH): libraries_sh $(OBJECTS)
	$(CCC)  $(OBJECTS) $(LIBS) $(LIBS_SH) -o $@ -Wl,--rpath,./

$(BINARY_ST): libraries_st $(OBJECTS)
	$(CCC)  $(OBJECTS) $(LIBS) $(LIBS_ST) -o $@

libraries_sh:
	$(MAKE) -C $(IDEA_DIR)/Core/Agent install-shared
	$(MAKE) -C $(IDEA_DIR)/Core/PlanServer install-shared
	$(MAKE) -C $(IDEA_DIR)/Core/Planner install-shared
	$(MAKE) -C $(IDEA_DIR)/Core/ReactivePlanner install-shared
	$(MAKE) -C $(IDEA_DIR)/Core/Utilities install-shared
	$(MAKE) -C $(IDEA_DIR)/Core/GoalLoader install-shared

libraries_st:
	$(MAKE) -C $(IDEA_DIR)/Core/Agent install-static
	$(MAKE) -C $(IDEA_DIR)/Core/PlanServer install-static
	$(MAKE) -C $(IDEA_DIR)/Core/Planner install-static
	$(MAKE) -C $(IDEA_DIR)/Core/ReactivePlanner install-static
	$(MAKE) -C $(IDEA_DIR)/Core/Utilities install-static
	$(MAKE) -C $(IDEA_DIR)/Core/GoalLoader install-static

install: install-static install-shared

install-static: checkace $(BINARY_ST)
	$(CP) $(BINARY_ST) $(INSTALL_BIN_DIR)/.

install-shared: checkace $(BINARY_SH)
	$(CP) $(BINARY_SH) $(INSTALL_BIN_DIR)/.

clean:
	$(RM) *~ *.o agentrunner_*
	$(MAKE) -C $(IDEA_DIR)/Core/Agent clean
	$(MAKE) -C $(IDEA_DIR)/Core/PlanServer clean
	$(MAKE) -C $(IDEA_DIR)/Core/Planner clean
	$(MAKE) -C $(IDEA_DIR)/Core/ReactivePlanner clean
	$(MAKE) -C $(IDEA_DIR)/Core/Utilities clean
	$(MAKE) -C $(IDEA_DIR)/Core/GoalLoader clean

veryclean: clean
	$(RM) $(INSTALL_BIN_DIR)/agentrunner_*
	$(MAKE) -C $(IDEA_DIR)/Core/Agent veryclean
	$(MAKE) -C $(IDEA_DIR)/Core/PlanServer veryclean
	$(MAKE) -C $(IDEA_DIR)/Core/Planner veryclean
	$(MAKE) -C $(IDEA_DIR)/Core/ReactivePlanner veryclean
	$(MAKE) -C $(IDEA_DIR)/Core/Utilities veryclean
	$(MAKE) -C $(IDEA_DIR)/Core/GoalLoader veryclean
