#!/usr/bin/make -f

export DH_OPTIONS

# Upstream handles the _FORTIFY_SOURCE flag on their own
DEB_BUILD_MAINT_OPTIONS=hardening=-fortify

ifneq (,$(wildcard /usr/share/dpkg/default.mk))
  include /usr/share/dpkg/default.mk
else
  DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
  DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
  DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
  DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
  DEB_VENDOR := $(shell dpkg-vendor --query vendor)

  CFLAGS := -Wall -g
  ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -O0
  else
    CFLAGS += -O2
  endif

  DEB_VERSION_UPSTREAM := $(shell dpkg-parsechangelog | sed -n '/^Version:/{s/Version: *\([^:]*:\)\?\([^-]*\)-.*/\2/;p;q}')
endif

BUILDER := $(shell echo $${DEBEMAIL:-$${EMAIL:-$$(echo $$LOGNAME@$$(cat /etc/mailname 2> /dev/null))}})

MAKETEST := no
ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
    MAKETEST := yes
  endif
endif

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif

CFGFLAGS := --prefix=/usr --mandir='$${prefix}'/share/man --without-local-dir
CFGFLAGS += --with-modified-by="pkg-vim-maintainers@lists.alioth.debian.org"
CFGFLAGS += --with-compiledby="$(BUILDER)"
CFGFLAGS += --enable-fail-if-missing

TINYFLAGS:=--with-features=small
TINYFLAGS+=--disable-gui
TINYFLAGS+=--disable-xsmp
TINYFLAGS+=--disable-xsmp-interact
TINYFLAGS+=--disable-netbeans
TINYFLAGS+=--disable-gpm
TINYFLAGS+=--enable-nls
TINYFLAGS+=--enable-multibyte
TINYFLAGS+=--enable-acl

OPTFLAGS:=--enable-cscope
ifeq ($(DEB_HOST_ARCH_OS),linux)
    OPTFLAGS+=--enable-gpm
    OPTFLAGS+=--enable-selinux
    TINYFLAGS+=--enable-selinux
else
    OPTFLAGS+=--disable-gpm
endif
OPTFLAGS+=--with-features=huge
OPTFLAGS+=--enable-multibyte
OPTFLAGS+=--enable-acl

NOXFLAGS:=--without-x
NOXFLAGS+=--enable-gui=no

GUIFLAGS:=--with-x
GUIFLAGS+=--enable-xim

GTK2FLAGS:=--enable-gui=gtk2
GTK2FLAGS+=--enable-gtk2-check
GTK2FLAGS+=--disable-gnome-check
GTK2FLAGS+=--disable-motif-check
GTK2FLAGS+=--disable-athena-check
GTK2FLAGS+=--disable-fontset

GNOMEFLAGS:=--enable-gui=gnome2
GNOMEFLAGS+=--disable-gtk2-check
GNOMEFLAGS+=--enable-gnome-check
GNOMEFLAGS+=--disable-motif-check
GNOMEFLAGS+=--disable-athena-check
GNOMEFLAGS+=--disable-fontset

ATHENAFLAGS:=--enable-gui=athena
ATHENAFLAGS+=--disable-gtk2-check
ATHENAFLAGS+=--disable-gnome-check
ATHENAFLAGS+=--disable-motif-check
ATHENAFLAGS+=--enable-athena-check
ATHENAFLAGS+=--enable-fontset

NOINTERPFLAGS:=--disable-luainterp
NOINTERPFLAGS+=--disable-mzschemeinterp
NOINTERPFLAGS+=--disable-perlinterp
ifeq ($(DEB_VENDOR),Ubuntu)
	NOINTERPFLAGS+=--enable-pythoninterp
else
	NOINTERPFLAGS+=--disable-pythoninterp
endif
NOINTERPFLAGS+=--disable-python3interp
NOINTERPFLAGS+=--disable-rubyinterp
NOINTERPFLAGS+=--disable-tclinterp

ALLINTERPFLAGS:=--enable-luainterp
ALLINTERPFLAGS+=--disable-mzschemeinterp
ALLINTERPFLAGS+=--enable-perlinterp
ALLINTERPFLAGS+=--enable-pythoninterp
ALLINTERPFLAGS+=--disable-python3interp
ALLINTERPFLAGS+=--enable-rubyinterp
ALLINTERPFLAGS+=--enable-tclinterp

# Each vim-xxx package is said to be a vim variant and contains only a vim
# binary built with some compile-time options. Makefile VARIANTS below are
# one-to-one with those packages with the exception of "vim-basic". In this
# Makefile vim-basic is used to build 4 packages: "vim", "vim-runtime",
# "vim-common", "vim-gui-common". "vim-tiny" is the only variant package not
# depending on vim-runtime.

VARIANTS+=vim-tiny
VARIANTS+=vim-gtk
ifneq (m68k,$(DEB_HOST_ARCH_CPU))
	VARIANTS+=vim-gnome
endif
VARIANTS+=vim-athena
VARIANTS+=vim-nox
VARIANTS+=vim-basic

ifeq ($(origin VARIANT), command line)
	VARIANTS = $(VARIANT) vim-basic
endif

CFLAGS_vim-basic:=$(CFLAGS)
CFGFLAGS_vim-basic:=$(CFGFLAGS) $(OPTFLAGS) $(NOXFLAGS) $(NOINTERPFLAGS)

CFLAGS_vim-tiny:=$(CFLAGS) -DTINY_VIMRC
CFGFLAGS_vim-tiny:=$(CFGFLAGS) $(TINYFLAGS)

CFLAGS_vim-gtk:=$(CFLAGS)
CFGFLAGS_vim-gtk:=$(CFGFLAGS) $(OPTFLAGS) $(GUIFLAGS) $(GTKFLAGS) $(ALLINTERPFLAGS)

CFLAGS_vim-gnome:=$(CFLAGS)
CFGFLAGS_vim-gnome:=$(CFGFLAGS) $(OPTFLAGS) $(GUIFLAGS) $(GNOMEFLAGS) $(ALLINTERPFLAGS)

CFLAGS_vim-athena:=$(CFLAGS)
CFGFLAGS_vim-athena:=$(CFGFLAGS) $(OPTFLAGS) $(GUIFLAGS) $(ATHENAFLAGS) $(ALLINTERPFLAGS)

CFLAGS_vim-nox:=$(CFLAGS)
CFGFLAGS_vim-nox:=$(CFGFLAGS) $(OPTFLAGS) $(NOXFLAGS) $(ALLINTERPFLAGS)

NAME:=vim
VERSION:=7.3
SNAPSHOT:=
VIMCUR:=$(NAME)$(subst .,,$(VERSION))$(SNAPSHOT)
EXPORT_DIR ?= ..
ORIG_SOURCE := $(EXPORT_DIR)/$(NAME)_$(DEB_VERSION_UPSTREAM).orig.tar.gz
PER_VARIANT_FILES := install postinst prerm links
LANGS := fr it pl ru

DOT_IN_DEPS := debian/vim-common.install
DOT_IN_DEPS += debian/vim-common.links
DOT_IN_DEPS += debian/vim-gui-common.install
DOT_IN_DEPS += debian/vim-gui-common.links
DOT_IN_DEPS += debian/vim-runtime.install
DOT_IN_DEPS += debian/vim-runtime.links
DOT_IN_DEPS += debian/vim-runtime.postrm
DOT_IN_DEPS += debian/vim-runtime.preinst
DOT_IN_DEPS += debian/runtime/debian.vim
DOT_IN_DEPS_TINY := debian/tiny/vimrc.tiny

# nothing to do per default
all: 

$(ORIG_SOURCE):
	if hg root >/dev/null 2>&1; then \
	    hg archive -t tgz -X .hg\* --prefix=$(NAME)-$(DEB_VERSION_UPSTREAM)/ -r v$$(echo $(DEB_VERSION_UPSTREAM) | sed 's/\./-/g') $(ORIG_SOURCE); \
	fi

update-orig: $(ORIG_SOURCE)

# You only need to run this immediately after checking out the package from
# version control.
quilt-setup: export QUILT_PATCHES=debian/patches
quilt-setup:
	[ ! -d .pc ]
	set -e; for patch in $$(quilt series | tac); do \
		patch -Rp1 --no-backup-if-mismatch <"debian/patches/$$patch"; \
	done
	quilt push -a

clean: $(foreach v,$(VARIANTS),clean-$(v))
	dh_testdir
	dh_testroot
	rm -f extract-stamp* build-stamp* install-stamp* configure-stamp* autoconf-stamp
	rm -f debian/helpztags.1
	rm -rf debian/policy/vim-policy.html
	rm -f debian/policy/vim-policy.txt
	[ ! -f src/auto/config.cache ] || make distclean
	rm -f src/auto/config.mk src/pixmaps src/runtime
	[ ! -f debian/configure.dist ] || mv debian/configure.dist src/auto/configure
	rm -f src/auto/config.h
	rm -f runtime/doc/doctags runtime/doc/tags.ref
	rm -f runtime/doc/*.html runtime/doc/*.log
	dh_clean

clean-vim-basic:
	dh_testdir
	dh_testroot
	for x in $(PER_VARIANT_FILES) ; do \
	  rm -f debian/vim.$$x ; \
	done
	rm -f debian/lintian/vim
	[ ! -L src/vim-basic/po ] || $(MAKE) -C src/vim-basic/po clean
	rm -f $(DOT_IN_DEPS)
	rm -rf src/vim-basic

clean-%: SHADOWDIR=$*
clean-%:
	dh_testdir
	dh_testroot
	for x in $(PER_VARIANT_FILES) ; do \
	  rm -f debian/$*.$$x ; \
	done
	rm -f debian/lintian/$*
	if [ "$*" = "vim-tiny" ]; then \
	  rm -f $(DOT_IN_DEPS_TINY); \
	fi
	rm -rf src/$(SHADOWDIR)

build: build-stamp-arch

build-indep: build-stamp-indep
build-stamp-indep: export DH_OPTIONS=-pvim-doc
build-stamp-indep:
	dh_testdir
	dh_prep
	$(MAKE) -C runtime/doc html
	$(MAKE) -C debian/policy text html
	$(MAKE) -C src/po vim.pot
	touch $@

build-arch: build-stamp-arch
build-stamp-arch: $(foreach v,$(VARIANTS),build-stamp-$(v))
	dh_testdir
	touch $@

autoconf-stamp:
	dh_testdir
	[ -f debian/configure.dist ] || cp src/auto/configure debian/configure.dist
# The autoconf target generates a new configure, and touches some other
# configure-related things.  Need to run distclean afterward or timestamps
# will be off and the next make that runs will think it needs to run
# configure.  This breaks parallel builds since two configures are being run
# in the same directory at the same time instead of in their own shadow
# directories.
	$(MAKE) -C src autoconf
	$(MAKE) distclean
	touch $@

# As of 7.3.122, src/auto/config.mk is generated by copying src/config.mk.dist
# but src/Makefile depends on its existence and will automatically run
# configure if it doesn't.  So, to not break parallel building (multiple
# top-level configure instances running at once explode, as mentioned in
# autoconf-stamp target), we need to ensure src/auto/config.mk exists before
# running configure.
src/auto/config.mk:
	cp src/config.mk.dist src/auto/config.mk

configure-stamp-%: SHADOWDIR=$*
configure-stamp-%: src/auto/config.mk
	dh_testdir
	@echo "*** DEBIAN *** CONFIGURING VARIANT $*"
	$(MAKE) -C src shadow SHADOWDIR=$(SHADOWDIR)
	if test -f src/auto/config.cache; then make distclean; fi
	cd src/$(SHADOWDIR) && LDFLAGS="$(LDFLAGS)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS_$(*))" ./configure $(CFGFLAGS_$(*))
	touch $@

build-stamp-%: CURCFLAGS=$(CFLAGS_$*)
build-stamp-%: SHADOWDIR=$*
build-stamp-%: configure-stamp-%
	dh_testdir
	dh_prep -p $*
	@echo "*** DEBIAN *** BUILDING VARIANT $*"
	$(MAKE) -C src/$(SHADOWDIR)
	touch $@

install: $(foreach v,$(VARIANTS),install-stamp-$(v))

install-stamp-indep: export DH_OPTIONS=-i -Nvim-gui-common -Nvim-runtime
install-stamp-indep: build-stamp-indep
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_install
	dh_installchangelogs
	dh_installdocs
	touch $@

install-stamp-vim-basic: export DH_OPTIONS=-pvim-runtime -pvim-common -pvim-gui-common -pvim
install-stamp-vim-basic: DESTDIR=$(CURDIR)/debian/tmp
install-stamp-vim-basic: build-stamp-vim-basic $(DOT_IN_DEPS)
	dh_testdir
	dh_testroot
	@echo "*** DEBIAN *** INSTALLING VARIANT vim-basic"
	dh_installdirs
	
	# UPSTREAM INSTALLATION
	
	$(MAKE) -C src/vim-basic STRIP=: DESTDIR=$(DESTDIR) \
	    installvimbin \
	    installtutorbin \
	    installgtutorbin \
	    installruntime \
	    installtools \
	    install-icons \
	    install-languages
	
# Tests need to be run in series, otherwise the terminal requests may not see
# proper responses.
# Prefer the vim-nox binary if it exists since that will also test the
# language interfaces.
#
# We force the tests to pass (|| true) because test61 is very time sensitive,
# so slow or loaded systems will always fail on that test.  Therefore we find
# any "failed" file other than one for test61 to determine if the tests failed
	if [ $(MAKETEST) = "yes" ]; then \
	  if [ -e src/vim-nox/vim ]; then \
	    $(MAKE) -j1 -C src/vim-nox test || true; \
	  else \
	    $(MAKE) -j1 -C src/vim-basic test || true; \
	  fi; \
	  [ $$(find src -type f -name '*.failed' \! -name 'test61.failed' | wc -l) -eq 0 ]; \
	fi
	# installvimbin installs the vim binary under debian/tmp but we install
	# it into the vim package from src/.  Need to rm it from debian/tmp so
	# that dh_install doesn't fail
	rm -f debian/tmp/usr/bin/vim
	mv src/vim-basic/vim src/vim-basic/vim.basic
	
	# DEBIAN INSTALLATION
	
	# Use UTF-8 manpages for all languages and install them simply into
	# man/$lang
	rm -rf $(DESTDIR)/usr/share/man/fr.ISO8859-1 $(DESTDIR)/usr/share/man/fr
	rm -rf $(DESTDIR)/usr/share/man/it.ISO8859-1 $(DESTDIR)/usr/share/man/it
	rm -rf $(DESTDIR)/usr/share/man/pl.ISO8859-2 $(DESTDIR)/usr/share/man/pl
	rm -rf $(DESTDIR)/usr/share/man/ru.KOI8-R
	mv $(DESTDIR)/usr/share/man/fr.UTF-8 $(DESTDIR)/usr/share/man/fr
	mv $(DESTDIR)/usr/share/man/it.UTF-8 $(DESTDIR)/usr/share/man/it
	mv $(DESTDIR)/usr/share/man/pl.UTF-8 $(DESTDIR)/usr/share/man/pl
	mv $(DESTDIR)/usr/share/man/ru.UTF-8 $(DESTDIR)/usr/share/man/ru
	
	# rm stuff handled by alternatives
	rm -f $(DESTDIR)/usr/bin/ex $(DESTDIR)/usr/bin/view
	for f in $$(find $(DESTDIR)/usr/share/man -name view.1 -o -name ex.1); do \
	  rm -f $$f; \
	done
	
	# rm stuff handled by our own symlinks
	for f in $$(find $(DESTDIR)/usr/share/man -name rvim.1 -o -name rview.1); do \
	  rm -f $$f; \
	done
	
	# helpztags manpage
	pod2man -c "User Commands" -s 1 -q none -r "vim $(VERSION)$(SNAPSHOT)" \
		-d "August 2010" debian/helpztags debian/helpztags.1
	
	# variant-related installations for package "vim"
	# to be kept in sync with those in "install-stamp-%" target
	for x in $(PER_VARIANT_FILES) ; do \
	  sed -e "s:@PKG@:vim:;s:@VARIANT@:basic:g" \
	      -e "s:@COMMON@:vim-common:" \
	      debian/vim-variant.$$x > debian/vim.$$x ;\
	done
	for L in $(LANGS); do \
	  sed -e "s:\(.*\)@LANG_ALTS@:\1--slave \$$mandir/$$L/man1/\$$i.1.gz \$$i.$$L.1.gz \$$mandir/$$L/man1/vim.1.gz \\\\\n&:" \
	      -i debian/vim.postinst; \
	done
	sed -i "/@LANG_ALTS@/d" debian/vim.postinst
	sed -e "s:@PKG@:vim:;s:@VARIANT@:basic:" \
		debian/lintian/vim-variant > debian/lintian/vim
	
	# Generate language-specific sections of
	# vim-{runtime,common,gui-common}.install files
	for L in $(LANGS); do \
	  echo debian/tmp/usr/share/man/$$L/man1/vimtutor.1  \
	    usr/share/man/$$L/man1/ >>debian/vim-runtime.install; \
	  for f in vim xxd vimdiff; do \
	    echo debian/tmp/usr/share/man/$$L/man1/$$f.1 \
	      usr/share/man/$$L/man1/ >>debian/vim-common.install; \
	  done; \
	  echo debian/tmp/usr/share/man/$$L/man1/evim.1  \
	    usr/share/man/$$L/man1/ >>debian/vim-gui-common.install; \
	done
	
	dh_installman
	dh_install --fail-missing -X/tools/
	# adjust things for vim-gui-common
	cp debian/vim-common/usr/share/man/man1/vim.1 \
	   debian/vim-gui-common/usr/share/man/man1/gvim.1
	cp debian/vim-common/usr/share/man/man1/vimdiff.1 \
	   debian/vim-gui-common/usr/share/man/man1/gvimdiff.1
	cp debian/vim-runtime/usr/share/man/man1/vimtutor.1 \
	   debian/vim-gui-common/usr/share/man/man1/gvimtutor.1
	for L in $(LANGS); do \
	  cp debian/vim-common/usr/share/man/$$L/man1/vim.1 \
	     debian/vim-gui-common/usr/share/man/$$L/man1/gvim.1; \
	  cp debian/vim-common/usr/share/man/$$L/man1/vimdiff.1 \
	     debian/vim-gui-common/usr/share/man/$$L/man1/gvimdiff.1; \
	  cp debian/vim-runtime/usr/share/man/$$L/man1/vimtutor.1 \
	     debian/vim-gui-common/usr/share/man/$$L/man1/gvimtutor.1; \
	done
	# Generate language-specific sections of
	# vim-{runtime,common,gui-common}.links files
	for L in $(LANGS); do \
	  for p in rvim rview; do \
	    echo usr/share/man/$$L/man1/vim.1  \
	      usr/share/man/$$L/man1/$$p.1 >>debian/vim-common.links; \
	  done; \
	  for p in gview rgvim rgview; do \
	    echo usr/share/man/$$L/man1/gvim.1  \
	      usr/share/man/$$L/man1/$$p.1 >>debian/vim-gui-common.links; \
	  done; \
	  echo usr/share/man/$$L/man1/evim.1 \
	    usr/share/man/$$L/man1/eview.1 >>debian/vim-gui-common.links; \
	done
	dh_link
	
	 # all excepts vim
	dh_installchangelogs -Nvim -pvim-dbg
	dh_installdocs -pvim-dbg
	dh_installmime
	
	env -u DH_OPTIONS dh_bugfiles -A -pvim
	
	touch $@

# the other variants only include the binary
install-stamp-vim-tiny: export DH_OPTIONS=-pvim-tiny
install-stamp-vim-tiny: DESTDIR=$(CURDIR)/debian/vim-tiny
install-stamp-vim-tiny: build-stamp-vim-tiny $(DOT_IN_DEPS_TINY)
	dh_testdir
	dh_testroot
	@echo "*** DEBIAN *** INSTALLING VARIANT vim-tiny"
	dh_installdirs
	
	mv src/vim-tiny/vim src/vim-tiny/vim.tiny
	# variant-related installations
	# to be kept in sync with those in "install-stamp-vim-basic" target
	for x in $(PER_VARIANT_FILES) ; do \
	  sed -e "s:@PKG@:vim-tiny:" -e "s:@VARIANT@:tiny:g" \
	      -e "s:@COMMON@:vim-common:" \
	      debian/vim-variant.$$x > debian/vim-tiny.$$x ;\
	done
	sed -e "s:@PKG@:vim-tiny:;s:@VARIANT@:tiny:" \
	    debian/lintian/vim-variant > debian/lintian/vim-tiny
	for L in $(LANGS); do \
	  sed -e "s:\(.*\)@LANG_ALTS@:\1--slave \$$mandir/$$L/man1/\$$i.1.gz \$$i.$$L.1.gz \$$mandir/$$L/man1/vim.1.gz \\\\\n&:" \
	      -i debian/vim-tiny.postinst; \
	done
	sed -i "/@LANG_ALTS@/d" debian/vim-tiny.postinst
	# fake help installation for vim-tiny
	echo "debian/tiny/doc/	usr/share/vim/$(VIMCUR)" >> debian/vim-tiny.install
	echo "debian/tiny/vimrc.tiny	etc/vim" >> debian/vim-tiny.install
	echo "etc/vim/vimrc.tiny	usr/share/vim/vimrc.tiny" >> debian/vim-tiny.links
	dh_install
	dh_installmenu
	dh_link
	dh_bugfiles -A
	
	touch $@

# the other variants only include the binary
install-stamp-%: export DH_OPTIONS=-p$*
install-stamp-%: DESTDIR=$(CURDIR)/debian/$*
install-stamp-%: build-stamp-%
	dh_testdir
	dh_testroot
	@echo "*** DEBIAN *** INSTALLING VARIANT $*"
	dh_installdirs
	
	mv src/$*/vim src/$*/$(subst -,.,$*)
	# variant-related installations
	# to be kept in sync with those in "install-stamp-vim-basic" target
	for x in $(PER_VARIANT_FILES) ; do \
	  if [ "$*" = "vim-nox" ]; then \
	    sed -e "s:@PKG@:$*:" -e "s:@VARIANT@:$(patsubst vim-%,%,$*):g" \
	        -e "s:@COMMON@:vim-common:" \
	        debian/vim-variant.$$x > debian/$*.$$x ;\
	  else \
	    sed -e "s:@PKG@:$*:" -e "s:@VARIANT@:$(patsubst vim-%,%,$*):g" \
	        -e "s:@COMMON@:vim-gui-common:" \
	        debian/vim-variant.$$x > debian/$*.$$x ;\
	  fi \
	done
	sed -e "s:@PKG@:$*:;s:@VARIANT@:$(patsubst vim-%,%,$*):" \
	    debian/lintian/vim-variant > debian/lintian/$*
	for L in $(LANGS); do \
	  sed -e "s:\(.*\)@LANG_ALTS@:\1--slave \$$mandir/$$L/man1/\$$i.1.gz \$$i.$$L.1.gz \$$mandir/$$L/man1/vim.1.gz \\\\\n&:" \
	      -i debian/$*.postinst; \
	done
	sed -i "/@LANG_ALTS@/d" debian/$*.postinst
	dh_install
	dh_installmenu
	dh_link
	dh_bugfiles -A
	
	touch $@

%: %.in
	cat $< | sed 's/@VIMCUR@/$(VIMCUR)/' > $@

binary-indep: export DH_OPTIONS=-i
binary-indep: install-stamp-vim-basic install-stamp-indep
	dh_testdir
	dh_testroot
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb -- -Zxz

binary-arch: export DH_OPTIONS=-pvim-dbg
binary-arch: $(foreach v,$(VARIANTS),binary-arch-$(v))
	dh_testdir
	dh_testroot
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb -- -Zxz

binary-arch-vim-basic: export DH_OPTIONS=-pvim-common -pvim
binary-arch-vim-basic: install-stamp-vim-basic
	dh_testdir
	dh_testroot
	dh_strip --dbg-package=vim-dbg
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb -- -Zxz

binary-arch-%: export DH_OPTIONS=-p$* $(foreach v,$(VARIANTS_SKIP),-N$(v))
binary-arch-%: install-stamp-%
	dh_testdir
	dh_testroot
	dh_strip --dbg-package=vim-dbg
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb -- -Zxz

binary: beginlog binary-indep binary-arch endlog
.PHONY: patch unpatch extract clean build install binary-indep binary-arch binary update-orig quilt-setup

.PHONY: beginlog endlog
beginlog:
	@echo "*** DEBIAN *** BUILD STARTED"
	@echo "*** DEBIAN *** BUILDING VARIANTS: $(VARIANTS)"
	@echo "*** DEBIAN *** SKIPPING VARIANTS: $(VARIANTS_SKIP)"
endlog:
	@echo "*** DEBIAN *** BUILD COMPLETED"

# vim: set foldmethod=marker:
