#!/usr/bin/make -f

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

%:
	dh $@

# Makefile does not follow any conventions
override_dh_auto_install:
	true

override_dh_fixperms:
	dh_fixperms
	chmod -x $$(find debian/rpiboot -name "*.bin" -o -name "*.elf")

override_dh_dwz:
	dh_dwz -Xstart.elf -Xstart4.elf

override_dh_strip:
	dh_strip -Xstart.elf -Xstart4.elf

override_dh_install:
	# Copy the pinned firmware version
	rm -rf temp
	mkdir -p temp/firmware/2711
	mkdir -p temp/firmware/2712

	cp /lib/firmware/raspberrypi/bootloader-2711/latest/pieeprom-2024-07-30.bin temp/firmware/2711/pieeprom.bin
	cp /lib/firmware/raspberrypi/bootloader-2711/latest/recovery.bin temp/firmware/2711/recovery.bin
	cp /lib/firmware/raspberrypi/bootloader-2712/latest/pieeprom-2024-09-23.bin temp/firmware/2712/pieeprom.bin
	cp /lib/firmware/raspberrypi/bootloader-2712/latest/recovery.bin temp/firmware/2712/recovery.bin
	dh_install
	find $(CURDIR)/debian -name .gitignore -delete
	rm -rf temp

get-orig-source:
	DEB_SOURCE="$(DEB_SOURCE)" DEB_VERSION_UPSTREAM="$(DEB_VERSION_UPSTREAM)" \
		   debian/get-orig-source
