#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

PACKAGE=sdl-net1.2
include /usr/share/quilt/quilt.make

CFLAGS=-Wall -g -I/usr/include/SDL/

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

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

# FOR AUTOCONF 2.52 AND NEWER ONLY
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

# only examples needs gui
confflags += --disable-gui


configure: configure-stamp
configure-stamp:
	dh_testdir
	dh_quilt_patch
	cp -f /usr/share/misc/config.sub /usr/share/misc/config.guess .
	./autogen.sh
	./configure --prefix=/usr \
		$(confflags)

	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir

	$(MAKE) CFLAGS="$(CFLAGS)" LDFLAGS=-D_REENTRANT

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	[ ! -f Makefile ] || $(MAKE) distclean

	rm -f config.sub config.guess
	dh_quilt_unpatch
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	dh_install --sourcedir=debian/tmp --list-missing


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

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_movefiles

	dh_installdocs
	dh_installexamples
	dh_installman
	dh_installchangelogs CHANGES
	dh_link
	dh_strip $(STRIPARGS)
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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