-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (47 loc) · 1.77 KB
/
Makefile
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
BASEDIR = $(shell echo $(CURDIR)|sed 's/ /\\ /g')
BINDIR=$(BASEDIR)/bin
SRCDIR=$(BASEDIR)/src
WORKDIR=$(BASEDIR)/work
CROSSDIR = /usr/local/cross/ia32
CC = $(CROSSDIR)/bin/i686-elf-gcc
AS = $(CROSSDIR)/bin/i686-elf-as
CFLAGS=-std=gnu99 -ffreestanding -O2 -Wall -Wextra -fno-builtin -fno-stack-protector -nostdlib
#-nostdinc
INCLUDEDIRS = $(SRCDIR)
ASSEMBLIES_ABS = $(shell find $(SRCDIR) -name '*.s')
SOURCES_ABS = $(shell find $(SRCDIR) -name '*.c')
ASSEMBLIES = $(subst $(BASEDIR)/,,$(ASSEMBLIES_ABS))
SOURCES = $(subst $(BASEDIR)/,,$(SOURCES_ABS))
TARGETS = $(SOURCES:.c=.o) $(ASSEMBLIES:.s=.o)
OBJECTS = $(shell find $(SRCDIR) -name '*.o')
help:
@echo 'Usage: - make command'
@echo 'compile - compiles all files to object files'
@echo 'iso - creates an iso image of the kernel'
@echo 'link - links all object files together to a binary'
@echo 'run - runs the kernel, using qemu'
@echo 'clean - deletes bin, obj and work directory'
@echo 'help - shows this help message'
clean:
@if [ ! -z "$(OBJECTS)" ]; then rm $(OBJECTS); fi
@if [ -e $(BINDIR) ]; then rm -r $(BINDIR); fi
@if [ -e $(WORKDIR) ]; then rm -r $(WORKDIR); fi
compile: $(TARGETS)
%.o: %.s
$(AS) -o $@ $<
%.o: %.c
$(CC) -c -o $@ $(CFLAGS) $< -I $(INCLUDEDIRS)
iso: $(WORKDIR) compile link
mkdir -p $(WORKDIR)/boot/grub
cp $(BINDIR)/hammeros.bin $(WORKDIR)/boot/hammeros.bin
cp grub.cfg $(WORKDIR)/boot/grub/grub.cfg
grub-mkrescue -o $(BINDIR)/hammeros.iso $(WORKDIR)
link: $(BINDIR)
$(CC) -T $(SRCDIR)/linker.ld -o $(BINDIR)/hammeros.bin -ffreestanding -O2 -nostdlib $(OBJECTS) -lgcc
# Exit alt-2 q <enter>
run: compile link
qemu-system-i386 --curses -kernel $(BINDIR)/hammeros.bin
$(BINDIR):
mkdir -p $(BINDIR)
$(WORKDIR):
mkdir -p $(WORKDIR)/boot/grub