+release := $(shell dpkg-parsechangelog | sed -n 's/^Source: wxwidgets//p')
+soversion := $(shell grep '^WX_CURRENT=' configure.in | sed 's/WX_CURRENT=\([0-9]\+\).*/\1/')
+sorelease := $(release:%-$(DEBIAN_WXFLAVOUR)=%).$(soversion)$(addprefix -,$(DEBIAN_WXFLAVOUR))
+
+pydir := usr/lib/$(python_ver)/site-packages
+wxpydir := $(pydir)/wx-$(sorelease)-gtk2-unicode
+
+cross_host = i586-mingw32msvc
+cross_build = $(shell ./config.guess)
+
+config_cache = ../config_deb.cache
+config_cache_cross = ../config_deb_cross.cache
+
+# Packages to build:
+package_gtk_lib = libwxgtk$(sorelease)
+package_gtk_dev = libwxgtk$(release)-dev
+package_gtk_dbg = libwxgtk$(release)-dbg
+package_gtk_py_lib = libwxgtk$(sorelease)-python
+package_gtk_py = wxpython$(sorelease)
+package_common = wx$(release)-common
+package_headers = wx$(release)-headers
+package_i18n = wx$(release)-i18n
+package_doc = wx$(release)-doc
+package_examples = wx$(release)-examples
+
+package_gtk_dbg_py = libwxgtk$(sorelease)-dbg-python
+package_msw_dev = libwxmsw$(release)-dev
+package_msw_dbg = libwxmsw$(release)-dbg
+package_headers_msw = wx$(release)-headers-msw
+
+# Build directories:
+objdir_gtk_shared = objs_gtk_sh
+objdir_gtk_debug = objs_gtk_d
+objdir_gtk_install = objs_gtk_install
+objdir_doc_cruft = objs_doc_con
+objdir_doc = docs/wx-manual.html
+objdir_examples = docs/examples
+objdir_i18n = locale
+
+objdir_msw_shared = objs_msw_sh
+objdir_msw_static = objs_msw_st
+objdir_msw_dbg = objs_msw_d
+objdir_msw_install = objs_msw_install
+
+objdirs = $(objdir_gtk_shared) $(objdir_gtk_debug) $(objdir_gtk_install) \
+ $(objdir_doc_cruft) $(objdir_doc) $(objdir_examples) \
+ $(objdir_msw_shared) $(objdir_msw_static) $(objdir_msw_dbg) \
+ $(objdir_msw_install)
+
+# note that the i18n package is actually arch indep (once built)
+# but must be built (and installed) during the arch any phase as
+# it's pulled out of the wxGTK shared lib package.
+
+
+# Build stamps:
+build_arch_stamps = build-gtk-shared-stamp build-gtk-shared-contrib-stamp \
+ build-gtk-debug-stamp build-gtk-debug-contrib-stamp \
+ build-i18n-stamp build-gtk-py-stamp
+
+
+build_indep_stamps = build-examples-stamp build-doc-stamp
+
+build_cross_stamps = build-msw-shared-stamp build-msw-static-stamp build-msw-dbg-stamp
+
+build_stamps_native = $(build_arch_stamps) $(build_indep_stamps)
+
+build_stamps = $(build_stamps_native) $(build_cross_stamps)
+
+
+# Install targets:
+install_all_arch = install-gtk-lib install-gtk-dev install-gtk-dbg \
+ install-common install-headers install-i18n \
+ install-gtk-py
+
+install_all_indep = install-examples install-doc
+
+install_all_cross = install-msw-dev install-msw-dbg install-headers-msw
+
+install_all_native = $(install_all_arch) $(install_all_indep)
+
+install_all = $(install_all_native) $(install_all_cross)
+
+
+wxconfig := $(shell pwd)/$(objdir_gtk_shared)/wx-config --no_rpath
+wxconfig-dbg := $(shell pwd)/$(objdir_gtk_debug)/wx-config --no_rpath
+
+#contrib_libs := $(subst CVS,,$(notdir $(wildcard contrib/include/wx/*)))
+
+
+# The Rules:
+
+debian/python-version:
+ echo python_ver := python$(shell python -c "import sys;print sys.version[:3]") > $@
+
+debian/control: $(addprefix debian/,control.in python-version)
+ sed -e 's/=V/$(release)/g;s/=SOV/$(sorelease)/g;s/=PY/$(python_ver)/g' \
+ < debian/control.in > debian/control
+
+control-files-stamp: debian/control
+ dh_testdir
+ @for f in postinst prerm; do \
+ echo "generating control file $(package_gtk_dev).$$f"; \
+ sed -e 's/=V/$(release)/g' < debian/libwxgtk-dev.$$f \
+ > debian/$(package_gtk_dev).$$f; \
+ done;
+ @for f in postinst prerm; do \
+ echo "generating control file $(package_gtk_dbg).$$f"; \
+ sed -e 's/=V/$(release)/g' < debian/libwxgtk-dbg.$$f \
+ > debian/$(package_gtk_dbg).$$f; \
+ done;
+ @for f in docs postinst prerm; do \
+ echo "generating control file $(package_gtk_py_lib).$$f"; \
+ sed -e 's/=PY/$(python_ver)/g; \
+ s|=WXPYDIR|$(wxpydir)|g; \
+ s/=V/$(release)/g; \
+ s/=SOV/$(sorelease)/g' \
+ < debian/libwxgtk-python.$$f \
+ > debian/$(package_gtk_py_lib).$$f; \
+ done;
+ @echo "generating control file $(package_gtk_py).menu"; \
+ sed -e 's/=SOV/$(sorelease)/g' < debian/wxpython.menu \
+ > debian/$(package_gtk_py).menu;
+ @for f in docs postinst; do \
+ echo "generating control file $(package_gtk_dbg_py).$$f"; \
+ sed -e 's/=PY/$(python_ver)/g;s/=V/$(release)/g;s/=SOV/$(sorelease)/g' \
+ < debian/libwxgtk-python.$$f \
+ > debian/$(package_gtk_dbg_py).$$f; \
+ done;
+ @echo "generating control file $(package_gtk_dbg_py).prerm"; \
+ sed 's/=SOV/$(sorelease)/g' < debian/libwxgtk-dbg-python.prerm \
+ > debian/$(package_gtk_dbg_py).prerm
+ @for f in docs doc-base; do \
+ echo "generating control file $(package_doc).$$f"; \
+ sed -e 's/=V/$(release)/g' < debian/wx-doc.$$f \
+ > debian/$(package_doc).$$f; \
+ done;
+ @for f in examples; do \
+ echo "generating control file $(package_examples).$$f"; \
+ cp debian/wx-examples.$$f debian/$(package_examples).$$f; \
+ done;
+ @for f in postinst prerm; do \
+ echo "generating control file $(package_msw_dev).$$f"; \
+ sed -e 's/=V/$(release)/g;s/=H/$(cross_host)/g' < debian/libwxmsw-dev.$$f \
+ > debian/$(package_msw_dev).$$f; \
+ done;
+ @for f in postinst prerm; do \
+ echo "generating control file $(package_msw_dbg).$$f"; \
+ sed -e 's/=V/$(release)/g;s/=H/$(cross_host)/g' < debian/libwxmsw-dbg.$$f \
+ > debian/$(package_msw_dbg).$$f; \
+ done;
+# @echo "generating control file $(package_common).menu"; \
+# sed -e 's/=V/$(release)/g' < debian/wx-common.menu \
+# > debian/$(package_common).menu;
+ @echo "generating control file lintian-override"; \
+ sed -e 's/=V/$(release)/g' < debian/lintian-override.in \
+ > debian/lintian-override; \
+ touch $@
+
+build_arch: control-files-stamp $(build_arch_stamps)
+build_all: control-files-stamp $(build_stamps_native)
+
+# Really we should probably do nothing here until we know which
+# binary target is being called, but alpha builds were exploding
+# (compiler segfaults) in random places when building under fakeroot
+# from the binary-arch target. Build all -arch files here then, and
+# let the -indep stuff fend for itself later.
+
+build: build_arch
+
+
+configure-gtk-shared-stamp: