EXTRA_DIST += \
  src/dbus/server/pim/README \
  src/dbus/server/pim/pim-manager-api.txt \
  src/dbus/server/pim/examples/search.py \
  src/dbus/server/pim/examples/sync.py \
  src/dbus/server/pim/testpim.py \
  src/dbus/server/pim/test-dbus/db-active/config/syncevolution/pim-manager.ini \
  src/dbus/server/pim/test-dbus/simple-sort/config/syncevolution/pim-manager.ini \
  src/dbus/server/pim/test-dbus/first-last-sort/config/syncevolution/pim-manager.ini

if COND_DBUS

noinst_LTLIBRARIES += src/dbus/server/libsyncevodbusserver.la

src_dbus_server_server_cpp_files = \
  src/dbus/server/notification-backend-noop.cpp \
  src/dbus/server/notification-backend-libnotify.cpp \
  src/dbus/server/notification-backend-mlite.cpp \
  src/dbus/server/notification-manager-factory.cpp \
  src/dbus/server/auto-sync-manager.cpp \
  src/dbus/server/bluez-manager.cpp \
  src/dbus/server/client.cpp \
  src/dbus/server/connection.cpp \
  src/dbus/server/connman-client.cpp \
  src/dbus/server/dbus-callbacks.cpp \
  src/dbus/server/dbus-user-interface.cpp \
  src/dbus/server/exceptions.cpp \
  src/dbus/server/localed-listener.cpp \
  src/dbus/server/info-req.cpp \
  src/dbus/server/network-manager-client.cpp \
  src/dbus/server/presence-status.cpp \
  src/dbus/server/progress-data.cpp \
  src/dbus/server/read-operations.cpp \
  src/dbus/server/server.cpp \
  src/dbus/server/session.cpp

src_dbus_server_server_h_files = \
  $(src_dbus_server_server_cpp_files:.cpp=.h) \
  src/dbus/server/notification-backend-base.h \
  src/dbus/server/notification-manager.h \
  src/dbus/server/notification-manager-base.h \
  src/dbus/server/auto-term.h \
  src/dbus/server/cmdline-wrapper.h \
  src/dbus/server/resource.h \
  src/dbus/server/restart.h \
  src/dbus/server/session-common.h \
  src/dbus/server/source-progress.h \
  src/dbus/server/source-status.h \
  src/dbus/server/timeout.h \
  src/dbus/server/timer.h

src_dbus_server_libsyncevodbusserver_la_SOURCES = \
  $(src_dbus_server_server_h_files) \
  $(src_dbus_server_server_cpp_files) \
  src/dbus/server/main.cpp

nodist_src_dbus_server_libsyncevodbusserver_la_SOURCES =

dist_pkgdata_DATA += src/dbus/server/bluetooth_products.ini

src_dbus_server_libsyncevodbusserver_la_LDFLAGS =
src_dbus_server_libsyncevodbusserver_la_LIBADD = $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(DBUS_LIBS) $(PCRECPP_LIBS) $(ICU_LIBS)
src_dbus_server_libsyncevodbusserver_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) -I$(gdbus_dir) $(BACKEND_CPPFLAGS)
src_dbus_server_libsyncevodbusserver_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(SYNTHESIS_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(SYNCEVO_WFLAGS) $(ICU_CFLAGS)

if COND_DBUS_PIM
src_dbus_server_server_cpp_files += \
  src/dbus/server/pim/view.cpp \
  src/dbus/server/pim/full-view.cpp \
  src/dbus/server/pim/filtered-view.cpp \
  src/dbus/server/pim/edsf-view.cpp \
  src/dbus/server/pim/locale-factory.cpp \
  src/dbus/server/pim/merge-view.cpp \
  src/dbus/server/pim/individual-traits.cpp \
  src/dbus/server/pim/folks.cpp \
  src/dbus/server/pim/manager.cpp

src_dbus_server_server_h_files += \
  src/dbus/server/pim/persona-details.h

nodist_src_dbus_server_libsyncevodbusserver_la_SOURCES += \
  src/dbus/server/pim/locale-factory-@DBUS_PIM_PLUGIN@.cpp

src_dbus_server_libsyncevodbusserver_la_LDFLAGS += $(DBUS_PIM_PLUGIN_LDFLAGS)
src_dbus_server_libsyncevodbusserver_la_LIBADD += $(FOLKS_LIBS) $(DBUS_PIM_PLUGIN_LIBS) $(PHONENUMBERS_LIBS)
src_dbus_server_libsyncevodbusserver_la_CXXFLAGS += $(FOLKS_CFLAGS) $(DBUS_PIM_PLUGIN_CFLAGS) $(PHONENUMBERS_CFLAGS) $(DLT_CFLAGS)
endif

# Need to list all plugins here and not include the active one in the regular
# source list above, because "make dist" would only include the configured one.
EXTRA_DIST += \
  src/dbus/server/pim/locale-factory-boost.cpp

# Session helper: syncevo-dbus-helper 
noinst_LTLIBRARIES += src/dbus/server/libsyncevodbushelper.la

src_dbus_server_dbus_helper_cpp_files = \
  src/dbus/server/dbus-callbacks.cpp \
  src/dbus/server/dbus-sync.cpp \
  src/dbus/server/dbus-transport-agent.cpp \
  src/dbus/server/session-helper.cpp

src_dbus_server_dbus_helper_h_files = \
  $(src_dbus_server_dbus_helper_cpp_files:.cpp=.h) \
  src/dbus/server/cmdline-wrapper.h

src_dbus_server_libsyncevodbushelper_la_SOURCES = \
  $(src_dbus_server_dbus_helper_h_files) \
  $(src_dbus_server_dbus_helper_cpp_files) \
  src/dbus/server/session-common.h \
  src/dbus/server/sync-helper.cpp

src_dbus_server_libsyncevodbushelper_la_LIBADD = $(DBUS_LIBS)
src_dbus_server_libsyncevodbushelper_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) -I$(gdbus_dir) $(BACKEND_CPPFLAGS)
src_dbus_server_libsyncevodbushelper_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(SYNTHESIS_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(SYNCEVO_WFLAGS)

# Deal with .service, .desktop and startup script files.
CLEANFILES += \
  $(src_dbus_server_service_files) \
  $(src_dbus_server_systemd_files) \
  $(src_dbus_server_desktop) \
  $(src_dbus_server_script)

src_dbus_server_script_in = src/dbus/server/syncevo-dbus-server-startup.sh.in
src_dbus_server_script = $(src_dbus_server_script_in:.sh.in=.sh)
src_dbus_server_desktop_in = src/dbus/server/syncevo-dbus-server.desktop.in
src_dbus_server_desktop = $(src_dbus_server_desktop_in:.desktop.in=.desktop)
src_dbus_server_autostartdir = $(sysconfdir)/xdg/autostart
src_dbus_server_autostart_DATA = $(src_dbus_server_desktop)

libexec_SCRIPTS += $(src_dbus_server_script)
$(src_dbus_server_script): $(src_dbus_server_script_in)
	@sed -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@SYNCEVO_DBUS_SERVER_ARGS\@|$(SYNCEVO_DBUS_SERVER_ARGS)|" $< >$@
$(src_dbus_server_desktop): $(src_dbus_server_desktop_in)
	@sed -e "s|\@libexecdir\@|$(libexecdir)|" $< >$@

src_dbus_server_service_files_in = src/dbus/server/org.syncevolution.service.in
src_dbus_server_service_files = $(src_dbus_server_service_files_in:.service.in=.service)
src_dbus_server_servicedir = $(DBUS_SERVICES_DIR)
src_dbus_server_service_DATA = $(src_dbus_server_service_files)

src_dbus_server_systemd_files_in = src/dbus/server/syncevo-dbus-server.service.in
src_dbus_server_systemd_files = $(src_dbus_server_systemd_files_in:.service.in=.service)
src_dbus_server_systemddir = $(prefix)/lib/systemd/user
src_dbus_server_systemd_DATA = $(src_dbus_server_systemd_files)

# this works for both dbus and systemd service files
src/dbus/server/%.service: src/dbus/server/%.service.in
	@sed -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@SYNCEVO_DBUS_SERVER_ARGS\@|$(SYNCEVO_DBUS_SERVER_ARGS)|" $< >$@

if COND_DBUS_PIM
# this shares syncevo-dbus-server.service
src_dbus_server_service_files_in += \
  src/dbus/server/pim/org._01.pim.contacts.service.in

test_SCRIPTS += \
	src/dbus/server/pim/examples/search.py \
	src/dbus/server/pim/examples/sync.py \
	$(NOP)

if ENABLE_TESTING
test_SCRIPTS += \
	src/dbus/server/pim/testpim.py \
	$(NOP)

# It would be nice if we could use the nobase_ prefix here, but we
# can't because we want to replace parts of the path. Instead we have
# to spell out the desired install dir completely for each file.
src_dbus_server_testdbusdir = $(testdir)/test-dbus

src_dbus_server_testdbus_broken_configdir = $(src_dbus_server_testdbusdir)/broken-config/config/syncevolution
src_dbus_server_testdbus_broken_config_DATA = src/dbus/server/pim/test-dbus/broken-config/config/syncevolution/pim-manager.ini

src_dbus_server_testdbus_db_activedir = $(src_dbus_server_testdbusdir)/db-active/config/syncevolution
src_dbus_server_testdbus_db_active_DATA = src/dbus/server/pim/test-dbus/db-active/config/syncevolution/pim-manager.ini

src_dbus_server_testdbus_first_last_sortdir = $(src_dbus_server_testdbusdir)/first-last-sort/config/syncevolution
src_dbus_server_testdbus_first_last_sort_DATA = src/dbus/server/pim/test-dbus/first-last-sort/config/syncevolution/pim-manager.ini

src_dbus_server_testdbus_simple_sortdir = $(src_dbus_server_testdbusdir)/simple-sort/config/syncevolution
src_dbus_server_testdbus_simple_sort_DATA = src/dbus/server/pim/test-dbus/simple-sort/config/syncevolution/pim-manager.ini
endif # ENABLE_TESTING
endif # COND_DBUS_PIM

dist_noinst_DATA += \
  $(src_dbus_server_service_files_in) \
  $(src_dbus_server_systemd_files_in) \
  $(src_dbus_server_script_in) \
  $(src_dbus_server_desktop_in)

endif
