#!/usr/bin/make -f

#export DH_VERBOSE=1
export DH_COMPAT=4

# package name
PACKAGE = eyebot-debugger

# build, host, target platform for the toolchain
DEB_BUILD_GNU_TYPE      := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE       := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_TARGET_GNU_TYPE     := m68k-eyebot-elf

SOURCE_DIR = /usr/local/src
SOURCE_ARCHIVES += gdb-5.2.1

PREFIX = /usr

PATCHLIST = 10m68k-bdm-gdb 20m68k-eyebot-elf-debugger

include /usr/share/dpatch/dpatch.make
	
unpack: unpack-stamp
unpack-stamp:
	for f in $(SOURCE_ARCHIVES); do debian/scripts/unpack $(SOURCE_DIR)/$$f; done
	mv gdb-* src
	touch unpack-stamp

configure: unpack patch-stamp configure-stamp
configure-stamp:
	dh_testdir

	# configure in build
	mkdir -p build
	cd build && \
	../src/configure --prefix=$(PREFIX) \
	       --infodir=$$\{prefix\}/share/info \
	       --mandir=$$\{prefix\}/share/man \
	       --build=$(DEB_BUILD_GNU_TYPE) \
	       --host=$(DEB_HOST_GNU_TYPE) \
	       --target=$(DEB_TARGET_GNU_TYPE) \
	       --with-gnu-as \
	       --with-gnu-ld \
	       --enable-nls \
	       --without-included-gettext
	touch configure-stamp

build: configure build-stamp
build-stamp: 
	dh_testdir
	cd build && $(MAKE)
	touch build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd build && $(MAKE) install \
            prefix=$(CURDIR)/debian/$(PACKAGE)/$(PREFIX) \
	    
   
	# set up manpages
	rm -rf debian/$(PACKAGE)/$(PREFIX)/share/man/man7

	# don't need these
	rm -rf debian/$(PACKAGE)/$(PREFIX)/{include,lib}

	# don't want info pages and LC_MESSAGES; you can use the ones from the host's toolchain
	rm -rf debian/$(PACKAGE)/$(PREFIX)/share/{info,locale}

	# package-specific stuff
	mkdir -p debian/$(PACKAGE)/$(PREFIX)/share/$(PACKAGE)
	cp -r bdm-driver debian/$(PACKAGE)/$(PREFIX)/share/$(PACKAGE)
	cp gdbinit dddbuttons debian/$(PACKAGE)/$(PREFIX)/share/$(PACKAGE)
	cp gdb68 ddd68 debian/$(PACKAGE)/$(PREFIX)/bin

clean: unpatch
	dh_testdir
	dh_testroot
	-make -C bdm-load clean
	-make -C bdm-driver clean
	rm -rf src build
	rm -f build-stamp configure-stamp unpack-stamp

	dh_clean


# 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
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
	dh_installmodules
	dh_installman
#	dh_installinfo
	dh_installchangelogs
	dh_link
	dh_strip --exclude=.o --exclude=.a
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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