#
#  Makefile for the DRS DAQ 
#
# Compiled and streamlined from original makefiles - O. Grimm, Nov 2008
# Use the VMECTRL flag to switch between different VME controllers: -DCT_VME
# for Concurrent Technologies, -DSTRUCK_VME for Struck

VMECTRL = -DCT_VME

CC  	= g++   	# Compiler to use

SOURCES = DAQReadout.cc RawDataCTX.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp ../Evidence/Evidence.cc 
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
INCDIRS   = -I. -IDRS -I../pixelmap -I../Evidence -I$(DIMDIR)/dim

REVISION = $(shell svnversion -n)

ifeq ($(VMECTRL),-DCT_VME)
 VMELIB = -L./VME/atlas/lib -lvme_rcc -lcmem_rcc -lrcc_time_stamp
 INCDIRS := $(INCDIRS) -I./VME/atlas/include/
else
 VMELIB = -L./VME/struck
 INCDIRS := $(INCDIRS) -I./VME/struck/
 OBJECTS := $(OBJECTS) ./VME/struck/sis3100.o ./VME/struck/sis3100_vme_calls.o
endif

CPPFLAGS = -DREVISION='"$(REVISION)"' -O3 -Wall $(VMECTRL)
LIBS = -lstdc++ -lz -lpthread -lutil -lfl -lreadline -ltermcap $(VMELIB) $(DIMDIR)/linux/libdim.a

drsdaq: $(OBJECTS)
	$(CC) $(CPPFLAGS) -Wl,-rpath,VME/atlas/lib -o $@ $(OBJECTS) $(LIBS)

clean:
	@rm -f $(OBJECTS)
	@rm -f *.d
	@rm -f *~

-include Dep.d
	
# Implicit rules

%.o : %.c
	$(CC) $(CPPFLAGS) $(INCDIRS) -c -o $@ $<
%.o : %.cc
	$(CC) $(CPPFLAGS) $(INCDIRS) -c -o $@ $<
%.o : %.cpp
	$(CC) $(CPPFLAGS) $(INCDIRS) -c -o $@ $< 
%.d : 
	@echo "Generating dependencies" $@
	@$(CC) -MM $(SOURCES) $(INCDIRS) \
	| sed 's/^\(.*\).o:/$@ \1.o:/' > $@
