-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
47 lines (47 loc) · 1.47 KB
/
makefile
File metadata and controls
47 lines (47 loc) · 1.47 KB
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
UNAME_S := $(shell uname -s)
CC=
LD=
OUT=./bin
NO_SSE = -mno-sse -mno-sse2 -mfpmath=387 -march=i386
ifeq ($(UNAME_S),Linux)
CFLAGS = -ffreestanding -Wall -Wextra -Wno-unused-function -Wno-unused-variable \
-fno-exceptions -nostdlib -nostdinc -fno-stack-protector \
-fno-builtin-function -fno-builtin
CC=i386-elf-gcc -m32
LD=i386-elf-ld
endif
ifeq ($(UNAME_S),Darwin)
CFLAGS = -ffreestanding -g -Wall -Wextra \
-fno-exceptions -nostdlib -nostdinc -fno-stack-protector \
-fno-builtin-function -fno-builtin \
-Wno-unused-function -Wno-unused-variable
CC=x86_64-elf-gcc -m32
LD=x86_64-elf-ld -melf_i386
endif
all: clean bootloader kernel os qemu
clean:
@echo "Clean $(OUT)"
@rm -rf $(OUT)
@mkdir -p $(OUT)
bootloader:
@echo "Build Bootloader"
@nasm -f bin src/boot/boot.asm -o $(OUT)/boot.bin
kernel:
@echo "Build kernel"
@mkdir -p $(OUT)/kernel
@nasm -f elf src/kernel/kernelstrap.asm -o ./bin/kernel/kernelstrap.asm.o
@elfs="";\
for file in src/*/*.c;\
do \
echo "Build $$file"; \
$(CC) -c $(NO_SSE) $(CFLAGS) $$file -o $(OUT)/kernel/$$(basename $${file}.o) ;\
elfs+="$(OUT)/kernel/$$(basename $${file}.o) "; \
done ; \
$(LD) -o $(OUT)/kernel.bin --oformat binary -T linker.ld $(OUT)/kernel/kernelstrap.asm.o $$elfs
os:
@echo "Build final OS"
@cat $(OUT)/boot.bin $(OUT)/kernel.bin > $(OUT)/os.bin
@echo "Full image at $(OUT)/os.bin"
qemu:
qemu-system-i386 -drive format=raw,file=$(OUT)/os.bin \
-qmp unix:./qmp-sock,server,wait=off