if WITH_COCKPIT_SSH

# -----------------------------------------------------------------------------
# libcockpit-ssh.a: code used in cockpit-ssh and its tests

noinst_LIBRARIES += libcockpit-ssh.a

libcockpit_ssh_a_CPPFLAGS = \
	-DG_LOG_DOMAIN=\"cockpit-ssh\" \
	$(glib_CFLAGS) \
	$(json_glib_CFLAGS) \
	$(libssh_CFLAGS) \
	$(AM_CPPFLAGS)

libcockpit_ssh_a_LIBS = \
	libcockpit-ssh.a \
	$(libcockpit_common_a_LIBS) \
	$(libssh_LIBS) \
	$(NULL)

libcockpit_ssh_a_SOURCES = \
	src/ssh/cockpitsshoptions.c \
	src/ssh/cockpitsshoptions.h \
	src/ssh/cockpitsshrelay.h \
	src/ssh/cockpitsshrelay.c \
	$(NULL)

# -----------------------------------------------------------------------------
# cockpit-ssh

libexec_PROGRAMS += cockpit-ssh
cockpit_ssh_CPPFLAGS = $(libcockpit_ssh_a_CPPFLAGS)
cockpit_ssh_LDADD = $(libcockpit_ssh_a_LIBS)
cockpit_ssh_SOURCES = src/ssh/ssh.c

# -----------------------------------------------------------------------------
# C bridge config; Python bridge handles it internally

if WITH_OLD_BRIDGE
sshmanifestdir = $(datadir)/cockpit/ssh
dist_sshmanifest_DATA = src/ssh/manifest.json
endif

# -----------------------------------------------------------------------------
# mock-ssh

check_PROGRAMS += mock-sshd
mock_sshd_CPPFLAGS = $(libcockpit_ssh_a_CPPFLAGS) $(TEST_CPP)
mock_sshd_LDADD = $(libcockpit_ssh_a_LIBS) $(TEST_LIBS)
mock_sshd_SOURCES = src/ssh/mock-sshd.c

# -----------------------------------------------------------------------------
# Unit tests

dist_check_DATA += \
	src/ssh/mock_rsa_key \
	src/ssh/mock_ecdsa_key \
	src/ssh/test_rsa \
	src/ssh/test_rsa.pub \
	src/ssh/mock_known_hosts \
	src/ssh/mock-pid-cat \
	src/ssh/mock-config \
	src/ssh/invalid_known_hosts \
	$(NULL)

TEST_PROGRAM += test-sshbridge
test_sshbridge_CPPFLAGS = $(libcockpit_ssh_a_CPPFLAGS) $(TEST_CPP)
test_sshbridge_LDADD = $(libcockpit_ssh_a_LIBS) $(TEST_LIBS)
test_sshbridge_SOURCES = src/ssh/test-sshbridge.c

TEST_PROGRAM += test-sshoptions
test_sshoptions_CPPFLAGS = $(libcockpit_ssh_a_CPPFLAGS) $(TEST_CPP)
test_sshoptions_LDADD = $(libcockpit_ssh_a_LIBS) $(TEST_LIBS)
test_sshoptions_SOURCES = src/ssh/test-sshoptions.c

check_DATA += test_rsa_key
CLEANFILES += test_rsa_key
test_rsa_key: src/ssh/test_rsa
	$(AM_V_GEN) cp $< $@ && chmod 600 $@

update-known-hosts:
	cat $(srcdir)/src/ssh/mock_*.pub | \
		sed -ne 's/\(.*\) [^ ]\+$$/[localhost]:*,[127.0.0.1]:* \1/p' > \
			$(srcdir)/src/ssh/mock_known_hosts

endif
