#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/architecture.mk

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@

override_dh_auto_build:
	# These are small shims loaded directly into raw target ram without an OS.
	echo 'blhc: ignore-line-regexp: arm-none-eabi-gcc .* -o (fel-sdboot|jtag-loop|uart0-helloworld-sdboot)\.elf .*'

	$(MAKE) -C thunks CROSS_COMPILE=arm-none-eabi-
	dh_auto_build -- CFLAGS="$(CFLAGS) $(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" tools misc

	mkimage -A arm -T script -d bin/ramboot.uboot-sh ramboot.scr
	$(MAKE) CROSS_COMPILE=arm-none-eabi- binfiles

override_dh_auto_install: PKG := debian/sunxi-tools
override_dh_auto_install:
	$(MAKE) install-tools install-misc install-appstream-metainfo DESTDIR=$(CURDIR)/$(PKG) PREFIX=/usr

	install -m0644 ramboot.scr $(PKG)/usr/share/sunxi-tools/ramboot.scr
	install -m0644 fel-sdboot.sunxi $(PKG)/usr/share/sunxi-tools/fel-sdboot.sunxi
	install -m0644 jtag-loop.sunxi $(PKG)/usr/share/sunxi-tools/jtag-loop.sunxi
	install -m0644 uart0-helloworld-sdboot.sunxi $(PKG)/usr/share/sunxi-tools/uart0-helloworld-sdboot.sunxi
