
# libfdisk.h is generated, so it's stored in builddir!
fdiskincdir = $(includedir)/libfdisk
nodist_fdiskinc_HEADERS = libfdisk/src/libfdisk.h

usrlib_exec_LTLIBRARIES += libfdisk.la
libfdisk_la_SOURCES = \
	include/list.h \
	\
	libfdisk/src/fdiskP.h \
	libfdisk/src/init.c \
	libfdisk/src/field.c \
	libfdisk/src/item.c \
	libfdisk/src/test.c \
	libfdisk/src/ask.c \
	libfdisk/src/alignment.c \
	libfdisk/src/label.c \
	libfdisk/src/utils.c \
	libfdisk/src/context.c \
	libfdisk/src/parttype.c \
	libfdisk/src/partition.c \
	libfdisk/src/table.c \
	libfdisk/src/iter.c \
	libfdisk/src/script.c \
	libfdisk/src/version.c \
	libfdisk/src/wipe.c \
	\
	libfdisk/src/sun.c \
	libfdisk/src/sgi.c \
	libfdisk/src/dos.c \
	libfdisk/src/bsd.c \
	libfdisk/src/gpt.c

libfdisk_la_LIBADD = libcommon.la libuuid.la

libfdisk_la_CFLAGS = \
	$(AM_CFLAGS) \
	$(SOLIB_CFLAGS) \
	-I$(ul_libuuid_incdir) \
	-I$(ul_libfdisk_incdir) \
	-I$(top_srcdir)/libfdisk/src

EXTRA_libfdisk_la_DEPENDENCIES = \
	libfdisk/src/libfdisk.sym

libfdisk_la_LDFLAGS = $(SOLIB_LDFLAGS)
if HAVE_VSCRIPT
libfdisk_la_LDFLAGS += $(VSCRIPT_LDFLAGS),$(top_srcdir)/libfdisk/src/libfdisk.sym
endif
libfdisk_la_LDFLAGS += -version-info $(LIBFDISK_VERSION_INFO)


if BUILD_LIBBLKID
libfdisk_la_LIBADD += libblkid.la
libfdisk_la_CFLAGS += -I$(ul_libblkid_incdir)
endif

EXTRA_DIST += \
	libfdisk/src/libfdisk.sym

if BUILD_LIBFDISK_TESTS
check_PROGRAMS += \
	test_fdisk_ask \
	test_fdisk_gpt \
	test_fdisk_script \
	test_fdisk_utils \
	test_fdisk_version \
	test_fdisk_item

libfdisk_tests_cflags  = -DTEST_PROGRAM $(libfdisk_la_CFLAGS) $(NO_UNUSED_WARN_CFLAGS)
libfdisk_tests_ldflags = libuuid.la -static
libfdisk_tests_ldadd   = libfdisk.la $(LDADD)

if BUILD_LIBBLKID
libfdisk_tests_ldflags += libblkid.la
endif

test_fdisk_ask_SOURCES = libfdisk/src/ask.c
test_fdisk_ask_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_ask_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_ask_LDADD = $(libfdisk_tests_ldadd)

test_fdisk_gpt_SOURCES = libfdisk/src/gpt.c
test_fdisk_gpt_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_gpt_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_gpt_LDADD = $(libfdisk_tests_ldadd)

test_fdisk_utils_SOURCES = libfdisk/src/utils.c
test_fdisk_utils_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_utils_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_utils_LDADD = $(libfdisk_tests_ldadd)

test_fdisk_script_SOURCES = libfdisk/src/script.c
test_fdisk_script_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_script_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_script_LDADD = $(libfdisk_tests_ldadd)

test_fdisk_version_SOURCES = libfdisk/src/version.c
test_fdisk_version_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_version_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_version_LDADD = $(libfdisk_tests_ldadd)

test_fdisk_item_SOURCES = libfdisk/src/item.c
test_fdisk_item_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_item_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_item_LDADD = $(libfdisk_tests_ldadd)

endif # BUILD_LIBFDISK_TESTS


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

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

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

