#
# Installation Makefile for gendoc
#
# $History: Makefile,v $
#

PYTHON_BIN = `python -c "import sys; print sys.prefix + '/bin'"`
PYTHON_LIB = `python -c "import sys; print sys.prefix + '/lib/python' + sys.version[:3] + '/site-packages'"`

PROG    = pythondoc
PACKAGE = pythondoc

INSTALL = install
#INSTALL = /opt/imake/bin/bsdinst # On HP/UX 10.20

INSTALL_PRG = $(INSTALL) -c -m 755
INSTALL_DATA= $(INSTALL) -c -m 644

VERSION = 0.6
CVS_VERSION = R0_6

DOCS=        README.html \
	     LICENSE.TXT \
	     Makefile \
	     test.py

MODULES    = StructuredText.py \
	     __init__.py \
	     codeutil.py \
	     docobjects.py \
	     docregex.py \
	     docstring.py \
	     doctree.py \
	     geninfo.py \
	     gui.py \
	     message.py \
	     options.py \
             pythondoc.py \
	     regex_util.py \
	     stdmarkup.py \
	     utilities.py \
	     version.py \
             formatters/__init__.py \
	     formatters/format_init.py \
	     formatters/HTML4Formatter.py \
	     formatters/HTML4strings.py \
	     formatters/XMLFormatter.py \
	     formatters/SaveFormatter.py \
	     xref/__init__.py \
	     xref/xref.py \
	     xref/internalXref.py

INSTALL_FILES = \
	     pythondoc.opts \
	     formatters/HTML4styles.css \
	     formatters/HTML4ValidateFooter.html \
	     formatters/HTML4StdHeader.html

all:
	@echo Type \"make install\" to install $(PACKAGE).
	@echo The program $(PROG) will be put in $(PYTHON_BIN)
	@echo The modules will be put in $(PYTHON_LIB) as the
	@echo package $(PACKAGE).
	@echo
	@echo You can control the path to the bin and the lib
	@echo directories by setting PYTHON_BIN and PYTHON_LIB
	@echo respectively.
	@echo
	@echo You can also try running \"make test\", which will
	@echo build HTML4 pages for pythondoc itself in /tmp/html.

install:
	@-mkdir $(PYTHON_BIN) 2>/dev/null || true
	@$(INSTALL_PRG) $(PROG) $(PYTHON_BIN)/$(PROG)

	@-mkdir $(PYTHON_LIB)/$(PACKAGE) 2>/dev/null || true
	@-mkdir $(PYTHON_LIB)/$(PACKAGE)/formatters 2>/dev/null || true
	@-mkdir $(PYTHON_LIB)/$(PACKAGE)/xref 2>/dev/null || true

	@for file in $(MODULES) $(INSTALL_FILES); do \
	    $(INSTALL_DATA) $$file $(PYTHON_LIB)/$(PACKAGE)/$$file; \
	done

	@cd /tmp; for file in $(MODULES); do \
	    test `basename $$file` = __init__.py && file=`dirname $$file`.py; \
	    test $$file = ..py && continue; \
	    echo Compiling $$file; \
	    python -c "from string import *; t=maketrans('/','.'); m=translate('$(PACKAGE)/$$file',t);__import__(m[:-3])"; \
	    python -O -c "from string import *; t=maketrans('/','.'); m=translate('$(PACKAGE)/$$file',t);__import__(m[:-3])"; \
	done

	@echo Installation of $(PACKAGE) done.
	@bindir=$(PYTHON_BIN); \
	echo Type $$bindir/$(PROG) -? for usage.

# Need to fix this!!
patch:
	@echo Making a patch for $(VERSION)

	@for file in $(DOCS) $(MODULES) $(INSTALL_FILES); do \
	  rcsdiff -r$(CVS_VERSION) -c $$file; \
	done > patch$(PATCH)

DIST_DOCS = $(addprefix $(PACKAGE)-$(VERSION)/, $(DOCS))
DIST_MODULES = $(addprefix $(PACKAGE)-$(VERSION)/, $(MODULES))
DIST_INSTALLS = $(addprefix $(PACKAGE)-$(VERSION)/, $(INSTALL_FILES))

dist:
	(cd ..; mv $(PACKAGE) $(PACKAGE)-$(VERSION); tar cf - $(DIST_DOCS) $(DIST_MODULES) $(DIST_INSTALLS) $(PACKAGE)-$(VERSION)/$(PROG)) | gzip --best > $(PACKAGE)-$(VERSION).tgz
	cd ..; mv $(PACKAGE)-$(VERSION) $(PACKAGE)

release:
	@if (cvs status | grep Modified > /dev/null); then \
	    false; \
	else \
	    true; \
	fi;
	cvs tag $(CVS_VERSION)

test:
	@echo Building HTML4 output for pythondoc in /tmp/html.
	@echo pythondoc sources in the current directory will be
	@echo used (run \"make test_install\" to use the installed
	@echo pythondoc).
	@export PYTHONPATH=$$PWD; \
	cp pythondoc /tmp; \
	cd /tmp; \
	mkdir html; \
	./pythondoc -f HTML4 -i -d html pythondoc

test_install:
	@echo Building HTML4 output for pythondoc in /tmp/html2.
	@echo The installed pythondoc will be used.
	cd /tmp; \
	mkdir html2; \
	./pythondoc -f HTML4 -i -d html2 pythondoc


