#!/usr/bin/make -f
# -*- makefile -*-
# GNU copyright 1997 to 1999 by Joey Hess.

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

CFLAGS = -Wall -g

PACKAGE = libss7

-include /usr/share/quilt/quilt.make

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

PKGNAME:=$(shell sed -nre 's/^Package: (.*[0-9])$$/\1/p' debian/control)
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$$//')
UPVERSIONMAJOR:=$(shell echo $(UPVERSION) | sed -re 's/(^[0-9]\.[0-9]).*/\1/')
SHLIBS = $(PKGNAME) (>= $(UPVERSIONMAJOR))

FILENAME := $(PACKAGE)_$(UPVERSION).orig.tar.gz
URL := http://downloads.digium.com/pub/telephony/$(PACKAGE)/releases/$(PACKAGE)-$(UPVERSION).tar.gz

%:
	dh $@

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_mkshlibs:
	dh_makeshlibs -V "$(SHLIBS)"

override_dh_strip:
	dh_strip --dbg-package=libss7-dbg

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

get-orig-source:
	@@dh_testdir
	@@[ -d ../tarballs/. ]||mkdir -p ../tarballs
	@@echo Downloading $(FILENAME) from $(URL) ...
	@@wget -nv -T10 -t3 -O ../tarballs/$(FILENAME) $(URL)

