#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export CC = clang
export CXX = clang++
export DEB_HOST_MULTIARCH
export DEB_CFLAGS_MAINT_APPEND = -fPIC
export DEB_CXXFLAGS_MAINT_APPEND = -fPIC
export DEB_CPPFLAGS_MAINT_APPEND = \
  -DNDEBUG \
  -I/usr/include/android \
  -UDEBUG
export DEB_LDFLAGS_MAINT_APPEND = -fPIC

COMPONENTS_ANY = debian/out/dmtracedump
COMPONENTS_AOSP = debian/out/dexdump debian/out/dexlist

ifeq ($(filter amd64 i386 armel armhf arm64 mips mipsel mips64el,$(DEB_HOST_ARCH)),)
  COMPONENTS += $(COMPONENTS_ANY)
else
  COMPONENTS += $(COMPONENTS_ANY) $(COMPONENTS_AOSP)
endif

debian/out/%: debian/%.mk
	dh_auto_build --buildsystem=makefile -- --file=$<

debian/out/lib%.so: debian/lib%.mk
	dh_auto_build --buildsystem=makefile -- --file=$<

debian/out/dexdump: debian/dexdump.mk debian/out/libart.so
	dh_auto_build --buildsystem=makefile -- --file=$<

debian/out/libart.so: debian/libart.mk debian/out/libsigchain.so
	dh_auto_build --buildsystem=makefile -- --file=$<

%:
	dh $@

override_dh_auto_build: $(COMPONENTS)

override_dh_auto_clean:
	dh_auto_clean
	make clean --file=debian/libart.mk