#! /usr/bin/make -f

export DEB_CFLAGS_MAINT_APPEND += -fvisibility=hidden -fvisibility-inlines-hidden
export DEB_CXXFLAGS_MAINT_APPEND += -fvisibility=hidden -fvisibility-inlines-hidden
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Build with NDEBUG (i.e. no debug messages) unless noopt build was requested
ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
    export DEB_CFLAGS_MAINT_APPEND += -DNDEBUG
    export DEB_CXXFLAGS_MAINT_APPEND += -DNDEBUG
endif

DH_AUTO_ARGS = --parallel --buildsystem=cmake --builddirectory=builddir

override_dh_auto_configure:
	dh_auto_configure $(DH_AUTO_ARGS) -- \
		-DCMAKE_USE_RELATIVE_PATHS=ON -DWITH_ASF=ON -DWITH_MP4=ON \
		-DLIB_INSTALL_DIR:PATH=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_installdocs:
	dh_installdocs
	# Install bindings README
	if [ -d debian/libtag1v5 ]; then \
	    install -m644 -oroot -groot -T bindings/README debian/libtag1v5/usr/share/doc/libtag1v5/README.bindings; \
	fi;

# Generate docs when building indep
builddir/doc/html/index.html:
	# build-indep gets invoked in buildds as well...
	if [ -x /usr/bin/doxygen ]; then \
	    dh_auto_build --buildsystem=makefile --builddirectory=builddir -- docs; \
	fi

build-indep: builddir/doc/html/index.html

clean:
	# Clean documentation
	rm -rf builddir/doc/html
	dh clean

# All-in-one default dh rule
%:
	dh $@ --with=pkgkde-symbolshelper $(DH_AUTO_ARGS)
