#!/usr/bin/make -f
# Copyright 2008-2010 Sylvestre Ledru <sylvestre@debian.org>

include /usr/share/cdbs/1/rules/debhelper.mk

COMMON_MAKE_OPTIONS = "NO_LAPACK=1"
ENABLE_DYNAMIC_ARCHS := amd64 i386 kfreebsd-amd64 kfreebsd-i386
ifneq (,$(findstring $(DEB_HOST_ARCH),$(ENABLE_DYNAMIC_ARCHS)))
	DYNAMIC_ARCH_ARG="DYNAMIC_ARCH=1"
endif

build: build-stamp

build-stamp:
	if test "$(TARGET)" = ""; then 		\
			echo "Support multiple architectures"; \
			$(MAKE) $(COMMON_MAKE_OPTIONS) $(DYNAMIC_ARCH_ARG);		\
	fi

	if test "$(TARGET)" = "custom"; then 		\
			echo "Leave the detection to GotoBLAS / OpenBLAS"; \
			$(MAKE) $(COMMON_MAKE_OPTIONS); 								\
	fi

	if test "$(TARGET)" != "" -a "$(TARGET)" != "custom"; then 		\
			echo "Use the value '$(TARGET)' provided by the user";	\
			$(MAKE) $(COMMON_MAKE_OPTIONS) TARGET=$(TARGET);									\
	fi;

	rm libopenblas.so
	mv libopenblasp-*.so libopenblas.so.0
	ln -s libopenblas.so.0 libopenblas.so
	mv libopenblasp-*.a libopenblas.a
	touch $@

custom: custom-stamp
	dch --local='+custom'  "custom build on: `uname -a`"
	LANG=C debian/rules TARGET=custom build binary

clean::
	$(MAKE) clean
	rm -f libopenblas.so.0

# Build a custom package optimized for the current arch
custom-stamp:

get-orig-source:
	-uscan --upstream-version 0
