+SRCPACKAGE=$(shell head -1 $(CURDIR)/debian/changelog | sed 's/\(.[^ ]*\) .*/\1/')
+MAJOR=$(shell head -1 $(CURDIR)/debian/changelog | sed 's/.*(\(.*\)-[^-]*).*/\1/')
+ORIGFILE=$(SRCPACKAGE)_$(MAJOR).orig.tar.gz
+OLDPACKAGE=gforge
+PACKAGE=fusionforge
+FORGENAME=FusionForge
+
+SED_REPLACE=sed -e 's/@PACKAGE@/$(PACKAGE)/g' -e 's/@SRCPACKAGE@/$(SRCPACKAGE)/g' -e 's/@FORGENAME@/$(FORGENAME)/g' -e 's/@OLDPACKAGE@/$(OLDPACKAGE)/g'
+
+CRONDFILES=$(patsubst packaging/cron.d/%,debian/$(PACKAGE)-%.cron.d,$(wildcard packaging/cron.d/[a-z]*))
+DIRSFILES=$(patsubst packaging/dirs/%,debian/$(PACKAGE)-%.dirs,$(wildcard packaging/dirs/[a-z]*))
+LINKSFILES=$(patsubst packaging/links/%,debian/$(PACKAGE)-%.links,$(wildcard packaging/links/[a-z]*))
+INSTALLFILES=$(patsubst packaging/install/%,debian/$(PACKAGE)-%.install,$(wildcard packaging/install/[a-z]*))
+DOCSFILES=$(patsubst packaging/docs/%,debian/$(PACKAGE)-%.docs,$(wildcard packaging/docs/[a-z]*))
+POFILES=$(patsubst debian/dsf-po/%,debian/po/%,$(wildcard debian/dsf-po/*) debian/po/POTFILES.in)
+
+.PHONY: conffiles
+conffiles: $(CRONDFILES) $(DIRSFILES) $(LINKSFILES) $(INSTALLFILES) $(DOCSFILES) debian/control
+
+debian/$(PACKAGE)-%.cron.d:
+ (cat $(CURDIR)/packaging/cron.d/00phpcron ; sed -e 's/\$$FFUSER/$(PACKAGE)/g' $(CURDIR)/packaging/cron.d/$*) > $@
+
+debian/$(PACKAGE)-%.dirs:
+ cp $(CURDIR)/packaging/dirs/$* $@
+
+debian/$(PACKAGE)-%.links:
+ cp $(CURDIR)/packaging/links/$* $@
+
+debian/$(PACKAGE)-%.install:
+ cp $(CURDIR)/packaging/install/$* $@
+
+debian/$(PACKAGE)-%.docs:
+ cp $(CURDIR)/packaging/docs/$* $@
+
+debian/control: $(wildcard packaging/control/*)
+ ls $(CURDIR)/packaging/control/[0-9][0-9][0-9]* | grep -v shortdesc | grep -v scmcpold | while read file ; do cat $${file}; if [ -f $${file}.shortdesc ] ; then cat $(CURDIR)/packaging/control/AAAdesc; echo ' .'; cat $${file}.shortdesc; fi; echo ''; done | $(SED_REPLACE) > $@
+
+debian/po/templates.pot: $(wildcard debian/dsf-in/*.templates.dsfh-in) $(wildcard debian/dsf-helper/*.templates)
+ @debconf-updatepo --podir=debian/dsf-po
+
+debian/po/%:
+ cat $(patsubst debian/po/%,debian/dsf-po/%,$@) | $(SED_REPLACE) > $@
+
+build: debian/po/templates.pot conffiles
+ dh $@
+ # Build gettext *.mo files
+ utils/manage-translations.sh build
+
+clean:
+ dh $@
+ rm -f $(CURDIR)/debian/*.cron.d
+ rm -f $(CURDIR)/debian/*.dirs
+ rm -f $(CURDIR)/debian/*.links
+ rm -f $(CURDIR)/debian/*.install
+ rm -f $(CURDIR)/debian/*.docs
+ rm -rf locales
+ rm -f $(POFILES)
+
+makeorig:
+ find $(PKGDIR) -type f -or -type l | grep -v '/CVS/' | \
+ grep -v '/.svn/' | grep -v '/.testbox/' | \
+ grep -v rpm-specific | grep -v docs/phpdoc/docs | \
+ grep -v ^./debian/ | grep -v \\.jar$$ | \
+ grep -v \\.pdf$$ | grep -v plugins/fckeditor/www/_samples | \
+ cpio -o -H ustar | gzip > ../$(ORIGFILE)