#!/usr/bin/make -f

include  /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
	    -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
	    -DCMAKE_INSTALL_PREFIX=/usr \
	    -DBUNDLE_DOCS=OFF \
            -DBUNDLE_TCDATA=ON \
            -DBUNDLE_GSHHS=CRUDE \
            -DBUILD_SHARED_LIBS=OFF \
            -DUSE_BUNDLED_LIBS=OFF \
            -DOCPN_NEW_SERIAL=OFF \
            -DOCPN_FORCE_GTK3=ON

override_dh_auto_install:
	dh_auto_install
	# Remove generated files without source.
	rm -rf debian/tmp/usr/share/opencpn/doc/opencpn
	# Move plugin documentation to proper location
	-mv debian/tmp/usr/share/opencpn/sounds/README.bells \
	    debian/tmp/usr/share/opencpn/tcdata/README.harmonics \
	    debian/tmp/usr/share/doc/opencpn
	# Use existing license files instead of bundled copy
	rm -f debian/tmp/usr/share/doc/opencpn/license.txt
	ln -s /usr/share/common-licenses/GPL-2 \
	    debian/tmp/usr/share/doc/opencpn/license.txt


override_dh_missing:
	dh_missing --fail-missing

# Work around what's seemingly a tar bug, see
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=831870

VERSION     = $(word 1,$(subst +, ,$(DEB_VERSION_UPSTREAM)))

get-orig-source:
	rm -rf utmp; mkdir utmp
	uscan  --destdir=utmp  --force-download --safe \
	    --download-version=$(VERSION)
	cd utmp; \
	    rm -rf $$(find . -mindepth 1 -maxdepth 1 -type d); \
	    tar xaf *-*.tar.*z; \
	    test -d OpenCPN-$(VERSION) || \
	        mv $$(find . -mindepth 1 -maxdepth 1 -type d) \
	           OpenCPN-$(VERSION); \
	    tar caf opencpn-$(VERSION).tar.gz OpenCPN-$(VERSION)
	mk-origtargz --compression xz \
                     --repack \
	             utmp/opencpn-$(VERSION).tar.gz \
	    && rm -rf utmp
