src/common/cockpitassets.h: src/common/cockpitassets.gresource.xml
	@$(MKDIR_P) $(dir $@)
	$(AM_V_GEN) glib-compile-resources --target=$@ --generate-header --sourcedir=$(dir $<) $<
src/common/cockpitassets.c: src/common/cockpitassets.gresource.xml src/common/fail.html
	@$(MKDIR_P) $(dir $@)
	$(AM_V_GEN) glib-compile-resources --target=$@ --generate-source --sourcedir=$(dir $<) $<

COCKPIT_ASSETS = \
       src/common/cockpitassets.h \
       src/common/cockpitassets.c \
       $(NULL)

BUILT_SOURCES += $(COCKPIT_ASSETS)
CLEANFILES += $(COCKPIT_ASSETS)

EXTRA_DIST += \
	src/common/mock-content \
	src/common/mock-stderr \
	src/common/cockpitassets.gresource.xml \
	src/common/fail.html \
	$(test_locale_PO) \
	$(NULL)

noinst_LIBRARIES += libcockpit-common-nodeps.a

# Code that has no dependencies other than libc
libcockpit_common_nodeps_a_SOURCES = \
	src/common/cockpitauthorize.c \
	src/common/cockpitauthorize.h \
	src/common/cockpitbase64.c \
	src/common/cockpitbase64.h \
	src/common/cockpitconf.h \
	src/common/cockpitconf.c \
	src/common/cockpitframe.c \
	src/common/cockpitframe.h \
	src/common/cockpithacks.h \
	src/common/cockpithex.c \
	src/common/cockpithex.h \
	src/common/cockpitjsonprint.c \
	src/common/cockpitjsonprint.h \
	src/common/cockpitmemory.c \
	src/common/cockpitmemory.h \
	src/common/cockpitwebcertificate.h \
	src/common/cockpitwebcertificate.c \
	$(NULL)

libcockpit_common_nodeps_a_CFLAGS = \
	-fPIC \
	$(NULL)

noinst_LIBRARIES += libcockpit-common.a

# Code that has other dependencies, like glib or libsystemd
libcockpit_common_a_SOURCES = \
	src/common/cockpitchannel.c \
	src/common/cockpitchannel.h \
	src/common/cockpitcontrolmessages.c \
	src/common/cockpitcontrolmessages.h \
	src/common/cockpiterror.h src/common/cockpiterror.c \
	src/common/cockpitflow.c \
	src/common/cockpitflow.h \
	src/common/cockpithacks-glib.h \
	src/common/cockpithash.c \
	src/common/cockpithash.h \
	src/common/cockpitjson.c \
	src/common/cockpitjson.h \
	src/common/cockpitlocale.c \
	src/common/cockpitlocale.h \
	src/common/cockpitloopback.c \
	src/common/cockpitloopback.h \
	src/common/cockpitmemfdread.c \
	src/common/cockpitmemfdread.h \
	src/common/cockpitmachinesjson.c \
	src/common/cockpitmachinesjson.h \
	src/common/cockpitpipe.c \
	src/common/cockpitpipe.h \
	src/common/cockpitpipetransport.c \
	src/common/cockpitpipetransport.h \
	src/common/cockpitsystem.c \
	src/common/cockpitsystem.h \
	src/common/cockpittemplate.c \
	src/common/cockpittemplate.h \
	src/common/cockpittest.c \
	src/common/cockpittest.h \
	src/common/cockpittransport.c \
	src/common/cockpittransport.h \
	src/common/cockpitunicode.c \
	src/common/cockpitunicode.h \
	src/common/cockpitunixfd.c \
	src/common/cockpitunixfd.h \
	src/common/cockpitunixsignal.c \
	src/common/cockpitunixsignal.h \
	src/common/cockpitversion.c \
	src/common/cockpitversion.h \
	src/common/cockpitwebfilter.h \
	src/common/cockpitwebfilter.c \
	src/common/cockpitwebinject.h \
	src/common/cockpitwebinject.c \
	src/common/cockpitwebresponse.h \
	src/common/cockpitwebresponse.c \
	src/common/cockpitwebserver.h \
	src/common/cockpitwebserver.c \
	$(NULL)

nodist_libcockpit_common_a_SOURCES = \
	$(COCKPIT_ASSETS) \
	$(NULL)

libcockpit_common_a_CFLAGS = \
	-fPIC \
	-DG_LOG_DOMAIN=\"cockpit-protocol\" \
	$(COCKPIT_CFLAGS) \
	$(NULL)

libcockpit_common_a_LIBS = \
	libcockpit-common.a \
	libcockpit-common-nodeps.a \
	libwebsocket.a \
	$(COCKPIT_LIBS) \
	$(NULL)

# -----------------------------------------------------------------------------
# TESTS

COCKPIT_CHECKS = \
	test-frame \
	test-hash \
	test-hex \
	test-json \
	test-jsonfds \
	test-locale \
	test-pipe \
	test-transport \
	test-channel \
	test-unixsignal \
	test-template \
	test-webresponse \
	test-webserver \
	test-webcertificate \
	test-config \
	test-unicode \
	test-version \
	test-system \
	test-base64 \
	test-authorize \
	$(NULL)

test_authorize_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_authorize_SOURCES = src/common/test-authorize.c
test_authorize_LDADD = libcockpit-common-nodeps.a libretest.a

test_base64_CFLAGS = $(COCKPIT_SESSION_CFLAGS)
test_base64_SOURCES = src/common/test-base64.c
test_base64_LDADD = libcockpit-common-nodeps.a libretest.a

test_channel_SOURCES = \
	src/common/test-channel.c \
	src/common/mock-pressure.c src/common/mock-pressure.h \
	src/common/mock-transport.c src/common/mock-transport.h
test_channel_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_channel_LDADD = $(libcockpit_common_a_LIBS)

test_frame_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_frame_SOURCES = src/common/test-frame.c
test_frame_LDADD = $(libcockpit_common_a_LIBS)

test_hash_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_hash_SOURCES = src/common/test-hash.c
test_hash_LDADD = $(libcockpit_common_a_LIBS)

test_hex_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_hex_SOURCES = src/common/test-hex.c
test_hex_LDADD = libretest.a $(libcockpit_common_a_LIBS)

test_json_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_json_SOURCES = src/common/test-json.c
test_json_LDADD = $(libcockpit_common_a_LIBS)

test_jsonfds_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_jsonfds_SOURCES = src/common/test-jsonfds.c
test_jsonfds_LDADD = $(libcockpit_common_a_LIBS)

test_locale_PO = \
	src/common/mock-locale/de_DE/LC_MESSAGES/test.po \
	src/common/mock-locale/zh_CN/LC_MESSAGES/test.po \
	$(NULL)

test_locale_MO = $(test_locale_PO:.po=.mo)

test_locale_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_locale_SOURCES = src/common/test-locale.c
test_locale_LDADD = $(libcockpit_common_a_LIBS)

# Tell make that we depend on these files being built here
src/common/test-locale.c: $(test_locale_MO)

test_pipe_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_pipe_SOURCES = src/common/test-pipe.c \
	src/common/mock-pressure.c src/common/mock-pressure.h
test_pipe_LDADD = $(libcockpit_common_a_LIBS)

test_system_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_system_SOURCES = src/common/test-system.c
test_system_LDADD = $(libcockpit_common_a_LIBS)

test_template_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_template_SOURCES = src/common/test-template.c
test_template_LDADD = $(libcockpit_common_a_LIBS)

test_transport_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_transport_SOURCES = src/common/test-transport.c \
	src/common/mock-transport.c src/common/mock-transport.h
test_transport_LDADD = $(libcockpit_common_a_LIBS)

test_unicode_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_unicode_SOURCES = src/common/test-unicode.c
test_unicode_LDADD = $(libcockpit_common_a_LIBS)

test_unixsignal_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_unixsignal_SOURCES = src/common/test-unixsignal.c
test_unixsignal_LDADD = $(libcockpit_common_a_LIBS)

test_version_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_version_SOURCES = src/common/test-version.c
test_version_LDADD = $(libcockpit_common_a_LIBS)

test_webresponse_SOURCES = \
	src/common/test-webresponse.c \
	src/common/mock-io-stream.c src/common/mock-io-stream.h \
	$(COCKPIT_ASSETS) \
	$(NULL)
test_webresponse_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_webresponse_LDADD = $(libcockpit_common_a_LIBS)

test_webserver_SOURCES = src/common/test-webserver.c
test_webserver_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_webserver_LDADD = $(libcockpit_common_a_LIBS)

test_webcertificate_SOURCES = src/common/test-webcertificate.c
test_webcertificate_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_webcertificate_LDADD = $(libcockpit_common_a_LIBS)

test_config_CFLAGS = $(libcockpit_common_a_CFLAGS)
test_config_SOURCES = src/common/test-config.c
test_config_LDADD = $(libcockpit_common_a_LIBS)

noinst_PROGRAMS += $(COCKPIT_CHECKS)
TESTS += $(COCKPIT_CHECKS)

# For the test-locale test
nodist_noinst_SCRIPTS += \
	src/common/mock-locale/de_DE/LC_MESSAGES/test.mo \
	src/common/mock-locale/zh_CN/LC_MESSAGES/test.mo \
	$(NULL)

# preload wrapper library for unit tests that need a temp home dir
# we don't use libtool, so build this manually
nodist_noinst_DATA += libpreload-temp-home.so
EXTRA_DIST += src/common/preload-temp-home.c

libpreload-temp-home.so: src/common/preload-temp-home.c
	$(AM_V_CCLD) $(CC) $(CFLAGS) -fPIC -shared -o $@ $^

CLEANFILES += \
	$(test_locale_MO) \
	libpreload-temp-home.so \
	$(NULL)
