# Change this value to install this program's files into another directory.
INSTALL_PREFIX=/usr/local


# This makefile is used for "squeezing" the components of the "moosic" and
# "moosicd" programs into single files, and for converting the POD documents for
# Moosic into the manpage format. This requires GNU make, the "install" utility
# program, python, and the pod2man and pod2html utilities (the latter two are
# usually included with Perl).


VERSION=1.5.0
PROGRAMS=moosicd moosic
DOCS=README License ChangeLog NEWS Todo History Moosic_API.txt README.developers
MANPAGES_1:=$(PROGRAMS:=.1)
MANPAGES_3:=Moosic_API.3
PUBLIC_MODULES:=moosic_factory.py utilities.py
HTMLDOCS:=$(PROGRAMS:=.html) $(PUBLIC_MODULES:.py=.html) Moosic_API.html
PYTHON=python

.PHONY: all
all: $(PROGRAMS) $(DOCS) $(MANPAGES_1) $(MANPAGES_3) $(HTMLDOCS)
	-

.PHONY: docs
docs: $(DOCS) $(MANPAGES_1) $(MANPAGES_3) $(HTMLDOCS)
	-

moosic: moosic_main.py utilities.py moosic_factory.py moosic_dispatcher.py
	$(PYTHON) squeezeTool -1v -o $@ -b moosic_main $+
	mv -f $@.py $@
	chmod 755 $@

moosicd: moosicd_main.py moosicd_methods.py moosicd_support.py xmlrpc_registry.py utilities.py moosic_factory.py daemonize.py
	$(PYTHON) squeezeTool -1v -o $@ -b moosicd_main $+
	mv -f $@.py $@
	chmod 755 $@

#moosh: moosh_main.py moosh_support.py moosic_factory.py moosic_dispatcher.py
#	$(PYTHON) squeezeTool -1v -o $@ -b moosh_main $+
#	mv -f $@.py $@
#	chmod 755 $@
#
#moosic_proxy: moosic_proxy.py moosic_factory.py
#	$(PYTHON) squeezeTool -1v -o $@_squeeze -b moosic_proxy $+
#	mv -f $@_squeeze.py $@
#	chmod 755 $@

Moosic_API.pod: Moosic_API.intro.pod Moosic_API.s0.pod Moosic_API.s1.pod Moosic_API.s2.pod Moosic_API.s3.pod Moosic_API.s4.pod Moosic_API.s5.pod Moosic_API.s6.pod
	cat $^ > $@

%.txt: %.pod
	pod2text -l $< $@

%.1: %.pod
	pod2man --section 1 --release "Moosic ${VERSION}" --center "" $< $@

%.3: %.pod
	pod2man --section 3 --release "Moosic ${VERSION}" --center "" $< $@

%.html: %.pod
	pod2html --podpath=. --htmlroot=. --infile=$< --outfile=$@
	rm -f pod2htm*

%.html: %.py
	pydoc -w $*

.PHONY: install
install: all
	install -d $(INSTALL_PREFIX)
	install -d $(INSTALL_PREFIX)/bin
	install -m 755 $(PROGRAMS) $(INSTALL_PREFIX)/bin/
	install -d $(INSTALL_PREFIX)/share/man/man1
	install -m 644 $(MANPAGES_1) $(INSTALL_PREFIX)/share/man/man1/
	install -d $(INSTALL_PREFIX)/share/man/man3
	install -m 644 $(MANPAGES_3) $(INSTALL_PREFIX)/share/man/man3/
	install -d $(INSTALL_PREFIX)/share/doc/moosic
	install -m 644 $(DOCS) $(INSTALL_PREFIX)/share/doc/moosic/
	install -m 644 $(PUBLIC_MODULES) $(INSTALL_PREFIX)/share/doc/moosic/
	install -d $(INSTALL_PREFIX)/share/doc/moosic/html
	install -m 644 $(HTMLDOCS) $(INSTALL_PREFIX)/share/doc/moosic/html/

.PHONY: clean
clean:
	rm -f $(PROGRAMS) *.pyc

.PHONY: cleandocs
cleandocs:
	rm -f $(MANPAGES_1) $(MANPAGES_3) $(HTMLDOCS)
