#!/usr/bin/make -f

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

build: build-stamp
build-stamp: build-arch build-indep
	touch build-stamp
build-arch: build-nongtk build-gtk
build-indep: build-doc

build-nongtk:
	dh_testdir

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

	# radare non gtk edition
	./configure --prefix=/usr --includedir=/usr/include \
	--mandir=/usr/share/man --sysconfdir=/etc \
	--libexecdir=/usr/lib --without-gui --without-nonfree

	$(MAKE)

	# get non gtk radare binary
	cp src/radare radare

build-gtk:
	dh_testdir

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

	# radare gtk edition
	./configure --prefix=/usr --includedir=/usr/include \
	--mandir=/usr/share/man --sysconfdir=/etc \
	--libexecdir=/usr/lib --without-nonfree

	$(MAKE)

build-doc:
	# build documentary (radare book)
	cd doc && $(MAKE) && cd ..

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# clean up build process
	[ ! -f Makefile ] || $(MAKE) clean
	rm -f radare
	dh_clean

install: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

binary-common:
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installmenu
	dh_installman
	dh_installchangelogs
	dh_python2 -V $(shell pyversions -vd)
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

binary-arch: build-arch install
	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

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