summaryrefslogtreecommitdiff
path: root/makefile
blob: c3f4ad3af5d1cc7a62f5ee408232def0d1675f41 (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
LIMINE_DIR = $(abspath dependencies/limine)
MINTSUKI_HEADERS_DIR = $(abspath dependencies/mintsuki-headers)
TOOLCHAIN_DIR = $(abspath toolchain)

EXTRA_CC_ARGS = -Wall -Wextra -Og -ggdb -fno-exceptions

HILBERT_NASM = nasm -f elf64
HILBERT_CC = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-c++ -std=c++20 \
  ${EXTRA_CC_ARGS} -static -mno-sse -I include -I $(abspath euler/include) \
  -I $(abspath libraries/daguerre/include) -I ${MINTSUKI_HEADERS_DIR} \
  -I $(abspath libraries/goldman/include)
HILBERT_AR = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-ar
HILBERT_LD = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-ld -z noexecstack

.EXPORT_ALL_VARIABLES:

LIB_DIR = ${TOOLCHAIN_DIR}/usr/x86_64-elf/lib

LIMINE_DEP = dependencies/.limine-done
MINTSUKI_HEADERS_DEP = dependencies/.mintsuki-headers-done
BINUTILS_DEP = toolchain/.binutils-done
GCC_DEP = toolchain/.gcc-done
LIBGCC_DEP = toolchain/.libgcc-done
LIBSTDCPP_DEP = toolchain/.libstdcpp-done

EULER_DEP = toolchain/.euler-done
DAGUERRE_DEP = toolchain/.daguerre-done

APP_DEPS = ${EULER_DEP}
LIBRARY_DEPS = ${LIBSTDCPP_DEP}

.PHONY: default run clean clean-dependencies

default: build/disk.iso

run: build/disk.iso
	gdb -x qemu.gdb

clean:
	rm -rf build ${EULER_DEP} ${DAGUERRE_DEP}
	make -C euler clean
	make -C kernel clean
	make -C applications/init clean
	make -C applications/goldman clean
	make -C applications/hello clean
	make -C libraries/daguerre clean

clean-dependencies: clean
	rm -rf toolchain dependencies

${LIMINE_DEP}:
	mkdir -p dependencies
	test -e dependencies/limine || git clone --depth 1 -b v7.5.1 https://github.com/limine-bootloader/limine dependencies/limine
	cd ${LIMINE_DIR} && ./bootstrap
	cd ${LIMINE_DIR} && ./configure --enable-bios --enable-bios-cd
	+make -C ${LIMINE_DIR}
	touch $@

${MINTSUKI_HEADERS_DEP}:
	mkdir -p dependencies
	test -e dependencies/mintsuki-headers || git clone --depth 1 https://github.com/osdev0/freestanding-headers dependencies/mintsuki-headers
	cd dependencies/mintsuki-headers && git fetch --depth=1 origin dd3abd2d7147efc4170dff478d3b7730bed14147
	cd dependencies/mintsuki-headers && git checkout dd3abd2d7147efc4170dff478d3b7730bed14147
	patch dependencies/mintsuki-headers/stddef.h patches/mintsuki-stddef.patch
	touch $@

${BINUTILS_DEP}:
	mkdir -p dependencies toolchain/usr
	test -e dependencies/binutils || git clone --depth 1 -b binutils-2_42 https://sourceware.org/git/binutils-gdb dependencies/binutils
	mkdir -p dependencies/binutils/build
	cd dependencies/binutils/build && ../configure --disable-gdb \
	  --target=x86_64-elf --prefix=${TOOLCHAIN_DIR}/usr
	+make -C dependencies/binutils/build
	+make -C dependencies/binutils/build install
	touch $@

${GCC_DEP}: ${BINUTILS_DEP}
	mkdir -p toolchain/usr/include
	test -e dependencies/gcc || git clone --depth 1 -b releases/gcc-14.1.0 https://gcc.gnu.org/git/gcc dependencies/gcc
	mkdir -p dependencies/gcc/build
	cd dependencies/gcc/build && ../configure --disable-fixed-point \
	  --disable-gcov --disable-multilib --disable-shared \
	  --disable-hosted-libstdcxx \
	  --enable-languages=c++ --target=x86_64-elf --enable-cstdio=stdio_pure \
	  --prefix=${TOOLCHAIN_DIR}/usr --without-headers --enable-cxx-flags=-mno-sse
	+make -C dependencies/gcc/build all-gcc
	+make -C dependencies/gcc/build install-gcc
	touch $@

${LIBGCC_DEP}: ${GCC_DEP}
	+make -C dependencies/gcc/build all-target-libgcc
	+make -C dependencies/gcc/build install-target-libgcc
	touch $@

${LIBSTDCPP_DEP}: ${LIBGCC_DEP}
	+make -C dependencies/gcc/build all-target-libstdc++-v3
	+make -C dependencies/gcc/build install-target-libstdc++-v3
	patch toolchain/usr/x86_64-elf/include/c++/14.1.0/memory patches/gcc-memory.patch
	touch $@

${EULER_DEP}: ${LIBRARY_DEPS}
	+make -C euler build/crt0.o build/libc.a build/libg.a build/libm.a
	mkdir -p ${LIB_DIR}
	cp euler/build/crt0.o euler/build/libc.a \
	  euler/build/libg.a euler/build/libm.a ${LIB_DIR}/
	touch $@

${DAGUERRE_DEP}: ${LIBRARY_DEPS}
	+make -C libraries/daguerre build/libdaguerre.a
	cp libraries/daguerre/build/libdaguerre.a ${LIB_DIR}/
	touch $@

kernel/build/kernel.elf: ${GCC_DEP} ${MINTSUKI_HEADERS_DEP} ${LIMINE_DEP}
	+make -C kernel build/kernel.elf

applications/init/build/init.elf: ${APP_DEPS}
	+make -C applications/init build/init.elf

applications/goldman/build/goldman.elf: ${APP_DEPS} ${DAGUERRE_DEP}
	+make -C applications/goldman build/goldman.elf

applications/hello/build/hello.elf: ${APP_DEPS} ${DAGUERRE_DEP}
	+make -C applications/hello build/hello.elf

build/initfs.tgz: applications/init/build/init.elf \
                  applications/goldman/build/goldman.elf \
                  applications/hello/build/hello.elf
	@mkdir -p build
	rm -rf build/initfs
	cp -r skeleton build/initfs
	cp applications/init/build/init.elf build/initfs/bin/init
	cp applications/goldman/build/goldman.elf build/initfs/bin/goldman
	cp applications/hello/build/hello.elf build/initfs/bin/hello
	cd build/initfs && tar czf ../initfs.tgz .

build/disk.iso: kernel/build/kernel.elf build/initfs.tgz ${LIMINE_DEP}
	@mkdir -p build
	rm -rf build/iso
	mkdir build/iso
	cp kernel/build/kernel.elf ${LIMINE_DIR}/bin/limine-bios.sys \
	  ${LIMINE_DIR}/bin/limine-bios-cd.bin build/initfs.tgz build/iso/
	echo 'TIMEOUT=0' > build/iso/limine.cfg
	echo ':Hilbert OS' >> build/iso/limine.cfg
	echo 'PROTOCOL=limine' >> build/iso/limine.cfg
	echo 'KERNEL_PATH=boot:///kernel.elf' >> build/iso/limine.cfg
	echo 'MODULE_PATH=$$boot:///initfs.tgz' >> build/iso/limine.cfg
	echo 'MODULE_CMDLINE=initfs' >> build/iso/limine.cfg
	xorriso -as mkisofs -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 \
	  -boot-info-table --protective-msdos-label build/iso -o $@