SUBDIRS = tests
CONFIG_CLEAN_FILES = *.loT *.rej *.orig

AM_CPPFLAGS = \
	-I${top_srcdir} \
	-I${top_srcdir}/src/library

check-recursive: libfapolicyd.la

sbin_PROGRAMS = fapolicyd fapolicyd-cli
if WITH_PERF_TEST
sbin_PROGRAMS += fapolicyd-perf-test
endif
libexec_PROGRAMS =

lib_LTLIBRARIES= libfapolicyd.la

fapolicyd_CFLAGS = -std=gnu11 -fPIE -DPIE -pthread -g -W -Wall -Wshadow -Wundef -Wno-unused-result -Wno-unused-parameter -D_GNU_SOURCE -DLIBEXECDIR='"$(libexecdir)"'
fapolicyd_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now  -static
fapolicyd_LDADD = libfapolicyd.la

fapolicyd_cli_CFLAGS = $(fapolicyd_CFLAGS)
fapolicyd_cli_LDFLAGS = $(fapolicyd_LDFLAGS)
fapolicyd_cli_LDADD = libfapolicyd.la

if WITH_PERF_TEST
fapolicyd_perf_test_CFLAGS = $(fapolicyd_CFLAGS)
fapolicyd_perf_test_LDFLAGS = $(fapolicyd_LDFLAGS)
fapolicyd_perf_test_LDADD = libfapolicyd.la
endif

libfapolicyd_la_SOURCES = \
	library/avl.c \
	library/avl.h \
	library/attr-lookup-metrics.c \
	library/attr-lookup-metrics.h \
	library/attr-sets.c \
	library/attr-sets.h \
	library/backend-manager.c \
	library/backend-manager.h \
	library/conf.h \
	library/database.c \
	library/database.h \
	library/database-internal.h \
	library/database-update.c \
	library/daemon-config.c \
	library/daemon-config.h \
	library/decision-config.c \
	library/decision-config.h \
	library/decision-context.h \
	library/decision-defer.c \
	library/decision-defer.h \
	library/decision-event.h \
	library/decision-timing.c \
	library/decision-timing.h \
	library/escape.c \
	library/escape.h \
	library/event.c \
	library/event.h \
	library/failure-action.c \
	library/failure-action.h \
	library/fapolicyd-defs.h \
	library/fapolicyd-backend.h \
	library/fd-fgets.c \
	library/fd-fgets.h \
	library/file.c \
	library/file.h \
	library/file-backend.c \
	library/gcc-attributes.h \
	library/llist.c \
	library/llist.h \
	library/lru.c \
	library/lru.h \
	library/message.c \
	library/message.h \
	library/nv.h \
	library/object-attr.c \
	library/object-attr.h \
	library/object.c \
	library/object.h \
	library/paths.h \
	library/policy.c \
	library/policy.h \
	library/policy-metrics.c \
	library/policy-metrics.h \
	library/process.c \
	library/process.h \
	library/queue.c \
	library/queue.h \
	library/rules.c \
	library/rules.h \
	library/subject-attr.c \
	library/subject-attr.h \
	library/subject.c \
	library/subject.h \
	library/stack.c \
	library/stack.h \
	library/string-util.c \
	library/string-util.h \
	library/trust-file.c \
	library/trust-file.h \
	library/filter.c \
	library/filter.h

if WITH_RPM
libfapolicyd_la_SOURCES += \
	library/rpm-backend.c

libexec_PROGRAMS += fapolicyd-rpm-loader

fapolicyd_rpm_loader_SOURCES = \
	handler/fapolicyd-rpm-loader.c

fapolicyd_rpm_loader_CFLAGS = $(fapolicyd_CFLAGS)
fapolicyd_rpm_loader_LDFLAGS = $(fapolicyd_LDFLAGS)
fapolicyd_rpm_loader_LDADD = libfapolicyd.la
endif

if WITH_DEB
libfapolicyd_la_SOURCES += library/deb-backend.c
libfapolicyd_la_LIBADD = -ldpkg -lmd
libexec_PROGRAMS += fapolicyd-deb-loader
fapolicyd_deb_loader_SOURCES = \
	handler/fapolicyd-deb-loader.c
fapolicyd_deb_loader_CFLAGS = $(fapolicyd_CFLAGS)
fapolicyd_deb_loader_LDFLAGS = $(fapolicyd_LDFLAGS)
fapolicyd_deb_loader_LDADD = libfapolicyd.la
fapolicyd_CFLAGS += -DLIBDPKG_VOLATILE_API
LIBS += -ldpkg -lmd
endif

if NEED_MD5
libfapolicyd_la_SOURCES += \
	library/md5-backend.c \
	library/md5-backend.h
endif

libfapolicyd_la_CFLAGS = $(fapolicyd_CFLAGS)
libfapolicyd_la_LDFLAGS = $(fapolicyd_LDFLAGS) -lpthread

fapolicyd_SOURCES = \
	daemon/fanotify-fs-error.c \
	daemon/fanotify-fs-error.h \
	daemon/fapolicyd.c \
	daemon/decision-worker.c \
	daemon/decision-worker.h \
	daemon/mounts.c \
	daemon/mounts.h \
	daemon/notify.c \
	daemon/notify.h \
	daemon/state-report.c \
	daemon/state-report.h \
	daemon/systemd-notify.c \
	daemon/systemd-notify.h \
	daemon/worker-health.c \
	daemon/worker-health.h

fapolicyd_cli_SOURCES = \
	cli/cli-privilege.c \
	cli/cli-privilege.h \
	cli/fapolicyd-cli.c \
	cli/file-cli.c \
	cli/file-cli.h \
	cli/ignore-mounts.c \
	cli/ignore-mounts.h \
	cli/rule-lint.c \
	cli/rule-lint.h

if WITH_PERF_TEST
fapolicyd_perf_test_SOURCES = \
	perf-test/fapolicyd-perf-test.c
endif
