summaryrefslogtreecommitdiff
path: root/src/src.am
blob: 1cfb837e5f60c6244be49660eb6d35e3b1775dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
src_cppflags = -I$(top_srcdir)/src

if ENABLE_GNOME_BLUETOOTH_PANEL
include $(top_srcdir)/src/gnome-bluetooth/gnome-bluetooth.am
src_cppflags += -I$(top_srcdir)/src/gnome-bluetooth
endif

if COND_GIO_GDBUS
include $(top_srcdir)/src/gdbusxx/gdbusxx.am
src_cppflags += -I$(top_srcdir)/src/gdbusxx
else
include $(top_srcdir)/src/gdbus/gdbus.am
src_cppflags += -I$(top_srcdir)/src/gdbus
endif

if COND_CORE
include $(top_srcdir)/src/syncevo/syncevo.am
src_cppflags += -I$(top_srcdir)/src/syncevo
include $(top_srcdir)/src/backends/backends.am
src_cppflags += $(addprefix -I$(top_srcdir)/,$(BACKENDS)) -I$(SYNTHESIS_SUBDIR)
bin_SCRIPTS += src/synccompare
include $(top_srcdir)/src/templates/templates.am
else
src_cppflags += -I$(top_srcdir)/$(SYNTHESIS_SUBDIR_INCLUDES)
endif
if COND_CMDLINE
bin_PROGRAMS += src/syncevolution
endif

include $(top_srcdir)/src/dbus/dbus.am
src_cppflags += -I$(top_srcdir)/src/dbus

include $(top_srcdir)/src/gtk-ui/gtk-ui.am
include $(top_srcdir)/src/gtk3-ui/gtk-ui.am

src_cppflags += -I$(top_srcdir)/test -I$(top_srcdir) $(BACKEND_CPPFLAGS)

DISTCLEANFILES += src/synccompare
CLEANFILES += src/libstdc++.a src/client-test $(CLIENT_LIB_TEST_FILES)

if COND_DBUS
nodist_bin_SCRIPTS += src/syncevo-http-server
endif
src/syncevo-http-server: $(top_srcdir)/test/syncevo-http-server.py
	$(AM_V_GEN)sed -e 's|\@PYTHON\@|$(PYTHON)|' $< > $@
CLEANFILES += src/syncevo-http-server

nodist_bin_SCRIPTS += src/syncevo-phone-config
src/syncevo-phone-config: $(top_srcdir)/test/syncevo-phone-config.py
	$(AM_V_GEN)sed -e 's|\@PYTHON\@|$(PYTHON)|' $< > $@
CLEANFILES += src/syncevo-phone-config

SYNCEVOLUTION_DEP =
if !ENABLE_MODULES
# SYNCEVOLUTION_LDADD is defined in configure script.
SYNCEVOLUTION_LDADD += @SYNCSOURCES@
SYNCEVOLUTION_DEP += @SYNCSOURCES@
endif
dist_noinst_DATA += \
  src/synthesis-includes/Makefile.am \
  src/synthesis-includes/Makefile.in

DISTCLEANFILES += src/synthesis-includes/Makefile

# synccompare is created by replacing its 'import Algorithm::Diff;'
# with a simplified copy of Diff.pm.
src/synccompare : $(top_srcdir)/test/Algorithm/Diff.pm $(top_srcdir)/test/synccompare.pl
	$(AM_V_GEN)perl -e '$$diff = shift; open(DIFF, "<$$diff"); ($$_) = split(/__END__/, join("", <DIFF>)); s/\*import.*//m; s/require +Exporter;//; s/^#.*\n//mg; s/ +#.*\n//mg; $$diff = $$_;' -e 'while(<>) {' @MODIFY_SYNCCOMPARE@ -e 's/use +Algorithm::Diff;/"# embedded version of Algorithm::Diff follows, copyright by the original authors\n" . $$diff . "# end of embedded Algorithm::Diff\n"/e; print;}' $+ >$@ \
	&&chmod u+x $@

# helper script for testing
bin_SCRIPTS += src/synclog2html
CLEANFILES += src/synclog2html
src/synclog2html: $(top_srcdir)/test/log2html.py
	$(AM_V_GEN)sed -e 's|\@PYTHON\@|$(PYTHON)|' $< > $@ && chmod u+x $@

CORE_SOURCES =

# The files which register backends have to be compiled into
# "client-test" and "syncevolution" in order to pull in the
# code from the libs which implement the backends.
#
# Unit testing also goes there.
#
# When using modules the registration is done inside the
# module and the register file is unnecessary. However, they
# still need to be included in "make dist".
if ENABLE_MODULES
dist_noinst_DATA += $(BACKEND_REGISTRIES)
else
CORE_SOURCES += $(BACKEND_REGISTRIES)
endif

CORE_CXXFLAGS = $(SYNTHESIS_CFLAGS) $(CPPUNIT_CFLAGS)
CORE_LDADD = $(SYNCEVOLUTION_LDADD) src/syncevo/libsyncevolution.la $(GLIB_LIBS) $(GTHREAD_LIBS) $(GOBJECT_LIBS) $(LIBS)
CORE_DEP = $(SYNCEVOLUTION_DEP) src/syncevo/libsyncevolution.la $(SYNTHESIS_DEP)
CORE_LD_FLAGS = -Wl,-uSyncEvolution_Module_Version -Wl,--export-dynamic $(CPPUNIT_LIBS) $(ADDITIONAL_LDFLAGS)

if ENABLE_ICALTZ_UTIL
# Force inclusion of our own ical replacement functions directly
# in the binaries. Otherwise the dynamic linker will still end up
# using the functions from libical.so.1.
CORE_LD_FLAGS += -Wl,-usyncevo_fetch_timezone src/syncevo/libsyncevo-icaltz-util-wrapper.la
endif

# Used when build syncevolution.org binaries to link statically
# against certain libraries with ABIs that changed between distros
# (libpcrecpp, libopenobex).
CORE_LDADD += $(EXTRACORELDADD)

# put link to static c++ library into current directory, needed if compiling with --enable-static-c++
src/libstdc++.a :
	$(AM_V_GEN)path=`$(CXX) $(CORE_LDADD) $(LD_FLAGS) -print-file-name=src/libstdc++.a` && ln -s $$path .

src_syncevolution_SOURCES = \
  src/syncevolution.cpp \
  $(CORE_SOURCES)

if ENABLE_UNIT_TESTS
nodist_src_syncevolution_SOURCES = test/test.cpp
endif

# SYNCEVOLUTION_LDADD will be replaced with libsyncebook.la/libsyncecal.la/libsyncsqlite.la
# if linking statically against them, empty otherwise;
# either way this does not lead to a dependency on those libs - done explicitly
src_syncevolution_LDADD = $(CORE_LDADD)
src_syncevolution_DEPENDENCIES = $(EXTRA_LTLIBRARIES) $(CORE_DEP)
if COND_DBUS
src_syncevolution_LDADD += $(gdbus_build_dir)/libgdbussyncevo.la
src_syncevolution_DEPENDENCIES += $(gdbus_build_dir)/libgdbussyncevo.la
endif
src_syncevolution_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(DBUS_LIBS)
src_syncevolution_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(DBUS_CFLAGS) $(SYNCEVO_WFLAGS)
src_syncevolution_CPPFLAGS = $(src_cppflags) -I$(gdbus_dir)

# include Synthesis in distribution: package only files in git if using a git checkout
#
# Need to run autogen.sh in $(distdir)-synthesis and not the final
# $(distdir)/src/synthesis because recent autotools do not copy
# files like config.sub when invoked in $(distdir)/src/synthesis
# (automake 1.11.5, autoconf 2.69), probably because they are
# found in a parent directory. However, these files are needed
# later on during the recursive libsynthesis configure+make.
all_dist_hooks += src_dist_hook
src_dist_hook:
	@set -x; [ ! '$(SYNTHESIS_SUBDIR)' ] || \
	rm -rf $(distdir)-synthesis && \
	mkdir -p $(distdir)-synthesis && \
	if test -d '$(SYNTHESIS_SRC)/.git'; \
	then \
	  ( ( cd '$(SYNTHESIS_SRC)' && git archive HEAD ) | ( cd '$(distdir)-synthesis' && tar xf - && $$SHELL autogen.sh && rm -rf autom4te.cache && find . -name .gitignore -delete ) ) && \
	  ( printf 'Creating synthesis ChangeLog... ' && \
	    ( ( cd '$(SYNTHESIS_SRC)' && \
	        echo '# Generated by configure.  Do not edit.' && \
	        githash=`git show-ref --head --hash | head -1` && \
	        echo "# git revision $$githash"  && \
	        echo "# git tag `git describe --tags $$githash`" && \
	        echo && \
	        '$(top_srcdir)/missing' --run perl '$(top_srcdir)/build/gen-changelog.pl' ) >ChangeLog.tmp ) && \
	    ( mv -f ChangeLog.tmp '$(distdir)-synthesis/ChangeLog' && \
	      printf 'synthesis ChangeLog done\n' ) || \
	    ( rm -f ChangeLog.tmp ; \
	      printf 'synthesis ChangeLog failed\n'; \
	      echo 'Failed to generate synthesis ChangeLog.' >&2 ) \
	  ); \
	elif test '$(SYNTHESIS_SRC)' != 'no-synthesis-source'; \
	then \
	  cp -a '$(SYNTHESIS_SRC)/'* '$(distdir)-synthesis' && \
	  for i in _build autom4te.cache; do [ ! -d "$(SYNTHESIS_SRC)/$$i" ] || chmod -R u+rwx "$(SYNTHESIS_SRC)/$$i"; done && \
	  find '$(distdir)-synthesis' -name '.libs' -o -name '*~' -o -name '.*' -o -name '*.o' -o -name '*.lo' -o -name 'CVS' -o -name '.svn' -o -name '.git' -o -name .gitignore -o -name 'autom4te.cache' -print0 | xargs -0 rm -rf; \
	fi && \
	mv '$(distdir)-synthesis' '$(distdir)/src/synthesis'

clean-local: testclean
	rm -rf src/testcases
	[ ! -L src/templates ] || rm src/templates

# files created during testing
testclean:
	rm -rf src/*.test.vcf src/*.log src/*.log.html src/*.tests src/*.diff src/*.dat src/*Client_Sync_*client.* src/*Client_Source*

distclean-local:
	rm -rf $(SYNTHESIS_SUBDIR)
	rm -rf $(CLEAN_CLIENT_SRC)

# Local sync helper executable. Depends on D-Bus for internal communication.
if COND_LOCAL_SYNC
libexec_PROGRAMS += src/syncevo-local-sync
src_syncevo_local_sync_SOURCES = \
	src/syncevo-local-sync.cpp \
	$(CORE_SOURCES)
if ENABLE_UNIT_TESTS
nodist_src_syncevo_local_sync_SOURCES = test/test.cpp
endif
src_syncevo_local_sync_LDADD = $(gdbus_build_dir)/libgdbussyncevo.la $(CORE_LDADD) $(DBUS_LIBS)
src_syncevo_local_sync_CPPFLAGS = -DHAVE_CONFIG_H -I$(gdbus_dir) $(src_cppflags)
src_syncevo_local_sync_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(SYNCEVO_WFLAGS)
src_syncevo_local_sync_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(LIBSOUP_LIBS)
src_syncevo_local_sync_DEPENDENCIES = $(top_builddir)/$(gdbus_build_dir)/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
endif

# Do the linking here, as with all SyncEvolution executables.
# Sources are compiled in dbus/server.
if COND_DBUS
# DBus Server
libexec_PROGRAMS += src/syncevo-dbus-server

src_syncevo_dbus_server_SOURCES = \
  $(CORE_SOURCES)
if ENABLE_UNIT_TESTS
nodist_src_syncevo_dbus_server_SOURCES = test/test.cpp
endif

src_syncevo_dbus_server_LDADD = $(builddir)/src/dbus/server/libsyncevodbusserver.la $(gdbus_build_dir)/libgdbussyncevo.la $(CORE_LDADD) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(DBUS_LIBS)
src_syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -I$(gdbus_dir) $(src_cppflags) -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\"
src_syncevo_dbus_server_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(SYNCEVO_WFLAGS)
src_syncevo_dbus_server_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS)
src_syncevo_dbus_server_DEPENDENCIES = $(builddir)/src/dbus/server/libsyncevodbusserver.la $(gdbus_build_dir)/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)

# syncevo-dbus-server's helper binary
libexec_PROGRAMS += src/syncevo-dbus-helper

if ENABLE_UNIT_TESTS
nodist_src_syncevo_dbus_helper_SOURCES = test/test.cpp
endif
src_syncevo_dbus_helper_SOURCES = \
  $(CORE_SOURCES)

src_syncevo_dbus_helper_LDADD = $(builddir)/src/dbus/server/libsyncevodbushelper.la $(gdbus_build_dir)/libgdbussyncevo.la $(CORE_LDADD) $(DBUS_LIBS)
src_syncevo_dbus_helper_CPPFLAGS = -DHAVE_CONFIG_H -I$(gdbus_dir) $(src_cppflags) -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\"
src_syncevo_dbus_helper_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(SYNCEVO_WFLAGS)
src_syncevo_dbus_helper_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS)
src_syncevo_dbus_helper_DEPENDENCIES = $(builddir)/src/dbus/server/libsyncevodbushelper.la $(gdbus_build_dir)/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
endif # COND_DBUS

# With --disable-shared autotools links against libfunambol.a which does not
# pull any of the test suites into the test binary, so they would not be
# executed. The workaround is to explicitly set them as undefined on the
# link line.
src_client_test_SOURCES = \
  src/client-test-app.cpp \
  test/ClientTest.cpp \
  test/ClientTest.h \
  test/ClientTestAssert.h \
  test/client-test-main.cpp \
  $(CORE_SOURCES)
nodist_src_client_test_SOURCES = test/test.cpp

# Compiling ClientTest.cpp with autotool's default CXXFLAGS (usually
# -g -O2) is expensive (due to many templates and the large file size)
# and unnecessary - it is much better for debugging when optimization
# is off.
#
# Therefore use GNU make's "Target-specific Variable Values" to
# override CXXFLAGS for that special file. We assume that the compiler
# knows the -g flag.
#
# We have to get the target name right. The worst that happens if we
# don't is that it gets compiled with the normal CXXFLAGS. Because
# we don't know if GNU make is used, use a configure check and only
# enable this when found during configure.
#
# Note that src_client_test_CXXFLAGS cannot be used to remove
# -O2, because CXXFLAGS comes later in the final compile command.
@ifGNUmake@ $(foreach e, $(foreach i, $(src_client_test_SOURCES), $(dir $(i))src_client_test-$(basename $(notdir $i))), $(e).o $(e).lo $(e).obj) : CXXFLAGS = -g

# List of test files which get copied verbatim from
# $(top_srcdir)/test/testcases/ to src/testcases below. test/test.am
# has the list for inclusion in "make dist" with the original
# "test/" directory. We need to replace that here.
#
# Generated files (testcases/eds_event.ics.funambol.tem) are derived from
# the original base file ($(srcdir)/test/testcases/eds_event.ics) by
# applying a patch ($(srcdir)/test/testcases/eds_event.ics.funambol.tem.patch).
CLIENT_LIB_TEST_FILES = $(subst test/,src/,$(test_testcases))

# all patch files
TEST_FILES_PATCHES = $(wildcard $(top_srcdir)/test/testcases/*.patch)
# generated local files
# converts from
# $(top_srcdir)/test/testcases/eds_contact.vcf.apple.tem.patch
# to
# src/testcases/eds_contact.vcf.apple.tem
TEST_FILES_GENERATED = $(subst .patch,,$(subst $(top_srcdir)/test/,src/,$(TEST_FILES_PATCHES)))
# all patched files, regardless whether the patch already exists
TEST_FILES_PATCHED = $(wildcard src/testcases/*.tem)
# add files created via patches
CLIENT_LIB_TEST_FILES += $(TEST_FILES_GENERATED)

# client-test must link against all static utility libs which might contain
# object files with SYNCEVOLUTION_TEST_SUITE_REGISTRATION() macros.
# To pull in those object files, LDFLAGS must contain undef statements
# for the C symbols exported by the macro.
src_client_test_libs = src/syncevo/libsyncevolution.la
if COND_DBUS
src_client_test_libs += src/dbus/server/libsyncevodbushelper.la src/dbus/server/libsyncevodbusserver.la
endif

# src/syncevo/libsyncevolution.la -> src/syncevo/.libs/libsyncevolution.a -> -Wl,-u...
src_client_test_undef = $(shell nm $(patsubst %.la,%.a,$(subst /lib,/.libs/lib,$(src_client_test_libs))) | grep funambolAutoRegisterRegistry | sed -e 's/.* /-Wl,-u/' )

src_client_test_CPPFLAGS = -DHAVE_CONFIG_H -DENABLE_INTEGRATION_TESTS -DENABLE_UNIT_TESTS $(src_cppflags) $(QT_CPPFLAGS)
src_client_test_CXXFLAGS = $(filter-out -O2, @CPPUNIT_CFLAGS@ $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(filter-out -O2 -g -W -Wall, $(QT_CXXFLAGS)) $(SYNCEVO_WFLAGS))
src_client_test_LDFLAGS = @CPPUNIT_LIBS@  $(src_client_test_undef) $(CORE_LD_FLAGS) $(QT_LDFLAGS)
src_client_test_LDADD = $(src_client_test_libs) $(CORE_LDADD) $(PCRECPP_LIBS) $(SYNTHESIS_ENGINE) $(QT_LIBS)

# These dependencies are intentionally a bit too broad:
# they ensure that all files are in place to *run* client-test.

# rule to generate patched files from patches:
# make cannot compute the dependencies completely, so run the commands
# on each make invocation and do the time stamp test ourselves
#
# If we create the patched file anew, then set its time to the more
# recent of the two input files. That way it won't be re-generated
# (because it is not older), and it won't be used to refresh the patch
# either in testcase2patch (because it is not newer either).
# That is useful on platforms where diff produces different results
# than the one in the source (possible because the "find shortest
# patch" problem may have multiple solutions).
all_phonies += $(TEST_FILES_GENERATED)
$(TEST_FILES_GENERATED):
	@ set -e \
	&& mkdir -p 'src/testcases' \
	&& echo 'checking whether server specific test case $@ is up-to-date'; \
	patchfile='$(top_srcdir)/test/$(subst src/,,$@).patch'; \
	basefile='$(top_srcdir)/test/$(subst src/,,$(basename $(basename $@)))'; \
	( [ -e '$@' ] && [ ! '$@' -ot "$$patchfile" ] && [ ! $@ -ot "$$basefile" ] && echo '   $@ up-to-date' ) || \
	( [ ! -s "$$patchfile" ] && echo "   copy $$basefile to $@ because patch file is empty" && cp "$$basefile" '$@' ) || \
	( echo "   generating $@ by applying $$patchfile to $$basefile" && \
	  (echo '*** foo'; echo '--- bar'; cat "$$patchfile") | patch -s -o '$@' "$$basefile" && \
	  ( if [ "$$basefile" -ot "$$patchfile" ]; then \
	    touch -r "$$patchfile" '$@'; else \
	    touch -r "$$basefile" '$@'; fi ) \
	)


# rule to regenerate patches:
# like generating the patched files, this is run every time.
# It must avoid making the patch file more recent than the
# patched file, otherwise the rule above would needlessly recreate
# it (not nice when having the file open in an editor).
#
# To avoid needlessly updating the content of the patch file,
# the first two lines with changing information (paths, file dates)
# are stripped from it.
all_phonies += testcase2patch
testcase2patch: $(TEST_FILES_GENERATED)
	@ set -e \
	&& echo 'checking whether test case patch files are up-to-date'; \
	for i in src/testcases/*.tem; do \
	  temfile=`echo "$$i" | cut -d / -f 2-` \
	  patchfile="$(top_srcdir)/test/$$temfile.patch"; \
	  basefile="$(top_srcdir)/test/`echo $$temfile | cut -d . -f  -2`"; \
	  if [ "$$patchfile" -ot "$$i" ] || [ "$$patchfile" -ot "$$basefile" ]; \
	  then \
	    diff -u "$$basefile" "$$i" | tail -n +3 > "$$patchfile" || true; \
	    touch -r "$$i" "$$patchfile"; \
	    echo "   updated $$patchfile"; \
	  else \
	    echo "   $$patchfile up-to-date"; \
	  fi; \
	done

# generate syntax-highlighted version of ClientTest.cpp for HTML
# version of .log test results
nodist_noinst_DATA += src/ClientTest.cpp.html
CLEANFILES += src/ClientTest.cpp.html
src/ClientTest.cpp.html: build/source2html.py test/ClientTest.cpp
	$(AM_V_GEN)$(PYTHON) $+ >$@

# copy base test files
$(filter-out %.tem, $(filter src/testcases/%, $(subst $(top_srcdir)/test/,src/,$(CLIENT_LIB_TEST_FILES)))) : src/% : $(top_srcdir)/test/%
	$(AM_V_at)mkdir -p '$(dir $@)'; \
	cp '$<' '$@'

# The binary does not really depend on the test cases, only running it does.
# Listing the dependencies here is done to ensure that one doesn't accidentally
# runs the binary with out-dated auxiliary files.
src_client_test_DEPENDENCIES = $(EXTRA_LTLIBRARIES) $(src_client_test_libs) $(CORE_DEP) $(CLIENT_LIB_TEST_FILES) testcase2patch src/synccompare src/synclog2html src/templates

# Copy template directory into current working directory, if not there
# yet. -ef flag checks whether device and inode numbers of both files
# are equal. If such check passes then it does mean that it is either
# the same file or one of them is symlink to another. So if this is a
# symlink, then it is fine - that is what we want. If this is the same
# file then also it is fine - that means that we built the project in
# the same directory as source.
all_phonies += src/templates
src/templates:
	$(AM_V_at)if test ! '$(top_srcdir)/src/templates' -ef '$(top_builddir)/src/templates'; \
	then \
	  rm -rf src/templates; \
	  ln -s '$(abs_top_srcdir)/src/templates' 'src/templates'; \
	fi

# distribute test system?
if ENABLE_TESTING
# yes: install client-test and test files in testdir
test_PROGRAMS += src/client-test
include $(top_srcdir)/src/testcases.am
else
# The "all" dependency causes a rebuild even if the actual input files
# haven't changed. If client-test is part of the regular targets built
# by "all", then it must not depend on all!
EXTRA_PROGRAMS += src/client-test
nodist_src_client_test_SOURCES += $(CLIENT_LIB_TEST_FILES)
src_client_test_DEPENDENCIES += all
endif

# test program for output redirection, has to be built
# and run manually
EXTRA_PROGRAMS += src/abort-redirect
CLEANFILES += src/abort-redirect.log
src_abort_redirect_SOURCES = test/abort-redirect.cpp
src_abort_redirect_CPPFLAGS = -DHAVE_CONFIG_H $(src_cppflags)
src_abort_redirect_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(SYNCEVO_WFLAGS)
src_abort_redirect_LDFLAGS = $(CORE_LD_FLAGS)
src_abort_redirect_LDADD = $(CORE_LDADD)
src_abort_redirect_DEPENDENCIES = all


# special target for testing with valgrind
valgrind : src/test
	valgrind --leak-check=yes --suppressions=valgrind.supp src/client-test

# old-style name for test program(s)
all_phonies += test valgrind
src/test: src/client-test