#!/usr/bin/make

BUILD_LOG := build.log

BUILD_OPTIONS = \
	--apt-indices none \
	--apt-secure false \
	--apt-source-archives false \
	--cache-stages false \
	--compression none \
	--mode debian \
	--security false \
	--binary-filesystem fat32 \
	--binary-images hdd \
	--chroot-filesystem squashfs \
	--hdd-size 512 \
	--initramfs live-boot \
	--system live \
	--firmware-binary false \
	--firmware-chroot false \
	--linux-flavours "rpi2-rpfv" \
	--updates false \
	--archive-areas 'main firmware non-free' \
	--distribution jessie \
	--chroot-filesystem squashfs \
	--architectures armhf \
	--bootstrap-qemu-arch armhf \
	--bootstrap-qemu-static /usr/bin/qemu-arm-static \
	--parent-mirror-bootstrap http://archive.raspbian.org/raspbian \
	--parent-mirror-chroot http://archive.raspbian.org/raspbian \
	--parent-mirror-chroot-security http://archive.raspbian.org/raspbian \
	--parent-mirror-binary http://archive.raspbian.org/raspbian \
	--parent-mirror-binary-security http://archive.raspbian.org/raspbian \
	--mirror-bootstrap http://archive.raspbian.org/raspbian \
	--mirror-chroot http://archive.raspbian.org/raspbian \
	--mirror-chroot-security http://archive.raspbian.org/raspbian \
	--mirror-binary http://archive.raspbian.org/raspbian \
	--mirror-binary-security http://archive.raspbian.org/raspbian \
	--mirror-debian-installer http://archive.raspbian.org/raspbian

.PHONY: clean check

default: check

check: live-image-armhf.img

live-image-armhf.img:
	env DEBOOTSTRAP_OPTIONS="--keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg" \
		lb config $(BUILD_OPTIONS)
	( sudo DEBOOTSTRAP_OPTIONS="--keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg" lb bootstrap ) 2>&1 | tee $(BUILD_LOG)

clean:
	sudo lb clean
	sudo lb clean --purge
	rm -fr config
	rm -fr $(BUILD_LOG)
