#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed

export QT_SELECT := qt5

ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)

ifneq (,$(filter $(ARCH), armhf))
	GLES_ENABLE=-DUSING_GLES2=ON -DUSING_EGL=ON
	# See issue #7817
	export CC=clang
	export CXX=clang++
else ifneq (,$(filter $(ARCH), arm64))
	GLES_ENABLE=-DUSING_GLES2=ON -DUSING_EGL=ON
endif

%:
	dh $@ --buildsystem=cmake --builddirectory=obj --parallel

override_dh_auto_configure:
#	mkdir ext/native/tools/build
#	cd ext/native/tools/build && \
#		cmake ../ && \
#		$(MAKE)
#	./buildatlas.sh
#	./build_ppgeatlas.sh
#ifeq ($(ARCH),amd64)
#	cd ffmpeg/ && \
#	./linux_x86-64.sh
#else ifeq ($(ARCH),i386)
#	cd ffmpeg/ && \
#	./linux_x86.sh
#else ifeq ($(ARCH),armhf)
#	cd ffmpeg/ && \
#	./linux_arm.sh
#else ifeq ($(ARCH),arm64)
#	cd ffmpeg/ && \
#	./linux_arm64.sh
#endif
	dh_auto_configure -- $(GLES_ENABLE) -DUSING_QT_UI=ON -DUSE_SYSTEM_FFMPEG=ON
override_dh_auto_build:
	dh_auto_build
	mv obj/PPSSPPQt ./
	dh_auto_clean
	dh_auto_configure -- $(GLES_ENABLE) -DUSE_SYSTEM_FFMPEG=ON
	dh_auto_build
	chrpath -d obj/PPSSPPSDL
	mv PPSSPPQt obj/

override_dh_auto_install:

override_dh_auto_clean:
	dh_auto_clean
#	rm -r -f ext/native/tools/build/

override_dh_strip:
	dh_strip --no-automatic-dbgsym
