#!/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
CFLAGS = \
	-Wall \
	$(shell DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags --get CFLAGS)
CPPFLAGS = \
	$(shell DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags --get CPPFLAGS)
LDFLAGS = \
	$(shell DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags --get LDFLAGS)

# debhelper
export DH_OPTIONS

include debian/xsfbs/xsfbs.mk

DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

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

clean: cleanscripts
	dh_testdir
	dh_clean debian/local/X debian/po/pothead
	$(MAKE) -C xsf-docs clean
	-rm -rf stampdir
	-debconf-updatepo


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

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

build: build-stamp
build-stamp: scripts-stamp
	dh_testdir
	# build Debian's X server wrapper
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o debian/local/X debian/local/xserver-wrapper.c
	$(MAKE) -C xsf-docs
	touch $@

build-arch-only: build
build-all:

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) -C xsf-docs install DESTDIR=$(CURDIR)/debian/xserver-xorg/usr/share/doc/xorg
	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_installinit -px11-common -u'start 70 S .'
	dh_installman
	dh_lintian
	dh_link
	dh_compress
	dh_fixperms
	chown root:root debian/x11-common/etc/X11/Xreset
	chmod 755 debian/x11-common/etc/X11/Xreset
	chown root:root debian/x11-common/etc/X11/Xsession
	chmod 755 debian/x11-common/etc/X11/Xsession
	dh_installdeb
	dh_gencontrol
	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_installexamples
	dh_installman
	dh_installchangelogs
	dh_lintian
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	chown root:root debian/xserver-xorg/usr/bin/X
	chmod ug+s debian/xserver-xorg/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) \
	                 -VF:XServer-Xorg-Video-Recommends=$(XSERVER_XORG_VIDEO_RECOMMENDS) \
	                 -VF:XServer-Xorg-Input-Recommends=$(XSERVER_XORG_INPUT_RECOMMENDS)
	dh_md5sums
	dh_builddeb
	touch $@-stamp

binary: binary-indep binary-arch

.PHONY: default
.PHONY: genscripts cleanscripts scripts
.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:
