#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

UPSTREAM_TAG = android-$(subst +,_,$(DEB_VERSION_UPSTREAM))
export DEB_BUILD_PROFILES = stage1

# ORDER IS IMPORTANT!
STAGE1_COMPONENTS = liblog \
                    libcutils \
                    libbase \
                    libbacktrace \
                    libutils \
                    libziparchive \
                    libsparse \
                    libadb \
                    adb
OTHER_COMPONENTS = fastboot
COMPONENTS = $(STAGE1_COMPONENTS)
ifeq ($(filter stage1,$(DEB_BUILD_PROFILES)),)
  COMPONENTS += $(OTHER_COMPONENTS)
endif

%:
	dh $@

override_dh_auto_build:
	$(foreach makefile, $(COMPONENTS), make -f debian/$(makefile).mk;)

override_dh_auto_clean:
	dh_auto_clean
	$(foreach makefile, $(COMPONENTS), make clean -f debian/$(makefile).mk;)

get-orig-source: $(UPSTREAM_TAG).tar.gz
	mk-origtargz --repack --compression xz $<

$(UPSTREAM_TAG).tar.gz:
	wget https://android.googlesource.com/platform/system/core/+archive/$(UPSTREAM_TAG).tar.gz