#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

CONFIGURE_OPTIONS = --with-gtk=3

ifneq ($(filter stage1,$(DEB_BUILD_PROFILES)),)
CONFIGURE_OPTIONS += --with-extra-only
else
CONFIGURE_OPTIONS += --enable-udisks
ifeq ($(filter nodoc,$(DEB_BUILD_OPTIONS)),)
ifneq ($(filter libfm-doc,$(shell dh_listpackages)),)
CONFIGURE_OPTIONS += --enable-gtk-doc
endif
endif
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTIONS)

override_dh_auto_install:
	dh_auto_install

	# split extra headers
	mkdir -p debian/libfm-extra-dev/usr/include/libfm-1.0
	for file in fm-extra.h fm-version.h fm-xml-file.h; do \
		mv debian/tmp/usr/include/libfm-1.0/$$file debian/libfm-extra-dev/usr/include/libfm-1.0/; \
	done

	# removing unused files
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.a
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.la

override_dh_install:
ifneq ($(filter nodoc,$(DEB_BUILD_OPTIONS)),)
	# in nodoc mode no documentation will be installed
	mkdir -p debian/tmp/usr/share/gtk-doc/html/libfm
endif
	dh_install

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_makeshlibs:
	# modules are not shared libs so disable processing for them
	dh_makeshlibs -X/modules/

ifneq ($(filter stage1,$(DEB_BUILD_PROFILES)),)
override_dh_auto_test:
	# will not work for stage1
endif