]> git.lizzy.rs Git - loadnothing.git/blob - Makefile
Fix makefile to build and convert stage 2 properly
[loadnothing.git] / Makefile
1 default_target: vm
2 .PHONY: vm clean
3
4 stage1/boot.bin: stage1/boot.asm
5         nasm -DSTAGE2SIZE=$$(du -b stage2/target/x86-loadnothing/release/stage2 | cut -f1) -f bin -o stage1/boot.bin stage1/boot.asm
6
7 magic.bin:
8         echo -en "\x55\xAA" > magic.bin
9
10 stage2/target/x86-loadnothing/release/stage2: stage2/src/main.rs
11         cd stage2 && cargo rustc --release -- --emit=obj
12         ld -m elf_i386 -o stage2/target/x86-loadnothing/release/stage2.bin --oformat binary stage2/target/x86-loadnothing/release/stage2 -Ttext=0x7e00
13         mv stage2/target/x86-loadnothing/release/stage2.bin stage2/target/x86-loadnothing/release/stage2
14
15 nothing.img: magic.bin stage2/target/x86-loadnothing/release/stage2 stage1/boot.bin
16         dd if=/dev/zero of=nothing.img bs=32M count=1
17         parted -s nothing.img mklabel msdos
18         parted -s -a optimal nothing.img mkpart primary fat32 16MiB 100%
19         doas losetup /dev/loop1 nothing.img
20         doas mkfs.fat /dev/loop1p1
21         doas losetup -d /dev/loop1
22         dd if=stage1/boot.bin of=nothing.img bs=1 count=446 conv=notrunc
23         dd if=magic.bin of=nothing.img bs=1 seek=510 count=2 conv=notrunc
24         dd if=stage2/target/x86-loadnothing/release/stage2 of=nothing.img bs=512 seek=1 conv=notrunc
25
26 vm: nothing.img
27         qemu-system-x86_64 -hda nothing.img
28
29 clean:
30         rm -f magic.bin stage1/boot.bin nothing.img
31         cd stage2 && cargo clean