#!/usr/bin/make
.DEFAULT_GOAL := list 

list: #Shows this list
	@echo The following options are available
	@grep '^[^#[:space:]].*:' Makefile | grep -v := | sed -e "s/:[^|]*#/: /g"

prep_buildenv: #Preperation for build (setting file permissons, etc)
	chmod 600 config/includes.chroot/etc/NetworkManager/system-connections/*.nmconnection

install_buildenv: # Install packages required to build the image
	sudo apt -y install live-build make build-essential wget git unzip colordiff apt-transport-https rename ovmf rsync python3-venv gnupg apt-utils cpio

download_extra: #For downloading extra's for iso (not needed/tested)
	make -f Makefile.extra

#Add 'download_extra' to build without third party software/dotfiles (not needed/tested)
build: prep_buildenv install_buildenv build_amd64 build_i386 clean_env #Runs build for all architectures

build_amd64: #Build iso for amd64
	rm -f Custom-image-amd64.iso
	sudo TargetArch=amd64 lb clean --all
	sudo TargetArch=amd64 lb config
	sudo TargetArch=amd64 lb build
	mv live-image-amd64.hybrid.iso Custom-image-amd64.iso

build_i386: # Build iso for i386
	rm -f Custom-image-i386.iso
	sudo TargetArch=i386 lb clean --all
	sudo TargetArch=i386 lb config
	sudo TargetArch=i386 lb build
	mv live-image-i386.hybrid.iso Custom-image-i386.iso

clean: clean_env clean_iso #Clear all caches, archives, and isos

clean_env: #Clear all caches and archives
	sudo TargetArch=amd64 lb clean --all
	sudo TargetArch=i386 lb clean --all
	make -f Makefile.extra clean

clean_iso: #Removes genereated iso's
	rm -f Custom-image-amd64.iso Custom-image-i386.iso
