#
#  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 = HVFeedback.cc DAQReadout.cc RawDataCTX.cc SlowData.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
INCDIRS   = -I. -IDRS -I../pixelmap

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)"' -Wl,-rpath,VME/atlas/lib -O3 -Wall $(VMECTRL)
LIBS = -lstdc++ -lz -lpthread -lutil -lfl -lreadline -ltermcap $(VMELIB)

drsdaq: $(OBJECTS)
	$(CC) $(CPPFLAGS) -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:/' > $@
