#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
				CFLAGS += -O0
else
				CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
				dh_testdir
				# Add here commands to configure the package.

				touch configure-stamp

build: build-stamp

build-stamp: configure-stamp
				dh_testdir

				# Add here commands to compile the package.
				./build docs

				touch $@

clean:
				dh_testdir
				dh_testroot
				rm -rf build-stamp configure-stamp debian/c++-annotations COPYING

				# Add here commands to clean up after the build process.
				./build clean

				dh_clean

install: build
				dh_testdir
				dh_testroot
				dh_prep
				dh_installdirs

				# Add here commands to install the package into debian/c++-annotations.
				#./build install debian/c++-annotations

# Build architecture-independent files here.
# binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
# binary-arch: build install
binary-indep: build install
				dh_testdir
				dh_testroot
				dh_installchangelogs -A changelog
				dh_installdocs   -A README README.papersize README.PORTUGUESE README.legalese debian/copyright
				cp -ra tmp/docs/html	debian/c++-annotations-html/usr/share/doc/c++-annotations/
				cp -ra contrib  debian/c++-annotations-html/usr/share/doc/c++-annotations/html/
				cp -a  tmp/docs/txt/cplusplus.txt				debian/c++-annotations-txt/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplus.latex   debian/c++-annotations-latex/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplus.sty				debian/c++-annotations-latex/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplusus.latex debian/c++-annotations-latex/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplusus.sty   debian/c++-annotations-latex/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplus.pdf				debian/c++-annotations-pdf/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplusus.pdf   debian/c++-annotations-pdf/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplus.ps				debian/c++-annotations-ps/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplusus.ps	debian/c++-annotations-ps/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplus.dvi				debian/c++-annotations-dvi/usr/share/doc/c++-annotations/
				cp -a  tmp/docs/latex/cplusplusus.dvi   debian/c++-annotations-dvi/usr/share/doc/c++-annotations/
				cp -ra contributions	debian/c++-annotations-contrib/usr/share/doc/c++-annotations/
				cp -ra contrib  debian/c++-annotations-contrib/usr/share/doc/c++-annotations/
				mkdir  debian/c++-annotations/usr/share/doc/c++-annotations/examples
				for e  in `find -type d -name examples | grep -v ^./debian`; \
				do cp  -r --parents   "$$e" debian/c++-annotations/usr/share/doc/c++-annotations/examples; done
				dh_installman -pc++-annotations tmp/man/c++-annotations.7
				dh_compress				  -A   -X.html -X.gif -X.pdf
				dh_fixperms
				dh_installdeb
				dh_gencontrol
				dh_md5sums
				dh_builddeb

# The following is for internal development usage only
# Update that sum when new _upstream_ releases occur, this
# catches silent file content forges at the upstream server side

# Downloaded from ftp.rug.nl/contrib/frank/documents/annotations:
MD5TRUSTED := 611ec8fbff69971e866c9443fc6ca83e

DEBVERSION:=$(shell head -n 1 debian/changelog | sed -e 's/^[^(]*(\([^)]*\)).*/\1/')
UPVERSION:=$(shell echo $(DEBVERSION) | sed -e 's/^.*://' -e 's/-[0-9.]*$$//' -e 's/.dfsg$$//')
UPNAME := c++-annotations
UPFILE := $(UPNAME)_$(UPVERSION).tar.gz
DEFILE := $(UPNAME)_$(UPVERSION).orig.tar.gz

URL				   := https://www.icce.rug.nl/debian/annotations
MD5CURRENT := `md5sum ../tarballs/$(DEFILE) | sed -e 's/ .*//'`

get-orig-source:
				@@dh_testdir
				@@[ -d ../tarballs/. ]||mkdir -p ../tarballs

				-@if [ ! -f ../tarballs/$(DEFILE) ] ; then \
				echo "Downloading $(URL)/$(UPFILE) from $(URL)/$(UPFILE) ..." ; \
				wget --no-check-certificate --quiet -nv -T10 -t3 \
				-O ../tarballs/$(DEFILE) $(URL)/$(UPFILE) ; \
				else \
				echo "Upstream source tarball have been already downloaded" ; \
				fi

				-@if [ "$(MD5CURRENT)" != "$(MD5TRUSTED)" ] ; then \
				echo "Expecting upstream filename md5sum $(MD5TRUSTED), but $(MD5CURRENT) found" ; \
				echo "Upstream filename md5sum is NOT trusted! Possible upstream filename forge!" ; \
				false ; \
				else \
				echo "Upstream filename md5sum is trusted!" ; \
				fi

print-version:
				@@echo "Debian version:  $(DEBVERSION)"
				@@echo "Upstream version:				 $(UPVERSION)"


binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
