#!/usr/bin/make -f
# Debian rules file for xfree86 source package
# Originally by Stephen Early <sde1000@debian.org>
# Modified by Mark W. Eichin <eichin@kitten.gen.ma.us>
# Modified by Adam Heath <doogie@debian.org>
# Modified by Branden Robinson <branden@debian.org>
# Modified by Fabio Massimo Di Nitto <fabbione@fabbione.net>
# Modified by Daniel Stone <daniel.stone@ubuntu.com>
# Modified by David Nusinow <dnusinow@debian.org>
# Copyright 1996--2005 Software in the Public Interest, Inc.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
# Acknowledgements to Stephen Early, Mark Eichin, and Manoj Srivastava.

DEB_HOST_GNU_TYPE=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CC=$(DEB_HOST_GNU_TYPE)-gcc
else
CC ?=gcc
endif

# debhelper
export DH_OPTIONS

# Default list of detection packages
XSERVER_XORG_DETECT_DEPENDS = ""

include debian/xsfbs/xsfbs.mk

# Get package version info.
SOURCE_VERSION:=$(shell dpkg-parsechangelog -ldebian/changelog | grep '^Version:' | awk '{print $$2}')

# The DEB_HOST_ARCH variable may be set per the Debian cross-compilation policy.
ifdef DEB_HOST_ARCH
 ARCH:=$(DEB_HOST_ARCH)
else
 # dpkg-cross sets the ARCH environment variable; if set, use it.
 ifndef ARCH
  ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
 endif
endif

# Read in important variables.
#include debian/scripts/vars
# Read in architecture-specific variables of importance.
include debian/scripts/vars.$(ARCH)

clean: cleanscripts
	dh_testdir
	dh_clean stamp-* debian/local/X debian/po/pothead
	-rm -rf stampdir
	-debconf-updatepo


SCRIPTS=$(shell ls debian/*.config.in debian/*.postinst.in debian/*.postrm.in debian/*.preinst.in debian/*.prerm.in)

DEFAULT_DCRESOLUTIONS="1920x1440, 1920x1200, 1856x1392, 1792x1344, 1680x1050, 1600x1200, 1440x900, 1400x1050, 1280x1024, 1280x960, 1280x854, 1280x800, 1280x768, 1200x800, 1152x864, 1152x768, 1024x768, 800x600, 640x480"

scripts: stamp-scripts
stamp-scripts: genscripts validatescripts
	touch $@

validatescripts: genscripts stamp-validatescripts
stamp-validatescripts: debian/local/dexconf
	sh debian/scripts/validate-posix-sh $<
	touch $@

build: stamp-build
stamp-build: stamp-scripts
	dh_testdir
	# build Debian's X server wrapper
	$(CC) -Wall -g -O2 -o debian/local/X debian/local/xserver-wrapper.c
	touch $@

build-arch-only: build
build-all:

install: stamp-install
stamp-install: stamp-build
	dh_testdir
	dh_testroot
	umask 022
	dh_clean -k
	touch $@

binary-indep: DH_OPTIONS=-i
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installdebconf
	dh_installdirs
	dh_installdocs
	dh_installchangelogs
	dh_link
	dh_compress
	t=x11-common; \
	for p in $$(dh_listpackages -i -N$$t); do \
	  rm -rf debian/$$p/usr/share/doc/$$p; \
	  ln -s $$t debian/$$p/usr/share/doc/$$p; \
	  ( \
	    echo "# doc dir is now a symlink to $$p"; \
	    echo 'if [ "$$1" = upgrade ] && [ ! -L /usr/share/doc/'$$p' ]; then'; \
	    echo "    rm -rf /usr/share/doc/$$p"; \
	    echo "fi"; \
	  ) >> debian/$$p.preinst.debhelper; \
	done
	dh_fixperms
	dh_installdeb
	dh_gencontrol -- -VF:XServer-Xorg-Detect-Depends=$(XSERVER_XORG_DETECT_DEPENDS)
	dh_md5sums
	dh_builddeb
	touch stamp-$@

binary-arch: DH_OPTIONS=-s
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installdebconf
	dh_installdirs
	dh_installdocs
	dh_installman
	dh_installinit -px11-common -u'start 70 S .'
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	t=x11-common; \
	for p in $$(dh_listpackages -s -N$$t); do \
	  rm -rf debian/$$p/usr/share/doc/$$p; \
	  ln -s $$t debian/$$p/usr/share/doc/$$p; \
	  ( \
	    echo "# doc dir is now a symlink to $$p"; \
	    echo 'if [ "$$1" = upgrade ] && [ ! -L /usr/share/doc/'$$p' ]; then'; \
	    echo "    rm -rf /usr/share/doc/$$p"; \
	    echo "fi"; \
	  ) >> debian/$$p.preinst.debhelper; \
	done
	dh_fixperms
	chown root:root debian/x11-common/etc/X11/Xsession
	chmod 755 debian/x11-common/etc/X11/Xsession
	chown root:root debian/x11-common/usr/bin/X
	chmod ug+s debian/x11-common/usr/bin/X
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -- -VF:XServer-Xorg-Video-Depends=$(XSERVER_XORG_VIDEO_DEPENDS) \
	                 -VF:XServer-Xorg-Input-Depends=$(XSERVER_XORG_INPUT_DEPENDS)
	dh_md5sums
	dh_builddeb
	touch stamp-$@

binary: binary-indep binary-arch

.PHONY: default
.PHONY: genscripts cleanscripts scripts validatescripts
.PHONY: updatepo
.PHONY: clean configure install
.PHONY: build build-arch-only build-all
.PHONY: binary binary-arch binary-indep
.PHONY: environment

# vim:set noet ai sts=8 sw=8 tw=0:
