#!/usr/bin/make -f

# Support multiple makes at once
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
NUMJOBS = -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
# on i386 and amd64, we query the system unless overriden by DEB_BUILD_OPTIONS
ifeq      ($(DEB_HOST_ARCH),i386)
NUMJOBS := -j$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
else ifeq ($(DEB_HOST_ARCH),amd64)
NUMJOBS := -j$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
endif
endif

CFLAGS = `dpkg-buildflags --get CFLAGS`
CFLAGS += `dpkg-buildflags --get CPPFLAGS`
LDFLAGS = `dpkg-buildflags --get LDFLAGS`

confflags := --prefix=/usr \
	--confdir=/etc/mplayer \
	--enable-translation \
	--disable-svga \
	--extra-cflags="${CFLAGS}" \
	--extra-ldflags="${LDFLAGS}" \
	--enable-debug=3

# runtime cpu detection works on x86 and ppc only. These checks also work on kfreebsd!
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
ifeq ($(DEB_HOST_GNU_CPU),i486)
	confflags += --enable-runtime-cpudetection
endif
ifeq ($(DEB_HOST_GNU_CPU),x86_64)
	confflags += --enable-runtime-cpudetection
endif
ifeq ($(DEB_HOST_GNU_CPU),powerpc)
	confflags += --enable-runtime-cpudetection
endif
ifeq ($(DEB_HOST_GNU_CPU),sparc)
        confflags += --target=generic
endif

%:
	dh $@

override_dh_auto_configure:
	./configure $(confflags)

override_dh_auto_build:
	make V=1 $(NUMJOBS)

override_dh_install:
	dh_install
	find debian/mplayer2/ -type d -empty -delete

override_dh_strip:
	dh_strip --dbg-package=mplayer2-dbg

override_dh_clean:
	dh_clean
