#include aminclude.am

#-------------------------------------------------------------------------

ACLOCAL_AMFLAGS = -I .macro_dir

SVN_REVISION = -DREVISION=\"`svnversion -n .`\"

DIM_FLAGS    = -DMIPSEL -DPROTOCOL=1 -Dunix -Dlinux
BOOST_FLAGS  = -DBOOST_DISABLE_ASSERTS

AM_CPPFLAGS = -Idim/dim $(DIM_FLAGS) $(BOOST_FLAGS) $(ROOTCPPFLAGS) \
   -Wall -Winit-self -Wpointer-arith -Wcast-align -Wextra -Wformat=2 \
   $(SVN_REVISION)

AM_CXXFLAGS = $(AM_CPPFLAGS) \
   -Woverloaded-virtual -Wnon-virtual-dtor -Wshadow

# -no-undefined
AM_LDFLAGS = -module -avoid-version

#$(man3_MANS): doxygen-doc
#DX_CLEANFILES = everything to clean.
# Add to MOSTLYCLEANFILES.

#-------------------------------------------------------------------------

# Executables which are build by default ('all')
bin_PROGRAMS = \
	dns \
	log logtime time argv \
	dimctrl \
	datalogger \
	ftmctrl ftm \
	fadctrl fad \
	fscctrl fsc \
	chatclient chatserv \
	biasctrl drivectrl \
	mcp feedback ratescan ratecontrol \
	magicweather \
	smartfact \
	timecheck \
	fitsdump fitscheck 

if HAS_GUI
bin_PROGRAMS += fact
endif

if HAS_SOPRANO
bin_PROGRAMS += tngweather
endif

if HAS_DBUS
bin_PROGRAMS += skypeclient
endif

if HAS_VIEWER
bin_PROGRAMS += viewer
endif

if HAS_LIBXP
bin_PROGRAMS += did
endif

# This is a trick to be able to build them but not having them in 'all'
if IS_FALSE
bin_PROGRAMS += \
	test scheduler \
	triggerschedule \
	dclient5 dserver2 \
	fitsloader fitsgrep \
	sched astro drivectrl \
	readfits
endif

lib_LTLIBRARIES = \
	libDim++.la libDim.la libDimExtension.la \
	libConfiguration.la libStateMachine.la libTime.la libTools.la
# 	libAstro.la

if HAS_HELP2MAN
dist_man1_MANS = \
	dimctrl.man \
	ftmctrl.man \
	fadctrl.man \
	fscctrl.man \
	mcp.man \
	feedback.man \
	ratescan.man \
	biasctrl.man \
	drivectrl.man \
	datalogger.man \
	fitsdump.man \
	fitscheck.man \
	smartfact.man
	timecheck.man
endif

#-------------------------------------------------------------------------

CLEANFILES =

dist_noinst_SCRIPTS = autogen.sh

EXTRA_DIST = \
	Doxyfile \
	dim/DIM_Performance.pdf \
	dim/LICENSE.GPL \
	dim/README.txt \
	dim/README_v9.txt \
	dim/README_v10.txt \
	dim/README_v11.txt \
	dim/README_v12.txt \
	dim/README_v13.txt \
	dim/README_v14.txt \
	dim/README_v17.txt \
	dim/README_v16.txt \
	dim/README_v17.txt \
	dim/README_v18.txt \
	dim/README_v19.txt

dns_LDADD    = libDim.la libDimExtension.la
dns_SOURCES  = src/dns.c
#dns_CPPFLAGS = $(AM_CPPFLAGS) $(DIM_FLAGS)

did_LDADD    = libDim.la 
did_CPPFLAGS = $(AM_CPPFLAGS) -Idim/src/did 
did_SOURCES  = \
	dim/src/did/did.c dim/src/did/did.h \
	dim/src/did/dui_util.c dim/src/did/dui_util.h \
	dim/src/did/dui_colors.h


#libDim_la_CPPFLAGS = $(AM_CPPFLAGS) $(DIM_FLAGS)
libDim_ladir = 
libDim_la_HEADERS = \
	dim/dim/dic.h \
	dim/dim/dim_common.h \
	dim/dim/dim.h \
	dim/dim/dim_tcpip.h \
	dim/dim/dis.h 

libDim_la_SOURCES = \
	dim/src/dic.c \
	dim/src/dis.c \
	dim/src/dna.c \
	dim/src/sll.c \
	dim/src/dll.c  \
	dim/src/hash.c \
	dim/src/swap.c \
	dim/src/copy_swap.c \
	dim/src/open_dns.c \
	dim/src/conn_handler.c \
	dim/src/tcpip.c \
	dim/src/dtq.c \
	dim/src/dim_thr.c \
	dim/src/utilities.c

libDimExtension_la_SOURCES = src/DimSetup.cc src/DimSetup.h

#libDimCpp_la_CXXFLAGS = $(AM_CXXFLAGS) $(DIM_FLAGS)
libDim___ladir =
libDim___la_HEADERS = \
	dim/dim/dic.hxx \
	dim/dim/dis.hxx \
	dim/dim/dim_core.hxx \
	dim/dim/dim.hxx \
	dim/dim/dim_tcpip.h \
	dim/dim/dllist.hxx \
	dim/dim/sllist.hxx \
	dim/dim/tokenstring.hxx \
	src/Dim.h
libDim___la_SOURCES = \
	dim/src/diccpp.cxx \
	dim/src/dimcpp.cxx \
	dim/src/discpp.cxx \
	dim/src/tokenstring.cxx 

# Divide into Readline / StateMachine / StateMachineDim / Tools?
libStateMachine_la_SOURCES = \
	src/WindowLog.h       src/WindowLog.cc \
	src/Readline.h        src/Readline.cc \
	src/ReadlineColor.h   src/ReadlineColor.cc \
	src/ReadlineWindow.h  src/ReadlineWindow.cc \
	src/Console.h         src/Console.cc \
	src/Shell.h           src/Shell.cc \
	\
	src/EventImp.h        src/EventImp.cc \
	src/Event.h           src/Event.cc \
	src/State.h           src/State.cc \
	src/Description.h     src/Description.cc \
	src/MessageImp.h      src/MessageImp.cc \
	src/Converter.h       src/Converter.cc \
	src/StateMachineImp.h src/StateMachineImp.cc \
	src/StateMachine.h    src/StateMachine.cc \
	\
	src/EventDim.h \
	src/MessageDim.h         src/MessageDim.cc \
	src/StateMachineDim.h    src/StateMachineDim.cc \
	src/DimServerList.h      src/DimServerList.cc \
	src/DimServiceInfoList.h src/DimServiceInfoList.cc \
	src/DimNetworkList.h     src/DimNetwork.cc \
	src/ServiceList.h        src/ServiceList.cc \
	src/DimErrorRedirecter.h  \
	src/DimErrorRedirecter.cc \
	src/DimDescriptionService.h \
	src/DimDescriptionService.cc \
	\
	src/Connection.h      src/Connection.cc \
	src/ConnectionUSB.h   src/ConnectionUSB.cc \
	\
	FACT.h ByteOrder.h \
	\
	src/DimWriteStatistics.h src/DimWriteStatistics.cc

libConfiguration_la_SOURCES = \
	src/Configuration.h src/Configuration.cc \
	src/FACT.h src/FACT.cc

libTime_la_SOURCES  = src/Time.h src/Time.cc
#libAstro_la_SOURCES = src/Astro.h src/Astro.cc
libTools_la_SOURCES = src/tools.h src/tools.cc


dserver2_SOURCES = src/dserver2.cc 
dserver2_LDADD   = libTime.la libTools.la

ftm_SOURCES = src/ftm.cc src/HeadersFTM.cc
ftm_LDADD   = libTime.la libTools.la libDim++.la libDim.la libConfiguration.la libDimExtension.la

fad_SOURCES = src/fad.cc src/HeadersFAD.cc
fad_LDADD   = libTime.la libTools.la libTools.la libDim++.la libDim.la libConfiguration.la libDimExtension.la

fsc_SOURCES = src/fsc.cc
fsc_LDADD   = libTime.la libTools.la


log_SOURCES = src/log.cc
log_LDADD   = libDim++.la libDim.la libStateMachine.la libTime.la libTools.la


logtime_SOURCES = src/logtime.cc
logtime_LDADD = libStateMachine.la libTools.la libTime.la libDim++.la libDim.la


chatserv_SOURCES = src/chatserv.cc src/LocalControl.h
chatserv_LDADD = libStateMachine.la libTools.la libConfiguration.la libTime.la \
	libDim++.la libDim.la libDimExtension.la


dclient5_SOURCES = src/dclient5.cc src/LocalControl.h
dclient5_LDADD   = libDim++.la libDim.la libStateMachine.la libTime.la libTools.la \
    libConfiguration.la

ftmctrl_SOURCES = src/ftmctrl.cc src/LocalControl.h src/HeadersFTM.cc
ftmctrl_LDADD   = libDim++.la libDim.la libDimExtension.la \
	libStateMachine.la libTime.la libTools.la \
	libConfiguration.la

drivectrl_SOURCES = src/drivectrl.cc src/LocalControl.h src/HeadersFTM.cc
drivectrl_LDADD   = libDim++.la libDim.la libDimExtension.la \
 	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

magicweather_SOURCES = src/magicweather.cc src/LocalControl.h
magicweather_LDADD   = libDim++.la libDim.la libDimExtension.la \
 	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

tngweather_SOURCES = src/tngweather.cc src/LocalControl.h
tngweather_LDADD   = libDim++.la libDim.la libDimExtension.la \
 	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

timecheck_SOURCES = src/timecheck.cc src/LocalControl.h
timecheck_LDADD   = libDim++.la libDim.la libDimExtension.la \
 	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

smartfact_SOURCES = src/smartfact.cc src/LocalControl.h src/PixelMap.cc
smartfact_LDADD   = libDim++.la libDim.la libDimExtension.la \
 	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

fadctrl_SOURCES = src/fadctrl.cc src/LocalControl.h src/HeadersFAD.cc \
	src/EventBuilder.c      src/EventBuilder.h \
	src/DataProcessorImp.cc src/DataProcessorImp.h \
	src/DataCalib.cc        src/DataCalib.h \
	src/DataWriteRaw.cc     src/DataWriteRaw.h \
	src/DrsCalib.h
if HAS_FITS
fadctrl_SOURCES += src/FitsFile.h src/FitsFile.cc \
	src/DataWriteFits.cc    src/DataWriteFits.h \
	src/DataWriteFits2.cc    src/DataWriteFits2.h
endif
fadctrl_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

fscctrl_SOURCES = src/fscctrl.cc src/LocalControl.h
fscctrl_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

biasctrl_SOURCES = src/biasctrl.cc src/LocalControl.h src/PixelMap.cc
biasctrl_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

mcp_SOURCES = src/mcp.cc src/LocalControl.h
mcp_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

feedback_SOURCES = src/feedback.cc src/LocalControl.h src/PixelMap.cc
feedback_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

ratescan_SOURCES = src/ratescan.cc src/LocalControl.h src/PixelMap.cc
ratescan_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

ratecontrol_SOURCES = src/ratecontrol.cc src/LocalControl.h src/PixelMap.cc
ratecontrol_LDADD   = libDim++.la libDim.la  libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la


argv_SOURCES = src/argv.cc
argv_LDADD = libConfiguration.la


dimctrl_SOURCES = src/dimctrl.cc src/RemoteControl.cc src/RemoteControl.h
dimctrl_LDADD = libStateMachine.la libTools.la libTime.la \
	libDim++.la libDim.la libDimExtension.la libConfiguration.la


chatclient_SOURCES = src/chatclient.cc src/ChatClient.h
chatclient_LDADD = libStateMachine.la libTools.la libTime.la \
	libDim++.la libDim.la libDimExtension.la libConfiguration.la

skypeclient_SOURCES = src/skypeclient.cc src/ChatClient.h
skypeclient_LDADD = libStateMachine.la libTools.la libTime.la \
	libDim++.la libDim.la libDimExtension.la libConfiguration.la


time_SOURCES = src/time.cc
time_LDADD = libTime.la 

#astro_SOURCES = src/astro.cc
#astro_LDADD = libAstro.la libTime.la 

test_SOURCES = src/test.cc
test_LDADD = libStateMachine.la libTools.la libTime.la libDim++.la libDim.la libConfiguration.la

datalogger_SOURCES = src/datalogger.cc src/LocalControl.h
if HAS_FITS
datalogger_SOURCES += src/FitsFile.h src/FitsFile.cc src/Fits.h src/Fits.cc
endif
datalogger_LDADD  = libDim++.la libDim.la libDimExtension.la \
	libStateMachine.la libTools.la libTime.la \
    	libConfiguration.la

scheduler_SOURCES = src/scheduler.cc src/LocalControl.h 
scheduler_LDADD   = libStateMachine.la libTools.la libTime.la \
	libDim++.la libDim.la libDimExtension.la libConfiguration.la

fitsloader_SOURCES = src/fitsloader.cc src/LocalControl.h 
fitsloader_LDADD   = libStateMachine.la libTools.la libTime.la libDim++.la libDim.la libConfiguration.la

fitsdump_SOURCES = src/fitsdump.cc 
fitsdump_LDADD   = $(ROOTLDFLAGS) $(ROOTLIBS) libConfiguration.la libTime.la

fitscheck_SOURCES = src/fitscheck.cc 
fitscheck_LDADD   = libConfiguration.la


readfits_SOURCES = src/readfits.cc src/ReadFits.h
readfits_LDADD   = libStateMachine.la libTools.la libTime.la libDim++.la libDim.la libConfiguration.la

triggerschedule_SOURCES = src/triggerschedule.cc 
triggerschedule_LDADD   = libDim++.la libDim.la libDimExtension.la libConfiguration.la

#fitsgrep_SOURCES = src/fitsgrep.cc
#fitsgrep_LDADD   = libConfiguration.la

# -----

if HAS_GUI

fact_DIALOGS = \
	gui/design.ui

fact_RESOURCES = \
	gui/design.qrc

fact_QT_SOURCES = \
	gui/DockWindow.cc \
	gui/MainWindow.cc \
	gui/QCameraWidget.cc \
	gui/BasicGlCamera.cc

fact_SRCADD = $(fact_DIALOGS:.ui=.h) $(fact_RESOURCES:.qrc=.cc) $(fact_QT_SOURCES:.cc=.moc.cc)

endif

# -----

if HAS_VIEWER

viewer_DIALOGS = \
	gui/RawEventsViewer/viewer.ui

viewer_QT_SOURCES = \
	gui/RawEventsViewer/RawEventsViewer.cc \
	gui/BasicGlCamera.cc \
	gui/QCameraWidget.cc

viewer_SRCADD = $(viewer_DIALOGS:.ui=.h) $(viewer_RESOURCES:.qrc=.cc) $(viewer_QT_SOURCES:.cc=.moc.cc)

endif



BUILT_SOURCES = $(fact_SRCADD) $(viewer_SRCADD)
	
CLEANFILES += $(BUILT_SOURCES)

EXTRA_DIST += \
	$(fact_DIALOGS) $(fact_RESOURCES) \
	$(viewer_DIALOGS) $(viewer_RESOURCES) 

fact_LDADD = $(ROOTLDFLAGS) $(ROOTGLIBS) $(QT4_LIB) $(QT4_LDFLAGS) -L. \
	libDim++.la libDim.la libDimExtension.la \
	libTools.la libStateMachine.la libTime.la libTools.la \
	libConfiguration.la

fact_SOURCES = $(fact_SRCADD) $(fact_QT_SOURCES) \
	gui/CheckBoxDelegate.cc gui/HtmlDelegate.cc \
	gui/fact.cc gui/FactGui.cc src/HeadersFTM.cc \
	src/PixelMap.cc

# Switch off most qwt warnings
viewer_CXXFLAGS = $(AM_CXXFLAGS) -Wno-shadow

viewer_LDADD = $(QT4_LIB) $(QT4_LDFLAGS) -L. -lQtOpenGL -lGLU \
	libDimExtension.la \
	libConfiguration.la libStateMachine.la libTools.la \
	libTime.la libDim++.la libDim.la 

viewer_SOURCES = $(viewer_SRCADD) $(viewer_QT_SOURCES) \
	src/DataProcessorImp.cc src/DataProcessorImp.h \
	src/FitsFile.cc  src/FitsFile.h \
	src/Fits.cc      src/Fits.h \
	src/PixelMap.cc



#-------------------------------------------------------------------------

SUFFIXES = .moc.cc

.ui.h: $<
	$(AM_V_GEN)$(UIC4) $< -o $@

.h.moc.cc: $<
	$(AM_V_GEN)$(MOC4) $(EXTRA_CPPFLAGS) $< -o $@

.qrc.cc: $<
	$(AM_V_GEN)$(RCC4) -name `echo "$<" | sed 's|^.*/\(.*\)\.qrc$$|\1|'` $< -o $@


#-------------------------------------------------------------------------

MAN_TARGETS = $(dist_man1_MANS)

if HAS_GROFF

MAN_TARGETS += $(dist_man1_MANS:.man=.html)
EXTRA_DIST  += $(dist_man1_MANS:.man=.html) 
CLEANFILES  += $(dist_man1_MANS:.man=.html) 

if HAS_PS2PDF

MAN_TARGETS += $(dist_man1_MANS:.man=.pdf)
EXTRA_DIST  += $(dist_man1_MANS:.man=.pdf)
CLEANFILES  += $(dist_man1_MANS:.man=.pdf)
endif

endif

$(dist_man1_MANS): $(dist_man1_MANS:.man=)
	@mkdir -p man
	$(AM_V_GEN)help2man -N -o $@ -m $(@:.man=) ./$(@:.man=)

.man.html: $<
	$(AM_V_GEN)groff -mandoc `man -w -l $<` -T html > $@

.man.pdf: $<
	$(AM_V_GEN)groff -mandoc `man -w -l $<` | ps2pdf - $@

man: $(MAN_TARGETS) doxygen-doc

diff:
	@svn diff | $(COLORDIFF)
	@svn diff externals | $(COLORDIFF)

#-------------------------------------------------------------------------

# Overwrite rules for silent or other verbosity levels
#AM_V_MAN = $(AM_MAN_$(V))
#AM_MAN_ = $(AM_V_GEN)
#AM_MAN_0 = @echo  "  MAN    "$@;

#$(MyAnalysisDS): $(MyAnalysisH) $(MyAnalysisL)
#	$(ROOTCINT) -f $@ -c -I$(top_builddir)/config $(INCLUDES) $^
#	rootcint_files=`echo $@ | sed -ne 's/\(.*\)\..*/\1.cxx \1.h/p'` && \
#        $(top_srcdir)/config/runsed $(top_srcdir)/config/rootcint.sed $$rootcint_files && \
#        for i in $$rootcint_files; do \
#          if test ! `diff $$i $(srcdir)/$$i >/dev/null 2>&1`; then \
#            cp $$i $(srcdir)/; \
#          fi; \
#        done

#CLEANFILES = *~ *.rej *.orig
#MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in \
#        stamp-h.in stamp-h[0-9].in
#DISTCLEANFILES = config.cache config.log
