#!/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.

VER := $(shell head -1 debian/changelog | sed -e 's/^.*(//' -e 's/).*$$//')
tmp := $(CURDIR)/debian/tmp
usl := $(tmp)/usr/share/lintian
usdl := $(tmp)/usr/share/doc/lintian

runtests: 
	$(checkdir)
	@echo .... running tests ....

	[ -d debian/tests ] || mkdir debian/tests
	LINTIAN_ROOT="" /usr/bin/perl testset/runtests testset debian/tests
	touch runtests

build:
	$(checkdir)
	@echo .... running build ....
	perl -i -pe '$$_="my \$$LINTIAN_VERSION = \"$(VER)\";\t#External Version number\n" \
		if m/^my \$$LINTIAN_VERSION = /;' frontend/lintian

	cd doc && LANG=C debiandoc2html lintian.sgml
	cd doc && LANG=C debiandoc2text lintian.sgml

	touch build

clean:
	$(checkdir)
	@echo .... cleaning ....

	rm -f build runtests
	rm -rf $(tmp) debian/files* core debian/substvars
	rm -rf doc/lintian.html/ doc/lintian.txt
	rm -rf debian/tests
	find -name "*~" -print0 | xargs -0r rm 
	find -name CVS -type d -print0 | xargs -0r rm 
	find -name "*.pyc" -print0 | xargs -0r rm 
	find -name "*.pyo" -print0 | xargs -0r rm 

binary-indep:	build
	test `id -u` = 0
	$(checkdir)
	@echo .... build binary-indep ....
	rm -rf $(tmp)
# frontends
	@echo .... install frontends ....
	install -d $(tmp)/usr/bin
	install -m 755 frontend/lintian $(tmp)/usr/bin/
	install -m 755 frontend/lintian-info $(tmp)/usr/bin/
# library files
	@echo .... install library files ....
	install -d $(usl) $(usl)/checks $(usl)/collection $(usl)/info
	install -d $(usl)/lib $(usl)/unpack $(usl)/overrides
	for d in checks collection info lib unpack; do \
	  find $$d -type f ! -path '*/CVS/*' | xargs -iFILE cp -p FILE $(usl)/$$d/; \
	done
# documentation
	@echo .... install documentation ....
	install -d $(usdl)
	find doc -maxdepth 1 -type f ! -path '*/CVS/*' ! -name lintianrc.example | xargs -iFILE cp -p FILE $(usdl)/
	cp -a doc/lintian.html $(usdl)/
	gzip -9 $(usdl)/lintian.sgml
	gzip -9 $(usdl)/lintian.txt
	install -m 644 debian/changelog $(usdl)/
	gzip -9 $(usdl)/changelog
	ln -s changelog.gz $(usdl)/changelog.Debian.gz
	install -m 644 debian/copyright $(usdl)/
# manual pages
	@echo .... install manual pages ....
	install -d $(tmp)/usr/share/man/man1
	install -m 644 man/*.1 $(tmp)/usr/share/man/man1
	gzip -9 $(tmp)/usr/share/man/man1/*
# config file
	@echo .... install config file ....
	install -d $(tmp)/etc/	
	install -m 644 doc/lintianrc.example $(tmp)/etc/lintianrc
# spool directory
	@echo .... install spool directory ....
	install -d $(tmp)/var/spool/lintian
# control files
	@echo .... install control files ....
	install -d $(tmp)/DEBIAN
	install -m 755 debian/prerm debian/postinst $(tmp)/DEBIAN/
	install -m 644 debian/conffiles $(tmp)/DEBIAN/

	dpkg-gencontrol -isp
	chown -R root.root $(tmp)
	chmod -R go=rX $(tmp)
	dpkg --build $(tmp) ..

binary-arch:
# 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
