#!/usr/bin/make -f

ifeq "$(DEB_BUILD_ARCH)" "armhf"
	OPTIONS=--disable-optimize
endif


ifneq (,$(findstring parallel=,$(DEB_BUILD_OPTIONS)))
	NCPUS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
	NCPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
	ifeq ($(NCPUS),-1)
		NCPUS:=1
	endif
	ifeq ($(NCPUS),0)
		NCPUS:=1
	endif
endif

export DEB_CXXFLAGS_MAINT_APPEND = -fpermissive -Wno-narrowing

%:
	dh $@

override_dh_auto_configure:
	cd mp4v2 && ./configure $(CROSS) CFLAGS="$(CFLAGS)" $(OPTIONS) --disable-gch
	cd faad2 && ./configure $(CROSS) CFLAGS="$(CFLAGS)" --without-xmms --without-mpeg4ip

	dh_auto_configure

override_dh_auto_build:
	$(MAKE) -C mp4v2 -j $(NCPUS)
	$(MAKE) -C faad2 -j $(NCPUS)

	$(MAKE) -j $(NCPUS)

override_dh_clean:
	if [ -f mp4v2/GNUmakefile ] ; then cd mp4v2 && $(MAKE) distclean ; fi
	if [ -f faad2/Makefile ] ; then cd faad2 && $(MAKE) distclean ; fi
	dh_clean aacgain/config.h mpeg4ip_config.h faad2/config.h mpeg4ip_config.h

# No dbgsym packages:
override_dh_strip:
	dh_strip --no-automatic-dbgsym
