summaryrefslogtreecommitdiff
path: root/partitions/Makefile
blob: e51ddd75335e1e130f2acd0ea25530b744f45bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

.PHONY: all clean

whole = _build/whole.img
key = _build/key.img

all: $(whole)

stage0_efi_file = ../import-grub-bootx64-efi/3/BOOTX64.EFI
$(stage0_efi_file):
	make -C ../import-grub-bootx64-efi ver=3

$(whole): $(stage0_efi_file)
	partvi

$(key): $(stage0_efi_file)
	partvi key

_liveboot:
	btrfs subvolume create $@

PERSIST_SIZE=20G
PERSIST_FILE=_liveboot/persist.img
$(PERSIST_FILE): | _liveboot
	[ ! -e $@ ]
	fallocate -l "$(PERSIST_SIZE)" $@
	truncate -s 0 $@
	truncate -s "$(PERSIST_SIZE)" $@

optional_persist_disk != [ ! -e $(PERSIST_FILE) ] || printf %s '-drive file=$(PERSIST_FILE),media=disk,driver=raw'

.PHONY: usb emu key emu-key keymu
usb: $(whole)
	usb=$$(usb) && sudo dd status=progress if="$<" of="$$usb"


# QEMU_DISPLAY_OPTIONS = -nographic
QEMU_DISPLAY_OPTIONS = -display gtk

define QEMU_OPTIONS
-global isa-fdc.fdtypeA=none
$(QEMU_BIOS_OPTIONS)
$(QEMU_DISPLAY_OPTIONS)
endef

define emu
	NO_AT_BRIDGE=1 qemu-system-x86_64 \
	  ${QEMU_OPTIONS:%=%} \
	  -m 800 -enable-kvm -boot c \
	  -drive file=$(1),media=disk,driver=raw \
	  $(optional_persist_disk)
endef

emu: $(whole)
	$(call emu,$<)

emu-key keymu: $(key)
	$(call emu,$<)

key: $(key)
	usb=$$(usb) && \
		sudo dd status=progress bs=1048576 if="$<" of="$$usb" && \
		sudo $(call emu,"$$usb")

efi: QEMU_BIOS_OPTIONS = -bios /usr/share/ovmf/OVMF.fd
efi: emu

efi-ventoy: QEMU_BIOS_OPTIONS = -bios /usr/share/ovmf/OVMF.fd
efi-ventoy: ventoy-efi-example.img
	$(call emu,$<)

clean:
	rm -rf _build

.PHONY: total-destroy
total-destroy: clean
	rm -f $(PERSIST_FILE)
	$(MAKE) $(PERSIST_FILE)