#!/usr/bin/make -f

VERSION=-2.24

# This package doesn't support parallel builds at the top level

wine_gecko$(VERSION)-x86/dist:
	dh_testdir
	wine/make_package

wine_gecko$(VERSION)-x86_64/dist:
	dh_testdir
	wine/make_package -win64

wine_gecko$(VERSION)-x86-dbg/dist:
	dh_testdir
	wine/make_package -dbg

wine_gecko$(VERSION)-x86_64-dbg/dist:
	dh_testdir
	wine/make_package -win64 -dbg

# targets for cleaning

build-clean:
	dh_testdir
	# The cleansrcdir target uses build/autoconf/clean-config.sh
	# which contains bashisms but has a #!/bin/sh line in the
	# upstream source; we only call the target if our patch is
	# applied
	if head -n 1 build/autoconf/clean-config.sh | grep -q /bin/bash; then \
		$(MAKE) -f client.mk cleansrcdir; \
	fi
	rm -rf wine_gecko$(VERSION)-x86*
	rm -f a.out confdefs.h configure js/src/configure \
	 .mozconfig.mk .mozconfig.out security/manager/.nss.checkout
	dh_clean
	# Restore a couple of deleted Makefile.in files which are needed
	mkdir -p config/tests/src-simple config/tests/makefiles/autodeps
	touch config/tests/src-simple/Makefile.in config/tests/makefiles/autodeps/Makefile.in
	# Restore a minified JS file which is needed
	mkdir -p testing/marionette/atoms
	touch testing/marionette/atoms/atoms.js

# standard targets

configure: wine_gecko

build-arch:

# The 64-bit debug package needs a 64-bit build platform, so to build it
# we need either multiarch support on buildds, or 64-bit wine-bin. Until
# that happens the 64-bit debug package is disabled.
build-indep: wine_gecko$(VERSION)-x86/dist wine_gecko$(VERSION)-x86-dbg/dist wine_gecko$(VERSION)-x86_64/dist #wine_gecko$(VERSION)-x86_64-dbg/dist

clean: build-clean
	dh_testdir
	rm -rf buildtools include lib
	find -name "*.pyc" -exec rm {} \;

binary-arch:

binary-indep: build-indep
	dh_testdir
	dh_testroot
	dh_prep -i
	install -m 644 -D wine_gecko$(VERSION)-x86/dist/wine_gecko$(VERSION)-x86.msi debian/libwine-gecko$(VERSION)/usr/share/wine-gecko/wine_gecko$(VERSION)-x86.msi
	install -m 644 -D wine_gecko$(VERSION)-x86_64/dist/wine_gecko$(VERSION)-x86_64.msi debian/libwine-gecko$(VERSION)/usr/share/wine-gecko/wine_gecko$(VERSION)-x86_64.msi
	install -m 644 -D wine_gecko$(VERSION)-x86-dbg/dist/wine_gecko$(VERSION)-x86-dbg.tar.bz2 debian/libwine-gecko-dbg$(VERSION)/usr/share/wine-gecko/wine_gecko$(VERSION)-x86-dbg.tar.bz2
	# 64-bit debug package disabled, see above
	# install -m 644 -D wine_gecko$(VERSION)-x86_64-dbg/dist/wine_gecko$(VERSION)-x86_64-dbg.tar.bz2 debian/libwine-gecko-dbg$(VERSION)/usr/share/wine-gecko/wine_gecko$(VERSION)-x86_64-dbg.tar.bz2
	dh_installdocs -i
	dh_installchangelogs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary: binary-indep

patch: wine-mozilla buildtools include

# Upstream source must be repacked for DFSG compliance
get-orig-source:
	uscan --download --destdir . --force-download

.PHONY: configure build build-clean clean install \
 binary-arch binary-indep binary patch get-orig-source
