#!/usr/bin/make -f

# Author: Jordi Sayol <g.sayol@yahoo.es>

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

# override dpkg-buildflags flags
CFLAGS =
CPPFLAGS =
CXXFLAGS =
FFLAGS =
LDFLAGS =

# DEB_BUILD_OPTIONS

ifneq (,$(findstring parallel,$(DEB_BUILD_OPTIONS)))
    PARALLEL_JOBS = $(shell echo $(DEB_BUILD_OPTIONS) | \
        sed -e 's/.*parallel=\([0-9]\+\).*/\1/')
    PARALLEL_OPTIONS = -j$(PARALLEL_JOBS)
endif

build: build-stamp

build-stamp:
	dh_testdir

	cmake -DCMAKE_INSTALL_PREFIX=/usr/brlcad -DBRLCAD_ENABLE_STRICT=OFF

	$(MAKE) $(PARALLEL_OPTIONS)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	dh_clean

install: install-stamp

install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -a
	dh_installchangelogs -a
	dh_install -a --list-missing
	dh_compress -a
	dh_fixperms -a
#	dh_makeshlibs -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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