# This make file builds the RodModule class library, libRodModule.so.
# This file also builds the TimModule class library, libTimModule.so.
# In order for it to work, the environment variable SCTPIXEL_DAQ_ROOT 
# must be set to point to the root of the DAQ directory tree, which is
# one level above the directory in which this Makefile resides.
#
# Here is the assumed directory structure
#   $SCTPIXEL_DAQ_ROOT/
#      CommonWithDsp/
#         Contains header files needed by DSP software and hosts (Win32 and Linux)
#      CommonForHosts/
#         Contains header files needed by both Win32 and Linux hosts
#   ../VmeInterface/
#         Contains the class library for accessing VME via RCCVmeInterface
#      RodCrate/
#         Contains the class libraries for RodModule, TimModule, and their
#         associated classes
#      RodTests/
#         Contains main programs for testing ROD software
#
# Doxygen output and a PowerPoint presentation can be found via links from
# the sctpixel web page:
#
# http://sctpixel.home.cern.ch/sctpixel/shared.html
#
RODOBJS = RodModule.o RodPrimitive.o RodPrimList.o RodOutList.o
TIMOBJS = TimModule.o
BOCOBJS = BocCard.o
dspheader = $(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/processor.h \
            $(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/comRegDfns.h \
            $(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/smSendTxtBuff.h \
            $(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/txtBuffer.h
rodheader = RodVmeAddresses.h RodDspAddresses.h RodRegisterBits.h BaseException.h
LDPATH = -L$(SCTPIXEL_DAQ_ROOT)/../VmeInterface -L$(DAQ_SW_DIR)/lib 
LDLIBS = -lRodModule -lRCCVmeInterface -lBaseException -lcmem_rcc -lrcc_error -lvme_rcc
CFLAGS = -c -g -Wall -DI_AM_LINUX_HOST -I$(SCTPIXEL_DAQ_ROOT)/CommonWithDsp -D$(ROD_TYPE) \
        -I$(SCTPIXEL_DAQ_ROOT)/CommonForHosts \
        -I$(SCTPIXEL_DAQ_ROOT)/../VmeInterface \
        -I$(DAQ_SW_DIR)/include \
        -I$(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/Pixel \
        -I$(SCTPIXEL_DAQ_ROOT)/CommonWithDsp/Sct
        

all: libRodModule.so libTimModule.so libBocCard.so 

libRodModule.so: $(RODOBJS)
	ar -ru libRodModule.so $(RODOBJS) 

RodModule.o: RodModule.cxx RodModule.h RodVmeAddresses.h $(dspheader)
	g++ $(CFLAGS) -o RodModule.o RodModule.cxx

RodPrimitive.o: RodPrimitive.cxx RodPrimitive.h 
	g++ $(CFLAGS) -o RodPrimitive.o RodPrimitive.cxx

RodPrimList.o: RodPrimList.cxx RodPrimList.h 
	g++ $(CFLAGS) -o RodPrimList.o RodPrimList.cxx

RodOutList.o: RodOutList.cxx RodOutList.h
	g++ $(CFLAGS) -o RodOutList.o RodOutList.cxx

libTimModule.so: $(TIMOBJS)
	ar -ru libTimModule.so $(TIMOBJS)

TimModule.o: TimModule.cxx TimModule.h TimDefine.h $(dspheader)
	g++ $(CFLAGS) -o TimModule.o TimModule.cxx

libBocCard.so: $(BOCOBJS)
	ar -ru libBocCard.so $(BOCOBJS)

BocCard.o: BocCard.cxx BocCard.h BocAddresses.h $(dspheader)
	g++ $(CFLAGS) -o BocCard.o BocCard.cxx

.PHONY : clean
clean:
	-rm *.o *.so *.a *~ core

SRCS=$(wildcard *.cxx)
include $(SRCS:.cxx=.d)

%.d: %.cxx
	$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< | sed '\''s%\($(*F)\)\.o[ :]*%$(*D)/\1.o $@ : %g'\'' > $@; [ -s $@ ] || rm -f $@' && echo
