#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

ifneq (,$(filter $(DEB_BUILD_ARCH),arm64 armel armhf mips mips64el mipsel hppa kfreebsd-amd64 kfreebsd-i386 sparc64))
  CACHE_FLAG = --with-memhinfo=L2:4/64/512K,L1:8/64/24K
else
  CACHE_FLAG =
endif

export DEB_CFLAGS_MAINT_APPEND  = -O3

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure --			\
	    $(CACHE_FLAG)			\
	    --with-hwloc			\
	    --enable-matrix-types=blas		\
	    --with-zlib=-lz			\
	    --enable-doc-build			\
	    --enable-fortran-module-install	\
	    --prefix=/usr

override_dh_auto_build:
	dh_auto_build
	rm -f doc/html/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js doc/html/jquery.js

override_dh_auto_install:
	dh_auto_install
	sed -i -e 's/\\\(leftarrow\|alpha\)/\\\\\1/g' debian/tmp/usr/share/man/man3/*.h.3
	sed -i -e 's/\\n$$//g' debian/tmp/usr/share/man/man3/rsb.h.3

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	make qtests
	(cd debian ;							\
	 gcc -o rsb127_bugfix -I.. rsb127_bugfix.c -L../.libs -lrsb; 	\
	 LD_LIBRARY_PATH=../.libs ./rsb127_bugfix )
endif
