#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.
#export DH_VERBOSE=1

package=libjpeg

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)


export LDFLAGS=-Wl,-z,relro
export CFLAGS=-g -Wall -Wno-main
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

export AUTOMAKE = automake-1.15
export ACLOCAL = aclocal-1.15
export AUTOHEADER = true

build: build-stamp 
build-stamp: 
	dh_testdir
	dh_autoreconf
	./configure --prefix=/usr --mandir=/usr/share/man \
	 --libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
	 --enable-static --enable-shared \
	 --disable-silent-rules \
	 --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE) 
	$(MAKE)
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) check
endif
	$(MAKE) -C debian/extra CC="$(DEB_HOST_GNU_TYPE)-gcc"\
                   CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-rm -f build-stamp
	if [ -f Makefile ]; then $(MAKE) distclean; fi
	$(MAKE) clean -C debian/extra
	dh_autoreconf_clean
	dh_clean

binary-indep: 

binary-arch: build
	dh_testdir 
	dh_testroot 
	dh_prep
	dh_installdirs 
	$(MAKE) install DESTDIR=`pwd`/debian/tmp
	$(MAKE) install -C debian/extra prefix=/usr DESTDIR=`pwd`/debian/tmp
	# fix jconfig.h 
	rm debian/tmp/usr/include/jconfig.h
	mkdir debian/tmp/usr/include/$(DEB_HOST_MULTIARCH)
	sed -e "s/#\(undef\|define\) HAVE_\(LOCALE\|\(STD\(DEF\|LIB\)\)\)_H 1//g" \
		jconfig.h > debian/tmp/usr/include/$(DEB_HOST_MULTIARCH)/jconfig.h
	# separate out lib package
	dh_movefiles
	# Finish it off with debhelper
	dh_installdocs README
	dh_installexamples 
	dh_installchangelogs change.log
	dh_strip --dbg-package=libjpeg9-dbg
	dh_compress 
	dh_fixperms 
	dh_installdeb 
	dh_shlibdeps -l`pwd`/debian/libjpeg9/usr/lib/$(DEB_HOST_MULTIARCH)
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb 

binary:	binary-indep binary-arch

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