2021-11-03 21:37:47 +01:00
|
|
|
# **************************************************************************** #
|
|
|
|
|
# #
|
|
|
|
|
# ::: :::::::: #
|
|
|
|
|
# Makefile :+: :+: :+: #
|
|
|
|
|
# +:+ +:+ +:+ #
|
|
|
|
|
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
|
|
|
|
# +#+#+#+#+#+ +#+ #
|
|
|
|
|
# Created: 2021/11/02 17:47:57 by gbaconni #+# #+# #
|
2022-01-25 12:45:40 +01:00
|
|
|
# Updated: 2022/01/25 12:45:23 by gbaconni ### lausanne.ch #
|
2021-11-03 21:37:47 +01:00
|
|
|
# #
|
|
|
|
|
# **************************************************************************** #
|
|
|
|
|
|
|
|
|
|
DVER = 11.1.0
|
|
|
|
|
|
|
|
|
|
RAM = 2048
|
|
|
|
|
SSD = 31539
|
2021-11-01 16:51:34 +01:00
|
|
|
|
2021-11-07 15:12:22 +01:00
|
|
|
CORES = 2
|
2021-11-07 19:23:37 +01:00
|
|
|
THREADS = 1
|
2021-11-07 15:12:22 +01:00
|
|
|
SOCKETS = 2
|
|
|
|
|
|
2021-11-05 08:44:22 +01:00
|
|
|
KERNEL = $(shell uname -s)
|
2021-11-08 19:04:14 +01:00
|
|
|
MACHINE = $(shell uname -m)
|
2021-11-05 11:20:40 +01:00
|
|
|
FT = $(shell if test -L ~/goinfre; then echo "yes"; else echo "no"; fi)
|
2021-11-05 08:44:22 +01:00
|
|
|
|
2021-11-08 19:04:14 +01:00
|
|
|
QEMU86 = qemu-system-x86_64
|
|
|
|
|
ifeq ($(KERNEL),Linux)
|
|
|
|
|
ifeq ($(MACHINE),x86_64)
|
2022-01-25 12:45:40 +01:00
|
|
|
QEMU86 = /usr/bin/qemu-system-x86_64
|
2021-11-08 19:04:14 +01:00
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2021-11-01 16:51:34 +01:00
|
|
|
all: sync
|
|
|
|
|
|
2021-11-03 21:37:47 +01:00
|
|
|
virtualbox:
|
2021-11-05 17:10:53 +01:00
|
|
|
@test -d ~/goinfre/VirtualBox\ VMs || mkdir -p ~/goinfre/VirtualBox\ VMs
|
|
|
|
|
@test -L ~/VirtualBox\ VMs || ln -snf ~/goinfre/VirtualBox\ VMs ~/VirtualBox\ VMs
|
2022-01-25 12:21:17 +01:00
|
|
|
@echo /Applications/VirtualBox.app/Contents/MacOS/VBoxManage createmedium disk --filename ~/goinfre/VirtualBox\\ VMs/$$(basename ~)42/$$(basename ~)42.vdi --size $(SSD) --format VDI
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-08 17:58:25 +01:00
|
|
|
signature:
|
|
|
|
|
ifeq ($(KERNEL),Darwin)
|
|
|
|
|
@shasum ~/goinfre/VirtualBox\ VMs/$$(basename ~)42/$$(basename ~)42.vdi | cut -d' ' -f1
|
|
|
|
|
endif
|
|
|
|
|
ifeq ($(KERNEL),Linux)
|
|
|
|
|
@sha1sum ~/goinfre/VirtualBox\ VMs/$$(basename ~)42/$$(basename ~)42.vdi | cut -d' ' -f1
|
|
|
|
|
endif
|
|
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
data:
|
|
|
|
|
ifeq ($(FT),yes)
|
|
|
|
|
@test -d ~/goinfre/born2beroot || install -d ~/goinfre/born2beroot
|
|
|
|
|
@test -L data || ln -snf ~/goinfre/born2beroot data
|
|
|
|
|
else
|
|
|
|
|
@test -d data || install -d data
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
uefi: data
|
2021-11-05 08:44:22 +01:00
|
|
|
ifeq ($(KERNEL),Linux)
|
2021-11-05 10:36:43 +01:00
|
|
|
@test -f data/efi-virtio.rom || cp /usr/lib/ipxe/qemu/efi-virtio.rom data/efi-virtio.rom
|
|
|
|
|
@test -f data/edk2-aarch64-code.fd || cp /usr/share/AAVMF/AAVMF_CODE.fd data/edk2-aarch64-code.fd
|
|
|
|
|
@test -f data/edk2-arm-vars.fd || cp /usr/share/AAVMF/AAVMF_VARS.fd data/edk2-arm-vars.fd
|
|
|
|
|
@test -f data/edk2-x86_64-code.fd || cp /usr/share/OVMF/OVMF_CODE_4M.fd data/edk2-x86_64-code.fd
|
|
|
|
|
@test -f data/edk2-i386-vars.fd || cp /usr/share/OVMF/OVMF_VARS_4M.fd data/edk2-i386-vars.fd
|
2021-11-05 08:44:22 +01:00
|
|
|
endif
|
|
|
|
|
ifeq ($(KERNEL),Darwin)
|
2021-11-05 10:36:43 +01:00
|
|
|
ifeq ($(FT),yes)
|
|
|
|
|
@test -f data/efi-virtio.rom || cp ~/.brew/Cellar/qemu/*/share/qemu/efi-virtio.rom data/efi-virtio.rom
|
|
|
|
|
@test -f data/edk2-aarch64-code.fd || cp ~/.brew/Cellar/qemu/*/share/qemu/edk2-aarch64-code.fd data/edk2-aarch64-code.fd
|
|
|
|
|
@test -f data/edk2-arm-vars.fd || cp ~/.brew/Cellar/qemu/*/share/qemu/edk2-arm-vars.fd data/edk2-arm-vars.fd
|
|
|
|
|
@test -f data/edk2-x86_64-code.fd || cp ~/.brew/Cellar/qemu/*/share/qemu/edk2-x86_64-code.fd data/edk2-x86_64-code.fd
|
|
|
|
|
@test -f data/edk2-i386-vars.fd || cp ~/.brew/Cellar/qemu/*/share/qemu/edk2-i386-vars.fd data/edk2-i386-vars.fd
|
|
|
|
|
else
|
|
|
|
|
@test -f data/efi-virtio.rom || cp /opt/homebrew/Cellar/qemu/*/share/qemu/efi-virtio.rom data/efi-virtio.rom
|
|
|
|
|
@test -f data/edk2-aarch64-code.fd || cp /opt/homebrew/Cellar/qemu/*/share/qemu/edk2-aarch64-code.fd data/edk2-aarch64-code.fd
|
|
|
|
|
@test -f data/edk2-arm-vars.fd || cp /opt/homebrew/Cellar/qemu/*/share/qemu/edk2-arm-vars.fd data/edk2-arm-vars.fd
|
|
|
|
|
@test -f data/edk2-x86_64-code.fd || cp /opt/homebrew/Cellar/qemu/*/share/qemu/edk2-x86_64-code.fd data/edk2-x86_64-code.fd
|
|
|
|
|
@test -f data/edk2-i386-vars.fd || cp /opt/homebrew/Cellar/qemu/*/share/qemu/edk2-i386-vars.fd data/edk2-i386-vars.fd
|
|
|
|
|
endif
|
2021-11-05 08:44:22 +01:00
|
|
|
endif
|
|
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
qemu:
|
2021-11-05 08:44:22 +01:00
|
|
|
ifeq ($(KERNEL),Linux)
|
2021-11-08 18:38:05 +01:00
|
|
|
@which qemu-system-x86_64 >/dev/null 2>&1 || sudo apt-get install -qq -y qemu-utils qemu-system-x86 qemu-system-arm qemu-efi-aarch64 ovmf ipxe-qemu expect
|
2022-01-25 12:45:40 +01:00
|
|
|
ifeq ($(MACHINE),x86_64)
|
|
|
|
|
sudo setcap -q 'cap_net_bind_service=+ep' /usr/bin/qemu-system-x86_64
|
|
|
|
|
endif
|
2021-11-05 08:44:22 +01:00
|
|
|
endif
|
|
|
|
|
ifeq ($(KERNEL),Darwin)
|
2021-11-05 10:36:43 +01:00
|
|
|
ifeq ($(FT),yes)
|
|
|
|
|
@which brew >/dev/null 2>&1 || curl -fsSL https://rawgit.com/kube/42homebrew/master/install.sh | zsh
|
|
|
|
|
@test -L ~/.brew/bin/qemu-system-x86_64 || (eval "$$(/opt/homebrew/bin/brew shellenv)" && brew install qemu)
|
|
|
|
|
else
|
2021-11-03 21:37:47 +01:00
|
|
|
@which brew >/dev/null 2>&1 || bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
2021-11-05 08:44:22 +01:00
|
|
|
@test -L /opt/homebrew/bin/qemu-system-x86_64 || (eval "$$(/opt/homebrew/bin/brew shellenv)" && brew install qemu)
|
|
|
|
|
endif
|
2021-11-05 10:36:43 +01:00
|
|
|
endif
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
curl:
|
|
|
|
|
ifeq ($(KERNEL),Linux)
|
|
|
|
|
@which curl >/dev/null 2>&1 || sudo apt-get install -qq -y curl
|
|
|
|
|
endif
|
2021-11-04 09:36:13 +01:00
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
debian: data curl
|
|
|
|
|
@test -f data/debian-$(DVER)-amd64-netinst.iso || curl -sLo data/debian-$(DVER)-amd64-netinst.iso https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-$(DVER)-amd64-netinst.iso
|
|
|
|
|
@test -f data/debian-$(DVER)-arm64-netinst.iso || curl -sLo data/debian-$(DVER)-arm64-netinst.iso https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/debian-$(DVER)-arm64-netinst.iso
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-06 14:15:06 +01:00
|
|
|
auto: data debian
|
2021-11-05 11:12:44 +01:00
|
|
|
@grep -q 42url data/debian-$(DVER)-amd64-netinst.iso || LC_ALL=C sed -i'.orig' -e 's|auto=true priority=critical vga=788|auto url=https://42url.com/6eMNuv2Y|g' data/debian-$(DVER)-amd64-netinst.iso
|
|
|
|
|
@grep -q 42url data/debian-$(DVER)-arm64-netinst.iso || LC_ALL=C sed -i'.orig' -e 's|auto=true priority=critical --- quiet|auto url=https://42url.com/6eMNuv2Y |g' data/debian-$(DVER)-arm64-netinst.iso
|
2021-11-05 10:36:43 +01:00
|
|
|
@rm -f data/debian-$(DVER)-amd64-netinst.iso.orig data/debian-$(DVER)-arm64-netinst.iso.orig
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
sda: data
|
2021-11-05 11:12:44 +01:00
|
|
|
@test -f data/sda.raw || qemu-img create -q -f raw -o size=$(SSD)M data/sda.raw
|
2021-11-05 10:36:43 +01:00
|
|
|
|
|
|
|
|
amd64: qemu uefi sda debian
|
2021-11-08 19:04:14 +01:00
|
|
|
@$(QEMU86) \
|
2021-11-03 21:37:47 +01:00
|
|
|
-name debian \
|
|
|
|
|
-cpu qemu64-v1 \
|
2021-11-07 15:12:22 +01:00
|
|
|
-smp cores=$(CORES),threads=$(THREADS),sockets=$(SOCKETS) \
|
2021-11-03 21:37:47 +01:00
|
|
|
-machine q35,vmport=off \
|
|
|
|
|
-accel tcg,tb-size=512 \
|
|
|
|
|
-global ICH9-LPC.disable_s3=1 \
|
|
|
|
|
-m $(RAM) \
|
|
|
|
|
-usb \
|
|
|
|
|
-device qemu-xhci \
|
|
|
|
|
-device usb-kbd \
|
|
|
|
|
-device usb-mouse \
|
|
|
|
|
-device usb-tablet \
|
|
|
|
|
-device virtio-gpu \
|
|
|
|
|
-device virtio-scsi-pci,num_queues=4,id=scsi0 \
|
|
|
|
|
-device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0,bootindex=0 \
|
|
|
|
|
-device scsi-cd,drive=cdrom0,bus=scsi0.0,channel=0,scsi-id=1,lun=0,bootindex=1 \
|
2021-11-05 10:36:43 +01:00
|
|
|
-drive id=pflash0,unit=0,file=${PWD}/data/edk2-x86_64-code.fd,if=pflash,format=raw,readonly=on \
|
|
|
|
|
-drive id=pflash1,unit=1,file=${PWD}/data/edk2-i386-vars.fd,if=pflash,format=raw \
|
|
|
|
|
-drive id=drive0,index=0,file=${PWD}/data/sda.raw,if=none,media=disk,format=raw,cache=writethrough,discard=unmap \
|
|
|
|
|
-drive id=cdrom0,index=1,file=${PWD}/data/debian-$(DVER)-amd64-netinst.iso,if=none,media=cdrom,readonly=on \
|
2021-11-09 12:27:49 +01:00
|
|
|
-nic user,model=virtio,hostfwd=tcp::4242-:4242,hostfwd=tcp::443-:443,hostfwd=tcp::80-:80 \
|
2021-11-03 21:37:47 +01:00
|
|
|
-monitor stdio \
|
|
|
|
|
-rtc base=localtime,clock=host
|
2021-11-03 23:37:39 +01:00
|
|
|
|
2021-11-05 08:44:22 +01:00
|
|
|
debug: qemu
|
2021-11-08 19:04:14 +01:00
|
|
|
@$(QEMU86) \
|
2021-11-03 23:37:39 +01:00
|
|
|
-name debian \
|
|
|
|
|
-cpu qemu64-v1 \
|
2021-11-07 15:12:22 +01:00
|
|
|
-smp cores=$(CORES),threads=$(THREADS),sockets=$(SOCKETS) \
|
2021-11-03 23:37:39 +01:00
|
|
|
-machine q35,vmport=off \
|
|
|
|
|
-accel tcg,tb-size=512 \
|
|
|
|
|
-global ICH9-LPC.disable_s3=1 \
|
|
|
|
|
-m $(RAM) \
|
|
|
|
|
-usb \
|
|
|
|
|
-device qemu-xhci \
|
|
|
|
|
-device usb-kbd \
|
|
|
|
|
-device usb-mouse \
|
|
|
|
|
-device usb-tablet \
|
|
|
|
|
-device virtio-gpu \
|
|
|
|
|
-device virtio-scsi-pci,num_queues=4,id=scsi0 \
|
|
|
|
|
-device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0,bootindex=0 \
|
2021-11-05 10:36:43 +01:00
|
|
|
-drive id=drive0,index=0,file=${PWD}/data/sda.raw,if=none,media=disk,format=raw,cache=writethrough,discard=unmap \
|
2021-11-09 12:27:49 +01:00
|
|
|
-nic user,model=virtio,hostfwd=tcp::4242-:4242,hostfwd=tcp::443-:443,hostfwd=tcp::80-:80 \
|
2021-11-03 23:37:39 +01:00
|
|
|
-monitor stdio \
|
|
|
|
|
-rtc base=localtime,clock=host
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-04 09:36:13 +01:00
|
|
|
test: auto amd64 debug
|
|
|
|
|
|
2021-11-05 10:36:43 +01:00
|
|
|
arm64: qemu uefi sda debian
|
2021-11-03 21:37:47 +01:00
|
|
|
@qemu-system-aarch64 \
|
|
|
|
|
-name debian \
|
|
|
|
|
-accel hvf \
|
|
|
|
|
-cpu host \
|
2021-11-07 15:12:22 +01:00
|
|
|
-smp cores=$(CORES),threads=$(THREADS),sockets=$(SOCKETS) \
|
2021-11-03 21:37:47 +01:00
|
|
|
-machine virt,highmem=off \
|
|
|
|
|
-accel hvf \
|
|
|
|
|
-accel tcg,tb-size=128 \
|
|
|
|
|
-m $(RAM) \
|
|
|
|
|
-usb \
|
|
|
|
|
-device qemu-xhci \
|
|
|
|
|
-device usb-kbd \
|
|
|
|
|
-device usb-mouse \
|
|
|
|
|
-device usb-tablet \
|
|
|
|
|
-device virtio-gpu \
|
|
|
|
|
-device virtio-scsi-pci,num_queues=4,id=scsi0 \
|
|
|
|
|
-device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0,bootindex=0 \
|
|
|
|
|
-device scsi-cd,drive=cdrom0,bus=scsi0.0,channel=0,scsi-id=1,lun=0,bootindex=1 \
|
2021-11-05 10:36:43 +01:00
|
|
|
-drive id=pflash0,unit=0,file=${PWD}/data/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on \
|
|
|
|
|
-drive id=pflash1,unit=1,file=${PWD}/data/edk2-arm-vars.fd,if=pflash,format=raw \
|
|
|
|
|
-drive id=drive0,index=0,file=${PWD}/data/sda.raw,if=none,media=disk,format=raw,cache=writethrough,discard=unmap \
|
|
|
|
|
-drive id=cdrom0,index=1,file=${PWD}/data/debian-$(DVER)-arm64-netinst.iso,if=none,media=cdrom,readonly=on \
|
2021-11-09 12:27:49 +01:00
|
|
|
-nic user,model=virtio,hostfwd=tcp::4242-:4242,hostfwd=tcp::443-:443,hostfwd=tcp::80-:80 \
|
2021-11-03 21:37:47 +01:00
|
|
|
-monitor stdio \
|
|
|
|
|
-rtc base=localtime,clock=host
|
|
|
|
|
|
|
|
|
|
clean:
|
2021-11-05 10:36:43 +01:00
|
|
|
@rm -f data/sda.raw
|
2021-11-03 21:37:47 +01:00
|
|
|
|
|
|
|
|
fclean: clean
|
2021-11-05 10:36:43 +01:00
|
|
|
@rm -f data/debian-$(DVER)-amd64-netinst.iso
|
|
|
|
|
@rm -f data/debian-$(DVER)-arm64-netinst.iso
|
|
|
|
|
@rm -f data/efi-virtio.rom
|
|
|
|
|
@rm -f data/edk2-aarch64-code.fd
|
|
|
|
|
@rm -f data/edk2-arm-vars.fd
|
|
|
|
|
@rm -f data/edk2-x86_64-code.fd
|
|
|
|
|
@rm -f data/edk2-i386-vars.fd
|
|
|
|
|
ifeq ($(FT),yes)
|
|
|
|
|
@rm -f data
|
|
|
|
|
@rm -fr ~/goinfre/born2beroot
|
|
|
|
|
else
|
|
|
|
|
@rm -fr data
|
|
|
|
|
endif
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-04 09:36:13 +01:00
|
|
|
re: clean test
|
|
|
|
|
|
2021-11-03 21:37:47 +01:00
|
|
|
ps:
|
2021-11-08 19:04:14 +01:00
|
|
|
@ps ax | grep -e qemu -e kvm | sed 's/ -/ \\\n-/g; s/^[^\/]*//;'
|
2021-11-03 21:37:47 +01:00
|
|
|
|
2021-11-03 23:37:39 +01:00
|
|
|
sync: up update
|
2021-11-01 16:51:34 +01:00
|
|
|
@git status | grep -q 'nothing to commit' || (git add -A && git commit -am "$$(date '+%F %T')" && git push) || true
|
|
|
|
|
|
2021-11-03 23:37:39 +01:00
|
|
|
up:
|
2021-11-01 16:51:34 +01:00
|
|
|
@dig +short vogsphere.baco.net A | grep -q '213\.5\.156\.25' || echo 'vogsphere.baco.net unreachable'
|
|
|
|
|
|
|
|
|
|
update:
|
|
|
|
|
@git pull
|
|
|
|
|
|
2021-11-07 15:51:39 +01:00
|
|
|
ssh:
|
2021-11-08 06:30:46 +01:00
|
|
|
@ssh-keygen -R "[127.0.0.1]:4242" >/dev/null 2>&1
|
2021-11-07 15:51:39 +01:00
|
|
|
@ssh -p 4242 -l gbaconni -i ~/.ssh/42lausanne-id_rsa -o StrictHostKeyChecking=no 127.0.0.1
|
|
|
|
|
|
2021-11-09 09:40:53 +01:00
|
|
|
sudo:
|
|
|
|
|
@ssh-keygen -R "[127.0.0.1]:4242" >/dev/null 2>&1
|
|
|
|
|
@ssh -p 4242 -l gbaconni -i ~/.ssh/42lausanne-id_rsa -o StrictHostKeyChecking=no 127.0.0.1 -t sudo -i
|
|
|
|
|
|