# lastlog2.h is generated, so it's stored in builddir!
lastlog2incdir = $(includedir)/liblastlog2
nodist_lastlog2inc_HEADERS = liblastlog2/src/lastlog2.h

usrlib_exec_LTLIBRARIES += liblastlog2.la

liblastlog2_la_SOURCES = \
	liblastlog2/src/lastlog2.c \
	liblastlog2/src/lastlog2P.h

EXTRA_liblastlog2_la_DEPENDENCIES = \
	liblastlog2/src/liblastlog2.sym

liblastlog2_la_LIBADD = $(SQLITE3_LIBS)

liblastlog2_la_CFLAGS = \
	$(AM_CFLAGS) \
	 $(SOLIB_CFLAGS) \
	 -I$(ul_liblastlog2_incdir) \
	 -I$(top_srcdir)/liblastlog2/src

liblastlog2_la_LDFLAGS = $(SOLIB_LDFLAGS)
if HAVE_VSCRIPT
liblastlog2_la_LDFLAGS += $(VSCRIPT_LDFLAGS),$(top_srcdir)/liblastlog2/src/liblastlog2.sym
endif
liblastlog2_la_LDFLAGS += -version-info $(LIBLASTLOG2_VERSION_INFO)

EXTRA_DIST += liblastlog2/src/liblastlog2.sym


if BUILD_LIBLASTLOG2_TESTS
check_PROGRAMS += \
	test_lastlog2_dlopen \
	test_lastlog2_pam_lastlog2_output \
	test_lastlog2_remove_entry \
	test_lastlog2_rename_user \
	test_lastlog2_write_read_user \
	test_lastlog2_y2038_ll2_read_all \
	test_lastlog2_y2038_sqlite3_time

lastlog2_tests_cflags  = -DTEST_PROGRAM $(liblastlog2_la_CFLAGS)
lastlog2_tests_ldflags = -static
lastlog2_tests_ldadd   = $(LDADD) liblastlog2.la $(SOLIB_LDFLAGS) $(SQLITE3_LIBS)

test_lastlog2_dlopen_SOURCES = liblastlog2/src/tests/tst_dlopen.c
test_lastlog2_dlopen_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_dlopen_LDFLAGS = $(lastlog2_tests_ldflags) -ldl
test_lastlog2_dlopen_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_pam_lastlog2_output_SOURCES = liblastlog2/src/tests/tst_pam_lastlog2_output.c
test_lastlog2_pam_lastlog2_output_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_pam_lastlog2_output_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_pam_lastlog2_output_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_remove_entry_SOURCES = liblastlog2/src/tests/tst_remove_entry.c
test_lastlog2_remove_entry_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_remove_entry_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_remove_entry_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_rename_user_SOURCES = liblastlog2/src/tests/tst_rename_user.c
test_lastlog2_rename_user_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_rename_user_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_rename_user_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_write_read_user_SOURCES = liblastlog2/src/tests/tst_write_read_user.c
test_lastlog2_write_read_user_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_write_read_user_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_write_read_user_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_y2038_ll2_read_all_SOURCES = liblastlog2/src/tests/tst_y2038_ll2_read_all.c
test_lastlog2_y2038_ll2_read_all_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_y2038_ll2_read_all_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_y2038_ll2_read_all_LDADD = $(lastlog2_tests_ldadd)

test_lastlog2_y2038_sqlite3_time_SOURCES = liblastlog2/src/tests/tst_y2038_sqlite3_time.c
test_lastlog2_y2038_sqlite3_time_CFLAGS = $(lastlog2_tests_cflags)
test_lastlog2_y2038_sqlite3_time_LDFLAGS = $(lastlog2_tests_ldflags)
test_lastlog2_y2038_sqlite3_time_LDADD = $(lastlog2_tests_ldadd)

endif #BUILD_LIBLIBLASTLOG2_TESTS


# move lib from $(usrlib_execdir) to $(libdir) if needed
install-exec-hook-liblastlog2:
	if test "$(usrlib_execdir)" != "$(libdir)" -a -f "$(DESTDIR)$(usrlib_execdir)/liblastlog2.so"; then \
		$(MKDIR_P) $(DESTDIR)$(libdir); \
		mv $(DESTDIR)$(usrlib_execdir)/liblastlog2.so.* $(DESTDIR)$(libdir); \
		so_img_name=$$(readlink $(DESTDIR)$(usrlib_execdir)/liblastlog2.so); \
		so_img_rel_target=$$(echo $(usrlib_execdir) | sed 's,\(^/\|\)[^/][^/]*,..,g'); \
		(cd $(DESTDIR)$(usrlib_execdir) && \
			rm -f liblastlog2.so && \
			$(LN_S) $$so_img_rel_target$(libdir)/$$so_img_name liblastlog2.so); \
	fi

uninstall-hook-liblastlog2:
	rm -f $(DESTDIR)$(libdir)/liblastlog2.so*

INSTALL_EXEC_HOOKS += install-exec-hook-liblastlog2
UNINSTALL_HOOKS += uninstall-hook-liblastlog2
