#Variables
include $(SCT_DAQ_ROOT)/build/Makefile.include
#Commands
include $(SCT_DAQ_ROOT)/build/Makefile.commands

Package=ArchivingService

#Lists of source files
HDRS := $(wildcard *.h)
SRCS := $(wildcard *.cpp)
IDLS := $(wildcard *.idl)
IDLFLAGS :=  $(IDLS:.idl=.cppidl)
OBJS := $(SRCS:.cpp=.o)
BINS := ArchivingService

#Flags
CPPFLAGS += $(ROOTINCLUDES)

# This is required before online 00-21-02 because ISistream does not have virtual methods.
CPPFLAGS += -DIS_SERIALIZABLE_BUG

# note that the rootlibs were removed since they cause problems with exception handling.
LDLIBS += -lSummaryWriter -lSctData -lSct $(ROOTLIBS) -lboost_thread

#Phony Targets
.PHONY: all c++ java install clean install_bin install_lib install_hdrs install_idl distclean idls test

all: c++ java
c++: idls
	$(MAKE) compile

idls: $(IDLFLAGS) install_idl 

java: install_idl
compile: $(BINS) install
install: $(IncludeDir) install_hdrs install_bin install_idl
distclean: clean
	-rm -f *.cc *.hh *.cppidl *.d
clean:
	-rm -f *.o $(BINS)

install_bin: $(BinDir)/ArchivingService
install_idl: $(IncludeDir)/$(Package) $(addprefix $(IncludeDir)/$(Package)/,$(IDLS))

install_hdrs : $(IncludeDir)/$(Package) $(addprefix $(IncludeDir)/$(Package)/,$(HDRS)) $(addprefix $(IncludeDir)/$(Package)/,$(wildcard *.hh))


#Real targets
ArchivingService: $(OBJS) ArchivingServiceI.o ArchivingServiceI-server-stubs.o
	$(BINCMD)

#Patterns
%.o: %.cpp
	$(CPPCMD)

%.o: %.cc
	$(CPPCMD)

%.cppidl: $(CURDIR)/%.idl
	@echo $^
	$(CPPIDLCMD) && touch $@

$(BinDir)/%: %
	$(CPCMD)

$(IncludeDir)/$(Package)/%: %
	$(CPCMD)

#Pre-requisites
$(IncludeDir)/$(Package):
	$(MKDIR)

#dependencies
$(BINS): $(DEPENDLIBCMD)

%.d: %.cpp
	$(DEPENDCMD)

ifeq ($(INCLUDEDEPENDANCIES),)
include $(SRCS:.cpp=.d)
endif

