#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)

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

#Phony Targets
.PHONY: all c++ java install clean install_bin distclean idls

all: c++ java
c++: idls

idls: $(IDLFLAGS) install_idl 
	$(MAKE) compile

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


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

#Real targets
ArchivingService: $(OBJS)  Service.o Archiving.o Archiving-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

