aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 8bc5de57b6c2c1a0ff02e1413a4acb4fb944f31e (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
# =====================================================================
#  spdx-license-identifier: ISC
#  glitch top-level makefile
# =====================================================================

MAKE      := make
MAKEID    := $(shell ${MAKE} --version | head -n1)
MAKEFLAGS += -rR --no-print-directory

ARCH := $(shell sed -nE "s/CONFIG_ARCH_(.+)=y/\1/p" .config)

SUBDIRS := lib ${ARCH} devices src

.PHONY: help info run doc clean test valgrind
help:
	@echo "run:      run kernel image in qemu"
	@echo "test:     run all tests"
	@echo "valgrind: run all tests in valgrind"

run: glitch.iso
	qemu-system-i386 -accel kvm -machine pc -cdrom $^ -d cpu_reset -display gtk,zoom-to-fit=on

clean:
	@for d in ${SUBDIRS}; do make -C $$d -f ../root.mk clean; done

test:
	@for d in ${SUBDIRS}; do make -C $$d -f ../root.mk test.quiet; done

valgrind:
	@for d in ${SUBDIRS}; do make -C $$d -f ../root.mk valgrind.quiet; done

# configure targets
kconfig:
	@make -C tools/kconfig -f ../../root.mk

.config: Kconfig
	@alldefconfig

config.mk: .config ${ARCH}/toolchain.mk
	@cat .config >> $@
	@echo -e '\n## toolchain.mk' >> $@
	@cat ${ARCH}/toolchain.mk >> $@

# build targets
lib/libk.a:
	@${MAKE} -C lib -f ../root.mk libk.a
i686/arch.a:
	@${MAKE} -C ${ARCH} -f ../root.mk arch.a
devices/devs.a:
	@${MAKE} -C devices -f ../root.mk devs.a
src/kernel.a:
	@${MAKE} -C src -f ../root.mk kernel.a

src/glitch.elf: lib/libk.a i686/arch.a devices/devs.a src/kernel.a
	@${MAKE} -C src -f ../root.mk glitch.elf

# iso image
glitch.iso: src/glitch.elf grub/grub.cfg
	@grub-file --is-x86-multiboot2 src/glitch.elf
	@mkdir -p isodir/boot/grub
	@mkdir -p isodir/boot/glitch
	@grub-script-check grub/grub.cfg
	@cp grub/grub.cfg isodir/boot/grub/grub.cfg
	@cp src/glitch.elf isodir/boot/glitch/glitch.elf
	@i686-elf-strip isodir/boot/glitch/glitch.elf
	@rm -f isodir/boot/glitch/checksums
	@sha512sum isodir/boot/glitch/* > isodir/boot/glitch/checksums
	@sed -i s/isodir// isodir/boot/glitch/checksums
	@grub-mkrescue -o glitch.iso isodir