#!/usr/bin/make -f

LIB_PKGS = $(shell sed -nr 's/^Package:[[:space:]]*(libx264-[0-9]+)[[:space:]]*$$/\1/p' debian/control)

ifeq ($(origin CC),default)
	CC := $(DEB_HOST_GNU_TYPE)-gcc
endif
export CC

ifeq ($(origin CXX),default)
	CXX := $(DEB_HOST_GNU_TYPE)-g++
endif
export CXX

%:
	dh $@ --with quilt

#,bash-completion

override_dh_auto_configure:
	./configure \
	--disable-avs \
	--disable-lavf \
	--disable-lsmash \
	--enable-debug \
	--enable-pic \
	--enable-shared \
	--enable-static \
	--host=$(DEB_HOST_GNU_TYPE) \
	--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
	--prefix=/usr \
	--system-libx264

#	exit 1

execute_before_dh_install:
	LD_LIBRARY_PATH=$(CURDIR):$(LD_LIBRARY_PATH) help2man -N --help-option=--fullhelp --name="video encoder for the H.264/MPEG-4 AVC standard" ./x264  > debian/x264.1

execute_before_dh_shlibdeps:
	$(CC) -xc -shared -Wl,--no-as-needed -o debian/libx264-recommends-dummy.so /dev/null \
	-lOpenCL

override_dh_shlibdeps:
	dh_shlibdeps

	dpkg-shlibdeps -dRecommends -edebian/libx264-recommends-dummy.so -xlibc6 -O >> debian/$(LIB_PKGS).substvars

override_dh_auto_clean:
	touch config.mak

	dh_auto_clean

override_dh_clean:
	dh_clean debian/libx264-recommends-dummy.so debian/x264.1
