

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

ifndef INSTALL_ROOT
INSTALL_ROOT=/usr/local
endif

ifndef DOCPATH
DOCPATH=$(INSTALL_ROOT)/doc/dopy
endif

ifndef PYTHON_PREFIX
PYTHON_LIB=$(shell python -c 'import sys, os; \
		print os.path.join(sys.prefix, "lib", \
                "python" + sys.version[:3])')
endif

ifndef MODPATH
MODPATH=$(PYTHON_LIB)/site-packages/dopy
endif

FILES=dopy.py tcp.py __init__.py naming.py pos.py tb.py dopyserver dopyclient \
   README.txt README.html Manual.nml Manual.html

MODULES=dopy.py naming.py pos.py tb.py rsh.py tcp.py

# documentation generated from modules
MOD_DOCS=dopy.html naming.html pos.html tb.html rsh.html tcp.html

# documentation written in NML
NML_DOCS=README.html Manual.html

ALL: docs

docs: $(NML_DOCS) $(MOD_DOCS)

README.html: README.txt
	nml2html README.txt

Manual.html: Manual.nml
	nml2html Manual.nml

distrib: ALL
	if [ "$(VER)" = "" ]; \
		then echo "Error: you must provide a VER parameter"; \
                exit 1; \
	fi
	cvs export -r dopy-$(subst .,-,$(VER)) dopy
	cd dopy; $(MAKE)
	mv dopy dopy-$(VER)
	zip -r dopy-$(VER).zip dopy-$(VER)
	rm -rf dopy-$(VER)

		
	
clean:
	rm -rf $(MOD_DOCS:.html=)
	rm -f $(MOD_DOCS) $(NML_DOCS)

install: install_docs install_code

install_code:
	install -d -m 755 $(MODPATH)
	install -m 644 $(MODULES) $(MODPATH)
	python -c "import compilall; compileall.main()" $(MODPATH)

install_docs:
	install -d -m 755 $(DOCPATH)
	install -m 644 $(NML_DOCS) $(MOD_DOCS) $(DOCPATH)
	for x in $(MOD_DOCS:.html=); do \
		if [ -e $$x ]; then cp -r $$x $(DOCPATH); fi; \
	done

uninstall: uninstall_docs uninstall_code
	
uninstall_docs:
	rm -rf $(DOCPATH)

uninstall_code:
	rm -rf $(MODPATH)
