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) \
   -O3 -Wall -Winit-self -Wpointer-arith -Wcast-align -Wextra -Wformat=2 \
   $(SVN_REVISION)

AM_CXXFLAGS = $(AM_CPPFLAGS) $(QT4_INCLUDES) \
   -Woverloaded-virtual -Wnon-virtual-dtor -Wshadow -std=c++0x

# -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 scheduler \
	triggerschedule \
	ftmctrl ftm \
	fadctrl fad \
	fscctrl fsc \
	chatclient chatserv \
	biasctrl \
	mcp \
	fitsdump

if HAS_GUI
bin_PROGRAMS += fact
if HAS_VIEWER
bin_PROGRAMS += viewer
endif
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 \
	dclient5 dserver2 \
	fitsloader fitsgrep \
	sched astro drivectrl \
	readfits
endif

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

if HAS_HELP2MAN
dist_man1_MANS = \
	dimctrl.man ftmctrl.man datalogger.man triggerschedule.man fitsdump.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/tokenstring.cxx \
	dim/src/discpp.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   = libTime.la libDim.la libDim++.la libTools.la libStateMachine.la 


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


chatserv_SOURCES = src/chatserv.cc src/LocalControl.h
chatserv_LDADD = libTools.la libStateMachine.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 libTime.la libTools.la libStateMachine.la \
    libConfiguration.la

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

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

fadctrl_SOURCES = src/fadctrl.cc src/LocalControl.h src/HeadersFAD.cc \
	src/EventBuilder.c src/EventBuilder.h
fadctrl_LDADD   = libDim.la libDim++.la  libDimExtension.la \
	libTime.la libTools.la libStateMachine.la \
    	libConfiguration.la

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

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

mcp_SOURCES = src/mcp.cc src/LocalControl.h
mcp_LDADD   = libDim.la libDim++.la  libDimExtension.la \
	libTime.la libTools.la libStateMachine.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 = libTools.la libStateMachine.la libTime.la \
	libDim.la libDim++.la libDimExtension.la libConfiguration.la


chatclient_SOURCES = src/chatclient.cc src/ChatClient.h
chatclient_LDADD = libTools.la libStateMachine.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 = libTools.la libStateMachine.la libTime.la libDim.la libDim++.la libConfiguration.la

datalogger_SOURCES = src/datalogger.cc src/LocalControl.h
if HAS_FITS
datalogger_SOURCES += src/Fits.cc
endif
datalogger_LDADD  = libDim.la libDim++.la libDimExtension.la \
	libTime.la libTools.la libStateMachine.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   = 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

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

#

if HAS_VIEWER

viewer_DIALOGS = \
	gui/RawEventsViewer/viewer.ui

viewer_QT_SOURCES = \
	gui/RawEventsViewer/RawEventsViewer.cc

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

endif

endif



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

EXTRA_DIST += $(DIALOGS) $(RESOURCES) 

fact_LDADD = $(ROOTLDFLAGS) $(ROOTGLIBS) $(QT4_LIB) $(QT4_LDFLAGS) -L. \
	libDim.la libDim++.la libDimExtension.la \
	libTools.la libTime.la libTools.la libStateMachine.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

viewer_LDADD = $(QT4_LIB) $(QT4_LDFLAGS) -L. -lQtOpenGL -lGLU

viewer_SOURCES = $(viewer_SRCADD) $(viewer_QT_SOURCES)



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

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)

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

# 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
