#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/utils.mk

DEB_AUTO_UPDATE_ACLOCAL = $(shell dpkg -s automake | perl -nle '/^Version: (?:\d:)?(\d+\.\d+)?/ and print $$1')
DEB_AUTO_UPDATE_AUTOCONF = $(shell dpkg -s autoconf | perl -nle '/^Version: (?:\d:)?(\d+\.\d+)?/ and print $$1')
DEB_AUTO_UPDATE_AUTOMAKE = $(shell dpkg -s automake | perl -nle '/^Version: (?:\d:)?(\d+\.\d+)?/ and print $$1')
DEB_AUTO_UPDATE_LIBTOOL = pre

DEB_AUTOMAKE_ARGS += --add-missing -Wno-portability

DEB_CONFIGURE_EXTRA_FLAGS = --with-layout=debian \
		--program-transform-name='s/isql$$/isql-vt/;s/isqlw/isqlw-vt/' \
		--with-readline --without-internal-zlib --with-debug

ifeq ($(DEB_BUILD_ARCH),alpha)
		EXTRA_LDFLAGS += -Wl,--no-relax
endif

EXTRA_LDFLAGS += $(shell dpkg-buildflags --get LDFLAGS)

ifeq (hurd,$(findstring hurd,$(DEB_BUILD_ARCH)))
		CFLAGS += -D_GNU_SOURCE
endif

ifeq (kfreebsd,$(findstring kfreebsd,$(DEB_BUILD_ARCH)))
		CFLAGS += -D_GNU_SOURCE
endif

DEB_CONFIGURE_SCRIPT_ENV += \
		LDFLAGS="-Wl,-z,defs -Wl,--no-undefined -Wl,--as-needed $(EXTRA_LDFLAGS)" \
		MONO_DISABLE_SHM=1 \
        DEBIANPKG=virtuoso-opensource-6.1

DEB_DH_INSTALL_ARGS := --sourcedir=debian/tmp

# update-rc.d is manually called in virtuoso-opensource-6.1.postinst
# See note there.
DEB_DH_INSTALLINIT_ARGS += --noscripts

# Disabled for now
#DEB_MAKE_INVOKE += -j
#.NOTPARALLEL:

clean::
	debconf-updatepo

build/virtuoso-opensource-6.1::
	cd debian; find . -name "*.?.xml" -exec docbook2x-man --solinks {} \;

cleanbuilddir/virtuoso-opensource-6.1::
	rm -f debian/*.1

build/libvirtuoso5.5-cil::
	$(MAKE) -C binsrc/VirtuosoClient.Net -f Makefile.mono
	chmod -x binsrc/VirtuosoClient.Net/OpenLink.Data.Virtuoso.dll

cleanbuilddir/libvirtuoso5.5-cil::
	$(MAKE) -C binsrc/VirtuosoClient.Net -f Makefile.mono clean

binary-install/libvirtuoso5.5-cil::
	dh_installcligac

binary-predeb/libvirtuoso5.5-cil::
	dh_makeclilibs
	dh_clideps -d

get-orig-source:
	-uscan --download --verbose
