# Makefile for p4 addins project

# Copyright (c) 2006 Qualcomm
# Miki Tebeka <mtebeka@qualcomm.com>

# You'll need the following programs to make the utilities:
# * Python from http://www.python.org
# * wxPython from http://www.wxpython.org
# * ElementTree from http://effbot.org/zone/element-index.htm
#   * Will be in Python 2.5 standard library
# * py2exe from http://www.py2exe.org/
# * sed, cp, chmod, rm and make from http://unxutils.sf.net 
#   (or use http://www.cygwin.com)
# * P4Python from http://tinyurl.com/lgzgm
# * docutils from http://docutils.sf.net
# * InnoSetup from http://www.jrsoftware.org/isinfo.php

# Find Python interpreter
PYTHON = $(shell pyexe.py)
# Find InnoSetup compiler
INNO = $(shell innoexe.py)
ICON = addins.ico

# List of sources
SOURCES = $(shell $(PYTHON) configure --sources)
# Source directory for unixdist
SRCDIST = p4vaddins-`cat VERSION`

ifeq ($(OSTYPE),cygwin)
CP = cp -f
RM = rm -fr
else
CP = xcopy /R /Y
RM = del /Q /F /S
endif

all: addins

addins: py README.html setup.iss copy_to_dist
	$(INNO) setup.iss

setup.iss: version.iss

version.iss: version.iss.in VERSION
	sed -e "s/_VERSION_/`cat VERSION`/" $< > $@

py:
	$(PYTHON) setup.py py2exe

copy_to_dist: README.html
	$(CP) $(ICON) dist
	$(CP) ChangeLog dist
	$(CP) install.cfg dist
	$(CP) README.html default.css dist
	$(CP) LICENSE.txt dist
ifeq ($(OSTYPE),cygwin)
	chmod +w dist/*
else
	attrib -R dist/*.*
endif

# FIXME: Find a solution for windows
README.html: README.txt style.css VERSION
	sed -e "s/_VERSION_/`cat VERSION`/" $< | rst2html.py --embed-stylesheet \
		--stylesheet=style.css - $@

clean:
	$(RM) dist build
	$(RM) *.pyc
	$(RM) README.html
	$(RM) $(SRCDIST) $(SRCDIST).tar.bz2

fresh: clean all

dist: all
ifeq ("$(DISTDIR)","")
	@echo "error: DISTDIR not set"
	@false
endif
	$(CP) dist/* $(DISTDIR)

unixdist: README.html
	mkdir $(SRCDIST)
	cp $(SOURCES) $(SRCDIST)
	cp README.html default.css $(SRCDIST)
	cp configure $(SRCDIST)
	cp p4vaddins.xml.in p4vaddins.txt.in $(SRCDIST)
	tar -cjf $(SRCDIST).tar.bz2 $(SRCDIST)
	rm -fr $(SRCDIST)

.PHONY: all dist clean fresh unixdist copy_to_dist