# Copyright (C) 2002 John Goerzen
# <jgoerzen@complete.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

FILE = gpgme
CPATH = generated
PYPATH = pyme
PYFILE = $(FILE).py
CFILE = $(FILE)_wrap.c
SWIGSOURCE = $(FILE).i
DOCMODSDIRS := $(shell find pyme -type d | grep -v svn | sed 'sx/x.xg')
DOCMODSFILES := $(shell find pyme -name "*.py" | grep -v __init__ | grep -v svn | sed 'sx/x.xg')
DOCMODS := $(DOCMODSDIRS) $(DOCMODSFILES:.py=)
SWIGOPT := `gpgme-config --cflags` -I/usr/local/include -I/usr/include 

all:
	@echo "This package is not built with make."
	@echo "To build this package, please run:"
	@echo "   python setup.py"
	@echo "Or read INSTALL for more details."

info:
	@echo $(DOCMODS)

swig: $(CPATH)/$(CFILE) $(PYPATH)/$(PYFILE)

#$(SWIGSOURCE): $(SWIGSOURCE)0
#	SWIGOPT="$(SWIGOPT)" perl callback/mkcallback.pl -python \
#		$(SWIGSOURCE)0 > $(SWIGSOURCE)

$(CPATH)/$(CFILE) $(PYPATH)/$(PYFILE): $(SWIGSOURCE) helpers.h
	swig -python $(SWIGOPT) $(SWIGSOURCE)
	mv $(CFILE) $(CPATH)/$(CFILE)
	mv $(PYFILE) $(PYPATH)/$(PYFILE)

clean:
	-python2.2 setup.py clean --all
	-rm -r build build2.2 build2.3 setup.cfg
	-rm `find . -name "*~"` `find . -name "*.pyc"` `find . -name "*.so"`
	-find . -name auth -exec rm -vf {}/password {}/username \;
	-svn cleanup

changelog:
	svn log -v > ChangeLog

reallyclean: clean
	-rm doc/*.html doc/gpgme/*.html generated/* $(PYPATH)/$(PYFILE)

doc: pydocs texidocs

pydocs:
	-rm doc/*.html
	cd doc; for MOD in $(DOCMODS); do PYTHONPATH=`echo ../build/lib*` pydoc -w $$MOD; done

texidocs:
	-rm doc/gpgme/*.html
	cd doc/gpgme; texi2html -split=chapter gpgme.texi

# This code was once used, but is now assumed as part of setup.py.
#_$(FILE).so: $(FILE)_wrap.c helpers.c
#	gcc -shared -fPIC -o _$(FILE).so helpers.c $(FILE)_wrap.c `gpgme-config --libs` \
#		`gpgme-config --cflags` -I/usr/include/python2.2

