#!/usr/bin/make -f

PACKAGE=z88

# DPatch
DEB_SOURCE_PACKAGE:=$(PACKAGE)


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

# set the number of build jobs
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        JOBS := -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

get-orig-source:
	. debian/get-orig-source

BUILD_PATH = DEB_build

CMAKE_FLAGS = -DCMAKE_INSTALL_PREFIX:PATH=/usr \
              -DCMAKE_VERBOSE_MAKEFILE=$(DH_VERBOSE) \
              -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed" \
              -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed" \
              -DCMAKE_SKIP_RPATH:BOOL=ON \
              -DCMAKE_BUILD_TYPE="Release" \

configure: configure-stamp
configure-stamp: 
	dh_testdir
	# Add here commands to configure the package.

	if [ ! -d $(BUILD_PATH) ]; then mkdir $(BUILD_PATH); fi
	cd $(BUILD_PATH) \
            && cmake $(CURDIR)/src/ $(CMAKE_FLAGS)

	touch $@


build: build-arch

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

        # Add here commands to compile the package.

        # build shared libs and binaries
	$(MAKE) $(JOBS) -C $(BUILD_PATH)

	touch $@


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

	touch $@


clean: clean-patched

clean-patched:
	dh_testdir
	dh_testroot

	# Add here commands to clean up after the build process.
	rm -rf $(BUILD_PATH)

	dh_clean 


install: install-indep install-arch

install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep  
	dh_installdirs

	# Add here commands to install the package into debian/tmp
	$(MAKE) $(JOBS) -C $(BUILD_PATH) install DESTDIR=$(CURDIR)/debian/tmp

	dh_install -pz88        debian/tmp/usr/bin/* z88             usr/bin
	dh_install -pz88        z88.fcd z88.dyn                      usr/share/z88
	dh_install -pz88        debian/z88.desktop                   usr/share/applications

install-indep: build-indep
	dh_install -pz88-data   data/*                               usr/share/z88


# Build architecture-independent files here.
binary-indep: install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture-dependent files here.
binary-arch: install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

# Build architecture-dependent files here.
binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installmenu
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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