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

target: all

ifndef IDEA_DIR
   IDEA_DIR= ./../
endif 

include $(IDEA_DIR)/Modules/IPC/ipcMakeOptions.imake

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/Simulator/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Core/Utilities/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Modules/IPC/ComRelay/Includes
INCLUDE_DIRS += -I$(IDEA_DIR)/Modules/SharedTimingService/Includes

INCLUDE_DIRS += -I$(ACE_ROOT)

BINARY_SH := simulator_sh$(IDEA_EXT)
BINARY_ST := simulator_st$(IDEA_EXT)

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

CFLAGS += $(INCLUDE_DIRS)

LIBS_SH :=  -lsimulator$(IDEA_EXT) \
	   -lagent$(IDEA_EXT) \
	   -lplanserver$(IDEA_EXT) \
	   -lplanner$(IDEA_EXT) \
	   -lipcrelay$(IDEA_EXT) \
	   -lutils$(IDEA_EXT) \
	   -lsharedtimingservice$(IDEA_EXT) \
           -lsharedagenttimingservice$(IDEA_EXT) \
	   -L$(ACE_ROOT)/ace -lACE \
	   -L$(INSTALL_LIB_DIR) \
	   -L$(IPC_LIB_DIR) -lipc

LIBS_ST := -L$(ACE_ROOT)/ace -lACE \
	     $(INSTALL_LIB_DIR)/libsimulator$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libagent$(IDEA_EXT).a \
             $(INSTALL_LIB_DIR)/libsharedagenttimingservice$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libsharedtimingservice$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libplanserver$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libplanner$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libutils$(IDEA_EXT).a \
	     $(INSTALL_LIB_DIR)/libipcrelay$(IDEA_EXT).a \
	     -L$(IPC_LIB_DIR) -lipc

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

all: install-static install-shared

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

$(BINARY_ST): libraries_st $(OBJECTS)
	$(CCC) $(OBJECTS) $(LIBS) $(LIBS_ST) $(INSTALL_LIB_DIR)/libutils$(IDEA_EXT).a  -o $@

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

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

libraries_sh:
	$(MAKE) -C $(IDEA_DIR)/Core/Simulator install-shared
	$(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)/TimingService install-shared
	$(MAKE) -C $(IDEA_DIR)/Modules/IPC/ComRelay install-shared
	$(MAKE) -C $(IDEA_DIR)/Modules/SharedTimingService install-shared

libraries_st:
	$(MAKE) -C $(IDEA_DIR)/Core/Simulator install-static
	$(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)/TimingService install-static
	$(MAKE) -C $(IDEA_DIR)/Modules/IPC/ComRelay install-static
	$(MAKE) -C $(IDEA_DIR)/Modules/SharedTimingService install-static

clean:
	$(RM) *~ *.o simulator_*

veryclean: clean
	$(RM) $(INSTALL_BIN_DIR)/simulator_*
