aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: fa371645dcea6c4dfbb7f688414bd06a706d4eab (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
79
80
81
MAKE       = make
MAKEFLAGS += --no-print-directory
SRC_ROOT  := $(shell pwd)

include Makefile.config

.PHONY: all doc run clean test FORCE
all: glitch.elf

doc: FORCE
	doxygen doxygen.config

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

clean:
	@${MAKE} ARCH=${ARCH} -C lib clean
	@${MAKE} ARCH=${ARCH} -C ${ARCH} clean
	@${MAKE} ARCH=${ARCH} -C devices clean
	@${MAKE} ARCH=${ARCH} -C src clean

info:
	@echo "* Build information *"
	@echo "  ARCH  ${ARCH}"
	@echo "  MAKE  $(shell ${MAKE} --version | head -n1)"
	@echo "  CC    $(shell ${CC} --version | head -n1)"
	@echo "        ${CFLAGS}"
	@echo "  CXX   $(shell ${CXX} --version | head -n1)"
	@echo "        ${CXXFLAGS}"
	@echo "  LD    $(shell ${LD} --version | head -n1)"
	@echo "        ${LDFLAGS}"

test:
	@echo Looking for inline assembly
	@grep -rn 'asm' devices lib src
	@echo Running tests
	@make -C lib test
	@make -C src test

valgrind:
	@make -C lib valgrind
	@make -C src valgrind

FORCE:

.config: Kconfig
	@alldefconfig

Makefile.config: .config
	@cp .config Makefile.config
	@echo -e '\n# toolchain.mk' >> Makefile.config
	@cat $$(sed -nE "s/CONFIG_ARCH_(.+)=y/\1/p" .config)/toolchain.mk >> Makefile.config

lib/libk.a: FORCE
	@${MAKE} -C lib libk.a
i686/arch.a: FORCE
	@${MAKE} -C ${ARCH} arch.a
devices/devs.a: FORCE
	@${MAKE} -C devices devs.a
src/kernel.a: FORCE
	@${MAKE} -C src kernel.a

glitch.elf: ${ARCH}/arch.a src/kernel.a devices/devs.a lib/libk.a
	@echo '  LD   $@'
	@${LD} ${LDFLAGS} -T ${ARCH}/linker.ld -o $@ $^
	@echo -n '  B2b  '
	@b2sum $@ | cut -d ' ' -f1

glitch.iso: glitch.elf grub/grub.cfg
	@grub-file --is-x86-multiboot2 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 glitch.elf isodir/boot/glitch/glitch.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