#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

DEB_BUILD_ARCH := $(shell dpkg-architecture -qDEB_BUILD_ARCH)

TARGET := profile-build ARCH=x86-32-old

ifneq (,$(findstring amd64,$(DEB_BUILD_ARCH)))
TARGET := profile-build ARCH=x86-64
endif

# no compile on the first shot so building without profile
ifneq (,$(findstring hppa,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

# no compile on the first shot
ifneq (,$(findstring powerpc,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring s390,$(DEB_BUILD_ARCH)))
TARGET := profile-build ARCH=general-32
endif

ifneq (,$(findstring sparc,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring mips,$(DEB_BUILD_ARCH)))
TARGET := profile-build ARCH=general-32
endif

# Profiling fails due to compiler issues
ifneq (,$(findstring mipsel,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring alpha,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-64
endif

# no compile on the first shot
ifneq (,$(findstring armel,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring armhf,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring ia64,$(DEB_BUILD_ARCH)))
TARGET := profile-build ARCH=general-64 optimize=no
endif

ifneq (,$(findstring m86k,$(DEB_BUILD_ARCH)))
TARGET := build ARCH=general-32
endif

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
TARGET2 := $(TARGET:profile-build=build)
else
TARGET2 := $(TARGET)
endif


ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
TESTCMD := 
else
TESTCMD := cd src && ./stockfish bench 32 1 10 default depth
endif


%:
	dh $@ --sourcedirectory=src

override_dh_auto_clean:
	cd src && rm -rf *.gcda && touch .depend && make clean

override_dh_auto_build:
#	cd src && make $(TARGET2)
	dh_auto_build --sourcedirectory=src  -- $(TARGET2)

override_dh_auto_test:
	$(TESTCMD)

override_dh_installman:
	dh_installman debian/stockfish.6
