DESTDIR=""
VERSION := $(shell dpkg-parsechangelog | grep Version | cut -d' ' -f2)

install:
	install -d -m 755 $(DESTDIR)/usr/bin
	install -d -m 755 $(DESTDIR)/usr/lib/site-python/linda
	install -d -m 755 $(DESTDIR)/usr/lib/site-python/linda/parser
	install -d -m 755 $(DESTDIR)/usr/share/linda/checks
	install -d -m 755 $(DESTDIR)/usr/share/linda/data
	install -d -m 755 $(DESTDIR)/usr/share/linda/output
	install -d -m 755 $(DESTDIR)/usr/share/linda/overrides
	install -d -m 755 $(DESTDIR)/usr/share/linda/po
	install -m 755 linda $(DESTDIR)/usr/bin
	install -m 644 *py $(DESTDIR)/usr/lib/site-python/linda
	install -m 644 parser/*py $(DESTDIR)/usr/lib/site-python/linda/parser
	cat $(DESTDIR)/usr/lib/site-python/linda/parser/clparser.py | \
	sed -e 's/VERSION/$(VERSION)/' > \
	$(DESTDIR)/usr/lib/site-python/linda/parser/clparser.py.new
	mv $(DESTDIR)/usr/lib/site-python/linda/parser/clparser.py.new \
	$(DESTDIR)/usr/lib/site-python/linda/parser/clparser.py
	install -m 644 data/*data $(DESTDIR)/usr/share/linda/data
	install -m 644 checks/*py $(DESTDIR)/usr/share/linda/checks
	install -m 644 output/*py $(DESTDIR)/usr/share/linda/output
	$(MAKE) -C po all
	install -m 644 po/*.mo $(DESTDIR)/usr/share/linda/po

test:
	install -m 644 munge_po $(DESTDIR)/usr/lib/site-python/munge_po.py
	LC_ALL=C PYTHONPATH=$(DESTDIR)/usr/lib/site-python tests/run_tests.py
	find . -name '*.py?' | xargs $(RM)
	$(RM) $(DESTDIR)/usr/lib/site-python/munge_po.py

clean:
	find . -name '*.py?' -o -name '.#*' -o -name '.*.swp' | xargs $(RM)
	$(MAKE) -C po $@

distclean: clean
	$(MAKE) -C po $@

.PHONY: install test clean distclean
