# Makefile for dhelp project

# Copyright (C) 2005 Esteban Manchado Velzquez <zoso@debian.org>

# This file 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, or (at your option) any
# later version.

# This file 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 file; see the file COPYING.  If not, write to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

PACKAGE = dhelp
VERSION = 0.6.15
PREFIX_  = $(if $(PREFIX),$(PREFIX),/usr/local)
DESTDIR_ = $(DESTDIR)/$(PREFIX_)
RHTML_TEMPLATES = *.rhtml
TMPL_TEMPLATES = *.tmpl
PERL_I18N_PROGRAMS = dsearch

all:

checkversion:
	@DCHANGELOG_VERSION=`dpkg-parsechangelog | egrep Version: | sed 's/Version: //'`; \
	if [ $$DCHANGELOG_VERSION != $(VERSION) ]; then \
	    echo "Version mismatch: debian/changelog says $$DCHANGELOG_VERSION, Makefile $(VERSION)" 2>&1; \
		exit 1; \
	fi

install: checkversion
	mkdir -p $(DESTDIR_) $(DESTDIR_)/sbin $(DESTDIR_)/bin $(DESTDIR_)/lib/cgi-bin $(DESTDIR_)/share/doc/dhelp $(DESTDIR_)/share/dhelp
	# Executable files
	install dhelp $(DESTDIR_)/bin/dhelp
	install dsearch $(DESTDIR_)/lib/cgi-bin/dsearch
	install dhelp_fetcher.rb $(DESTDIR_)/lib/cgi-bin/dhelp_fetcher
	install dhelp_parse.rb $(DESTDIR_)/sbin/dhelp_parse.rb
	# Update PREFIX variable in dhelp_parse.rb
	sed 's|^PREFIX = .*|PREFIX = "$(PREFIX_)"|' $(DESTDIR_)/sbin/dhelp_parse.rb >$(DESTDIR_)/sbin/dhelp_parse
	rm -f $(DESTDIR_)/sbin/dhelp_parse.rb
	chmod a+x $(DESTDIR_)/sbin/dhelp_parse
	# Ruby libraries
	mkdir -p $(DESTDIR_)/lib/ruby/1.8
	cp -r lib/* $(DESTDIR_)/lib/ruby/1.8
	# Misc files/dirs
	cp *.rhtml *.tmpl swish++.conf $(DESTDIR_)/share/dhelp/
	mkdir -p $(DESTDIR)/etc
	cp dhelp.conf-sample $(DESTDIR)/etc/dhelp.conf
	# Translations
	for i in po/*.po; do \
	    mkdir -p $(DESTDIR_)/share/locale/`basename $$i .po`/LC_MESSAGES/; \
	    rmsgfmt -o $(DESTDIR_)/share/locale/`basename $$i .po`/LC_MESSAGES/dhelp.mo $$i; \
	done

test:
	RUBYLIB=lib:test ruby -w test/ts_dhelp.rb

updatepo: po/*.po

reportpo:
	podebconf-report-po --call --withtranslators --languageteam --podir po/

po/dhelp.pot: $(RHTML_TEMPLATES) $(TMPL_TEMPLATES) $(PERL_I18N_PROGRAMS)
	rgettext $(RHTML_TEMPLATES) >po/dhelp.pot
	xgettext --language=c --keyword=t --join-existing -o po/dhelp.pot $(TMPL_TEMPLATES)
	xgettext --language=perl --keyword=_ --join-existing -o po/dhelp.pot $(PERL_I18N_PROGRAMS)

po/%.po: po-file
	msgmerge $@ po/dhelp.pot > $@.tmp
	mv -f $@.tmp $@

.PHONY: install all test updatepo checkversion po-file
