#! /usr/bin/make -f

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

# This is the debhelper compatibility version to use.
export DH_COMPAT=3

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_SYSTEM ?= $(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM)
DEB_BUILD_GNU_SYSTEM ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_SYSTEM)

CFLAGS = -O2
CXXFLAGS = -O2

# Use soft-float and thumb mode if it enabled.
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -mthumb
	CXXFLAGS += -mthumb
endif

export CFLAGS CXXFLAGS

CONFIGURE_ARGS = --host=${DEB_HOST_GNU_TYPE} --build=${DEB_BUILD_GNU_TYPE} --prefix=/usr --mandir=/usr/share/man --disable-dependency-tracking --without-ca-bundle --without-libidn --disable-gopher --disable-ldap --disable-dict --disable-telnet --disable-manual --disable-ares --disable-sspi

build: build-stamp

#configure-stamp: DH_OPTIONS=
configure-stamp:
	dh_testdir
	mkdir -p debian/build
	cd debian/build && ../../configure ${CONFIGURE_ARGS}

	touch configure-stamp

#build-stamp: DH_OPTIONS=
build-stamp: configure-stamp
	dh_testdir
	${MAKE} -C debian/build

	touch build-stamp

#test-stamp: DH_OPTIONS=
test-stamp: build-stamp
	dh_testdir
	touch test-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf test-stamp build-stamp configure-stamp debian/build

	dh_clean

#install: DH_OPTIONS=
install: build-stamp test-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	${MAKE} -C debian/build DESTDIR=`pwd`/debian/tmp install

	dh_movefiles

# Build architecture-independent files here.
#binary-indep: DH_OPTIONS=-i
binary-indep: build-stamp install
# We have nothing to do here.

# Build architecture-dependent files here.
#binary-arch: DH_OPTIONS=-a
binary-arch: build-stamp install
	dh_testdir
	dh_testroot
	dh_installdocs
	install -m 644 docs/*.html debian/libcurl3-dev/usr/share/doc/libcurl3-dev/html
	install -m 644 docs/libcurl/*.html debian/libcurl3-dev/usr/share/doc/libcurl3-dev/html/libcurl
	install -m 644 docs/*.pdf debian/libcurl3-dev/usr/share/doc/libcurl3-dev/pdf
	install -m 644 docs/libcurl/*.pdf debian/libcurl3-dev/usr/share/doc/libcurl3-dev/pdf/libcurl
	dh_installman
	dh_installexamples
	dh_installchangelogs CHANGES
	dh_link
	dh_strip --dbg-package=libcurl3
	dh_compress
	dh_fixperms
	dh_makeshlibs -plibcurl3 -V "libcurl3 (>= 7.13.1-1)"
	dh_installdeb
	dh_shlibdeps
	dh_md5sums

	dh_gencontrol -Nlibcurl3-gssapi
	dh_builddeb -Nlibcurl3-gssapi

binary: binary-indep binary-arch

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