diff options
author | dzwdz | 2023-08-15 20:41:38 +0200 |
---|---|---|
committer | dzwdz | 2023-08-15 20:41:38 +0200 |
commit | 034a60c19f15f74186bfb902172bf0f1cd356321 (patch) | |
tree | 6eee5fd1b7dd18697f40e9de26dec172ba2b6223 | |
parent | 070b19e2948b3a03669b0f1888f1661b0d196275 (diff) |
build: replace make {boot,test} with a dedicated script
-rw-r--r-- | Makefile | 38 | ||||
-rwxr-xr-x | boot | 73 |
2 files changed, 75 insertions, 36 deletions
@@ -15,22 +15,6 @@ USER_CFLAGS = $(CFLAGS) SPARSEFLAGS = -$(KERNEL_CFLAGS) -Wno-non-pointer-null -QFLAGS = -no-reboot -m 1g -gdb tcp::12366 -ifdef NET_DIRECT -QFLAGS += -nic socket,model=rtl8139,connect=:1234,mac=52:54:00:ca:77:1a,id=n1 -else -QFLAGS += -nic user,model=rtl8139,mac=52:54:00:ca:77:1a,net=192.168.0.0/24,hostfwd=tcp::12380-192.168.0.11:80,id=n1 -endif -ifdef NET_PCAP -QFLAGS += -object filter-dump,id=f1,netdev=n1,file=$(NET_PCAP) -endif -ifndef NO_KVM -QFLAGS += -enable-kvm -endif -ifndef QEMU_DISPLAY -QFLAGS += -display none -endif - PORTS = define from_sources @@ -38,28 +22,10 @@ define from_sources endef -.PHONY: all portdeps boot check clean ports -all: portdeps out/boot.iso check +.PHONY: all portdeps check clean ports +all: portdeps out/boot.iso check out/fs.e2 portdeps: out/libc.a out/libm.a src/libc/include/__errno.h -boot: all out/fs.e2 - qemu-system-x86_64 \ - -drive file=out/boot.iso,format=raw,media=disk \ - -drive file=out/fs.e2,format=raw,media=disk \ - $(QFLAGS) -serial stdio - -test: all - @# pipes for the serial - @mkfifo out/qemu.in out/qemu.out 2> /dev/null || true - qemu-system-x86_64 -drive file=out/boot.iso,format=raw,media=disk $(QFLAGS) -serial pipe:out/qemu & - @# for some reason the first sent character doesn't go through to the shell - @# the empty echo takes care of that, so the next echos will work just fine - @echo > out/qemu.in - echo tests > out/qemu.in - echo halt > out/qemu.in - @echo - @cat out/qemu.out - check: $(shell find src/kernel/ -type f -name *.c) @echo $^ | xargs -n 1 sparse $(SPARSEFLAGS) @@ -0,0 +1,73 @@ +#!/bin/sh +set -eu + +disk() { + echo "-drive file=$1,format=raw,media=disk" +} + +if [ -n "${QFLAGS:-}" ]; then + echo "QFLAGS in env" +fi +QFLAGS="-no-reboot -m 1g -gdb tcp::12366 $(disk out/boot.iso) $(disk out/fs.e2) ${QFLAGS:-}" +QEMU=qemu-system-x86_64 + +QDISPLAY="-display none" +QNET="-nic user,model=rtl8139,mac=52:54:00:ca:77:1a,net=192.168.0.0/24,hostfwd=tcp::12380-192.168.0.11:80,id=n1" +QKVM="-enable-kvm" +QTTY="-serial stdio" + +DRY_RUN= +TEST_RUN= + +for opt; do + case "$opt" in + --display|-d) + QDISPLAY= + ;; + --dry-run|-n) + DRY_RUN=1 + ;; + --help|-h) + echo $0 [opts] + sed -ne '/\t-.*)/ {s/)//; s/|/, /g; p}' $0 + exit + ;; + --pcap=*) + PCAP="${opt#*=}" + echo outputting pcap to $PCAP + QNET="$QNET -object filter-dump,id=f1,netdev=n1,file=$PCAP" + ;; + --no-kvm) + QKVM= + ;; + --test|-t) + rm -vf out/qemu.in out/qemu.out + mkfifo out/qemu.in out/qemu.out + TEST_RUN=1 + QTTY="-serial pipe:out/qemu" + POST="cat out/qemu.out" + ;; + *) + echo "unknown option $opt" + exit 1 + ;; + esac +done + +CMD="$QEMU $QDISPLAY $QNET $QKVM $QTTY $QFLAGS" +if [ -n "$DRY_RUN" ]; then + echo "$CMD" +elif [ -n "$TEST_RUN" ]; then + echo "$CMD &" + $CMD & + + # something eats the first character sent, so let's send a sacrificial newline + echo > out/qemu.in + # carry on with the tests + echo tests > out/qemu.in + echo halt > out/qemu.in + cat out/qemu.out +else + echo "$CMD" + $CMD +fi |