# Makefile - file to build idea module from retreived source
#
# Copyright (C) 1999 Josip Rodin.
# Copyright (C) 1999 Tom Lees.
# Copyright (C) 2002, 2004 Arthur de Jong.
#
# 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, 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.
#
# On Debian GNU/Linux systems, the complete text of the GNU General Public
# License can be found in /usr/share/common-licenses/GPL.

PACKAGE=gnupg-idea
VERSION=$(shell head -1 debian/changelog | sed -n 's/^gnupg-idea *(\([0-9a-zA-Z.]*\)).*$$/\1/p')
distdir=$(PACKAGE)-$(VERSION)

# these are the targets to build the idea module:
all: idea
%: %.c checkmd5
	gcc -Wall -shared -O2 -fPIC -o $@ $<
%.c: %.c.Z
	zcat $< > $@
%.c: %.c.gz
	zcat $< > $@
idea.c.gz:
	wget -N ftp://ftp.gnupg.dk/pub/contrib-dk/idea.c.gz
checkmd5: idea.c
	( FILE=idea.c ;\
	  MD5SUM=`md5sum $$FILE | sed 's/^\([0-9A-Fa-f]*\)[^0-9A-Fa-f].*$$/\1/'` ;\
	  DSC=`sed -n "s/^## $$MD5SUM *//p" < Makefile` ;\
	  if [ -n "$$DSC" ] ; then \
	    echo "$$FILE: MD5=$$MD5SUM $$DSC" ;\
	  else \
	    echo "$$FILE: MD5=$$MD5SUM ERROR: downloaded file unknown!" ;\
	    exit 1 ;\
	  fi )
	touch checkmd5
clean:
	rm -f idea idea.c checkmd5

# these are developer targets:
distdir:
	rm -rf $(distdir)
	mkdir $(distdir)
	mkdir $(distdir)/debian
	cp -p {Makefile,README,TODO,ChangeLog} $(distdir)/
	cp -p debian/{changelog,control,copyright,rules} $(distdir)/debian/
	chmod -R u+rwX,go+rX,go-w $(distdir)
dist: distdir
	cd $(distdir) && \
	  dpkg-buildpackage -S \
	      -pgpg -sgpg \
	      -kadejong@debian.org \
	      -rfakeroot
	rm -rf $(distdir)
changelog:
	cvs2cl --window 3600 --accum --prune

.PHONY: all clean distdir dist deb signeddeb

# m5sums for idea.c file:
## b98f4593369d16079c6534cd39880441 WARNING: idea module 1.8 for older version of gnupg
## 62c8a35a2cb6479f1b93a8ad559e1bc3 OK: idea module 1.11 for gnupg
## c4d44c7b322ae4e8c901be5d86a9acc0 OK: idea module 1.11 for gnupg
## 36eeaa4028107c4c3f518aa6cd3bdf5d OK: idea module 1.11 for gnupg
