#!/usr/bin/make -f

# Copyright (C) 1998 by Christian Schwarz and Richard Braakman
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.


runtests: 
	$(checkdir)

	if [ ! -d debian/tests ] ; then mkdir debian/tests; fi
	LINTIAN_ROOT= perl testset/runtests testset debian/tests

	touch runtests

build: runtests
	$(checkdir)

	cd doc; debiandoc2html lintian.sgml
	cd doc; debiandoc2text lintian.sgml

	touch build

clean:
	$(checkdir)
	-rm -f build runtests
	-rm -rf debian/tmp debian/files* core debian/substvars
	-rm -rf doc/lintian.html/ doc/lintian.text
	-rm -rf debian/tests
	-find -name "*~" -print0 | xargs -0r rm 
	-find -name "*.pyc" -print0 | xargs -0r rm 

binary-indep:	build
	test root = "`whoami`"
	$(checkdir)
	-rm -rf debian/tmp
# frontends
	install -d debian/tmp/usr/bin
	install -m 755 frontend/* debian/tmp/usr/bin/
# library files
	install -d debian/tmp/usr/share/lintian
	cp -a checks collection info lib unpack debian/tmp/usr/share/lintian/
# documentation
	install -d debian/tmp/usr/doc/lintian
	cp -a doc/* debian/tmp/usr/doc/lintian/
	rm debian/tmp/usr/doc/lintian/lintianrc.example
	gzip -9 debian/tmp/usr/doc/lintian/lintian.sgml
	gzip -9 debian/tmp/usr/doc/lintian/lintian.text
	gzip -9 debian/tmp/usr/doc/lintian/TODO
	install -m 644 debian/changelog debian/tmp/usr/doc/lintian/
	gzip -9 debian/tmp/usr/doc/lintian/changelog
	install -m 644 debian/copyright debian/tmp/usr/doc/lintian/
# manual pages
	install -d debian/tmp/usr/man/man1
	install -m 644 man/*.1 debian/tmp/usr/man/man1
	gzip -9 debian/tmp/usr/man/man1/*
# config file
	install -d debian/tmp/etc/	
	install -m 644 doc/lintianrc.example debian/tmp/etc/lintianrc
# spool directory
	install -d debian/tmp/var/spool/lintian
# control files
	install -d debian/tmp/DEBIAN
	install -m 755 debian/prerm debian/tmp/DEBIAN/
	install -m 644 debian/conffiles debian/tmp/DEBIAN/

	dpkg-gencontrol -isp
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

binary-arch: build
	test root = "`whoami`"
	$(checkdir)
# There are no architecture-dependent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

define checkdir
	test -f debian/rules
endef

binary:		binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
