#!/usr/bin/make -f

KERNEL_SOURCES = $(CURDIR)/android_kernel_common

include $(CURDIR)/debian/android-kernel-info.mk
include /usr/share/linux-packaging-snippets/kernel-snippet.mk

%:
	dh $@

debian/control:
	# Use a trick to create a new src package name. This allows to keep old
	# patchlevel kernels in the archive.
	rm -f $(CURDIR)/debian/control
	for file in /usr/share/linux-packaging-snippets/control.in $(CURDIR)/debian/control-extra.in; do \
		sed -e "s|Source: linux-@VARIANT@|Source: linux-@VARIANT@-@KERNEL_BASE_VERSION@|g" \
			-e "s|@KERNEL_BASE_VERSION@|$(KERNEL_BASE_VERSION)|g" \
			-e "s|@VARIANT@|$(VARIANT)|g" \
			-e "s|@DEVICE_VENDOR@|$(DEVICE_VENDOR)|g" \
			-e "s|@DEVICE_MODEL@|$(DEVICE_MODEL)|g" \
			-e "s|@DEVICE_FULL_NAME@|$(DEVICE_FULL_NAME)|g" \
			-e "s|@DEB_TOOLCHAIN@|$(DEB_TOOLCHAIN)|g" \
			-e "s|@DEB_BUILD_ON@|$(DEB_BUILD_ON)|g" \
			-e "s|@DEB_BUILD_FOR@|$(DEB_BUILD_FOR)|g" \
			$${file} >> $(CURDIR)/debian/control ; \
	done

override_dh_auto_install: kernel_snippet_install out/KERNEL_OBJ/boot-gz.img out/KERNEL_OBJ/boot-lz4.img out/KERNEL_OBJ/boot-recovery-gz.img out/KERNEL_OBJ/boot-recovery-lz4.img
	# Create package contents for other variants
	cp -Rav $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE) $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-gzip
	cp -Rav $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE) $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-lz4
ifeq ($(FLASH_ENABLED), 1)
	cp -a $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE).postinst $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-gzip.postinst
	cp -a $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE).postinst $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-lz4.postinst
endif

	# Replace contents
	cp -v $(KERNEL_OUT)/boot-gz.img $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-gzip/boot/boot.img-$(KERNEL_RELEASE)
	cp -v $(KERNEL_OUT)/boot-lz4.img $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-lz4/boot/boot.img-$(KERNEL_RELEASE)
	cp -v $(KERNEL_OUT)/boot-recovery-gz.img $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-gzip/boot/recovery.img-$(KERNEL_RELEASE)
	cp -v $(KERNEL_OUT)/boot-recovery-lz4.img $(CURDIR)/debian/linux-bootimage-$(KERNEL_RELEASE)-lz4/boot/recovery.img-$(KERNEL_RELEASE)
