# lkajan:
# `prof' is too short and I am very afraid it will collide with something else in /usr/share.
# Therefore we put everything into /usr/share/profphd/.
# Things like:
# prof
# phd
# maxhom
# molbio
bindir := $(prefix)/bin
datarootdir := $(prefix)/share
pkgdatadir := $(datarootdir)/$(PACKAGE)
docdir := $(datarootdir)/doc/$(PACKAGE)

man_MANS = prof.1

all: man

man:	$(man_MANS)

%.1:	%
	sed -e 's|__pkgdatadir__|$(pkgdatadir)|g;s|__sysconfdir__|$(sysconfdir)|g;s|__bindir__|$(bindir)|g;s|__VERSION__|$(VERSION)|g;s|__PREFIX__|$(prefix)|g;' "$<" | \
	pod2man -c 'User Commands' -r "$(VERSION)" -name $(shell echo "$(basename $@)" | tr '[:lower:]' '[:upper:]') > "$@"

install: install-perl install-man install-neuralnet

install-man:
	mkdir -p $(DESTDIR)$(prefix)/share/man/man1 && cp -a prof.1 $(DESTDIR)$(prefix)/share/man/man1/

install-perl:
	mkdir -p $(DESTDIR)$(prefix)/share/profphd/prof && rsync -aC \
		--exclude /bin \
		--exclude /embl/para \
		--exclude /embl/net \
		--exclude /exa/DMD_HUMAN.hssp.gz \
		--exclude /net \
		--exclude /Makefile \
		--exclude /prof.1 \
		--exclude Session.vim \
		--exclude '.*.swp' \
		./. $(DESTDIR)$(prefix)/share/profphd/prof/.
	find $(DESTDIR)$(prefix)/share/profphd/prof/embl/phd.pl $(DESTDIR)$(prefix)/share/profphd/prof/scr/CONFprof.pl $(DESTDIR)$(prefix)/share/profphd/prof/prof $(DESTDIR)$(prefix)/share/profphd/prof/scr/lib/prof.pm \
		-type f -exec sed -i -e 's|__PREFIX__|$(prefix)|g;s|__VERSION__|$(VERSION)|;' {} \;
	rm -rf $(DESTDIR)$(prefix)/bin/prof && mkdir -p $(DESTDIR)$(prefix)/bin && ln -s ../share/profphd/prof/prof $(DESTDIR)$(prefix)/bin/prof

install-neuralnet:
	mkdir -p $(DESTDIR)$(prefix)/share/profphd/prof/embl/para && rsync -aC \
		./embl/para/. $(DESTDIR)$(prefix)/share/profphd/prof/embl/para/.
	mkdir -p $(DESTDIR)$(prefix)/share/profphd/prof/embl/net && rsync -aC \
		./embl/net/. $(DESTDIR)$(prefix)/share/profphd/prof/embl/net/.
	mkdir -p $(DESTDIR)$(prefix)/share/profphd/prof/net && rsync -aC \
		./net/. $(DESTDIR)$(prefix)/share/profphd/prof/net/.
	find $(DESTDIR)$(prefix)/share/profphd/prof/embl/para -maxdepth 1 -name '*.com' -type f -exec sed -i -e 's|__PREFIX__|$(prefix)|g' {} \;

help:
	@echo "Targets:"
	@echo "all"
	@echo "install - install-perl install-neuralnet"
	@echo "install-perl"
	@echo "install-neuralnet"
	@echo
	@echo "Variables:"
	@echo "DESTDIR - install to DESTDIR"
	@echo "prefix - common installation prefix for all files"

clean:
	\rm -f *.[1-9]

.PHONY: all install install-man install-neuralnet install-perl help clean man

# vim:noet:ai:
