-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
109 lines (85 loc) · 3.04 KB
/
Copy pathMakefile
File metadata and controls
109 lines (85 loc) · 3.04 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
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
# This Makefile is assuming you have installed said dependancies
# We are also assuming other things. This includes:
# 1. You are using MacOS (anything but Arch)
# 2. You have the dependancies installed via Homebrew
# 3. You actually want to run the code.
# Dependancies are listed in README.md
RED = \033[0;31m
NC = \033[0m
MAKE_PREFIX = [$(RED)MAKE$(NC)]
NASM = nasm
ifeq ($(shell uname),Darwin)
GCC = x86_64-elf-gcc
LD = x86_64-elf-ld
GRUB_MKRESCUE = i686-elf-grub-mkrescue
else
GCC = gcc -m32
LD = ld
GRUB_MKRESCUE = grub-mkrescue
endif
INCLUDE_PATHS=$(shell find . -type d -name include)
NESTED_INCLUDE_PATHS=$(shell find . -type d -path '*/include/*')
ALL_INCLUDE_PATHS=$(INCLUDE_PATHS) $(NESTED_INCLUDE_PATHS)
INCLUDES=$(addprefix -I,$(ALL_INCLUDE_PATHS))
QEMU = qemu-system-i386
SRC = $(shell find sys -name "*.c" -type f)
OBJ = $(SRC:.c=.o)
ASM_SRC = $(shell find sys -name "*.asm" -type f)
ASM_OBJ = $(ASM_SRC:.asm=.o)
all: preclean build-run clean-all
build-elf: $(ASM_OBJ) $(OBJ)
@bash -c 'if [ "$(shell uname)" = "Linux" ]; then \
echo "Detected Linux."; \
fi'
@echo "$(MAKE_PREFIX) Building ELF..."
@$(LD) -m elf_i386 -T sys/link.ld -o bin/MooseOS.elf $(ASM_OBJ) $(OBJ)
%.o: %.c
@echo "$(MAKE_PREFIX) GCC: Compiling $<..."
@$(GCC) -m32 -c $< -o $@ -nostdlib -ffreestanding -O2 -mno-sse -mno-mmx $(INCLUDES)
%.o: %.asm
@echo "$(MAKE_PREFIX) NASM: Assembling $<..."
@$(NASM) -f elf32 $< -o $@
create-disk:
@if [ ! -f bin/moose_disk.img ]; then \
mkdir -p bin; \
dd if=/dev/zero of=bin/moose_disk.img bs=1M count=10; \
echo "$(MAKE_PREFIX) Created 10MB disk image: bin/moose_disk.img"; \
else \
echo "$(MAKE_PREFIX) Disk image bin/moose_disk.img already exists, skipping creation"; \
fi
build-iso: build-elf
@echo "$(MAKE_PREFIX) Building ISO..."
@mkdir -p iso/boot/grub
@cp bin/MooseOS.elf iso/boot
@# Copy files over from boot/grub/grub.cfg
@cp sys/boot/grub/grub.cfg iso/boot/grub/
@$(GRUB_MKRESCUE) -o bin/MooseOS.iso iso
@rm -rf iso
build-run: build-elf create-disk run
run: create-disk
@echo "$(MAKE_PREFIX) Running QEMU..."
@$(QEMU) -kernel bin/MooseOS.elf -drive file=bin/moose_disk.img,format=raw,if=ide -m 512M -audiodev coreaudio,id=speaker -machine pcspk-audiodev=speaker -serial stdio
run-fullscreen:
@$(QEMU) -display cocoa,zoom-to-fit=on -kernel bin/MooseOS.elf -drive file=bin/moose_disk.img,format=raw,if=ide -full-screen -m 512M -serial stdio
# Note: There is no build-run-fullscreen target
rm-iso:
@rm -f bin/MooseOS.iso
@rm -rf iso
clean-disk:
@rm -f bin/moose_disk.img
clean-o:
@rm -f $(ASM_OBJ) $(OBJ)
clean-all:
@echo "$(MAKE_PREFIX) Cleaning all object files.."
@find . -name "*.o" -type f -delete
@echo "$(MAKE_PREFIX) All .o files removed."
preclean:
@echo "$(MAKE_PREFIX) Removing previous build files..."
@find . -name "*.o" -type f -delete
clean-kernel:
@rm -f bin/MooseOS.elf
run-bochs: create-disk
@echo "$(MAKE_PREFIX) Running MooseOS with Bochs..."
@echo "$(MAKE_PREFIX) Note: QEMU is reccommended for better performance."
@bochs -f bin/bochsrc.txt -q
@echo "$(MAKE_PREFIX) Bochs session ended."