#!/usr/bin/make -f

xkb_base := /usr/share/X11/xkb

override_dh_autoreconf:
	intltoolize -c -f
	AUTOPOINT=true dh_autoreconf autoreconf -- -vfi

override_dh_auto_configure:
	dh_auto_configure -- \
	  --with-xkb-rules-symlink=xfree86,xorg \
	  --with-xkb-base=$(xkb_base) \
	  --disable-runtime-deps

override_dh_auto_install:
	# Regular deb:
	$(MAKE) -C build install DESTDIR=$(CURDIR)/debian/xkb-data

	# Treat the udeb as an exact copy, but remove messages/pkg-config/man-pages:
	cp -r $(CURDIR)/debian/xkb-data/* $(CURDIR)/debian/xkb-data-udeb
	rm -rf $(CURDIR)/debian/xkb-data-udeb/usr/share/locale
	rm -rf $(CURDIR)/debian/xkb-data-udeb/usr/share/man
	rm -rf $(CURDIR)/debian/xkb-data-udeb/usr/share/pkgconfig

	# Now try and save some space, by getting rid of comments (in
	# non-XML files, let's be cautious), then of multiple spaces:
	find $(CURDIR)/debian/xkb-data-udeb/ ! -name '*.xml' -type f -print0 \
	  | xargs -0 perl -i -pe 's,//.*$$,,'
	find $(CURDIR)/debian/xkb-data-udeb/usr/share/X11 -type f -print0 \
	  | xargs -0 perl -i -pe 's/[ \t]+/ /g'

# Work around quilt's removing empty files:
override_dh_quilt_unpatch:
	dh_quilt_unpatch
	touch rules/base.o_k.part

%:
	dh $@ --with quilt --builddirectory=build/
