-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
69 lines (52 loc) · 1.88 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
63
64
65
66
67
68
69
# Make File for Bulding Ultron
# Sets up the Assembler
AS := nasm
ASFLAGS := -f elf
ASFILES := $(wildcard kernel/boot/*.s kernel/arch/*.s)
ASOBJECTS := $(ASFILES:.s=.s.o)
# Compile C++ Files
CXX := g++
CXXFLAGS := -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 -I./kernel/include
CXXFILES := $(wildcard *.cc kernel/*.cc kernel/core/*.cc kernel/modules/*.cc )
CXXOBJECTS := $(CXXFILES:.cc=.o)
CXXHEADERS := $(wildcard *h kernel/include/*.h)
# Manage Dependencies So that make remakes requred files when header changes
DEPENDS := $(CXXFILES:.cc=.d)
# Manage the Precompiled Headers
PRECOMP := $(wildcard kernel/include/*.h.gch)
# Linker
LD := ld
LDFLAGS := -m elf_i386 -T link.ld
# Style Script
STYLER := bash scripts/style.sh
# Declare clean and run as Phony Targets
.PHONY: clean run style
# The Final Product will be ultron.bin in the build directory
all: ultron.bin
# Ultron.img : It is the Final Product formed by linking all the object files together
ultron.bin : $(ASOBJECTS) $(CXXOBJECTS)
$(LD) $(LDFLAGS) -o build/$@ $^
# Run the Kernel : First Make the Kernel and then run it
run: ultron.bin
qemu-system-i386 -kernel 'build/ultron.bin'
# Assemble the Assembly Files into object Files
# This Assembles all the Files into thier respective object files
%.s.o: %.s
$(AS) $(ASFLAGS) $< -o $@
# Compile the C++ Files into corresponding object Files and place it in same directory
%.o: %.cc
$(CXX) $(CXXFLAGS) -o $@ $<
# Generate the Dependency Make files so 'make' updates
# the objects when headers are modified
# The -MD and -MM Options Generates the MakeFiles
%.d: %.cc
$(CXX) -MM -MD -I./kernel/include -o $@ $<
# Inlcude the Generated Make Files
-include $(DEPENDS)
# Style the Script uses AStlye to Format to GNU Style
style:
$(STYLER) kernel cc
$(STYLER) kernel h
# Clean this Mess
clean: $(ASOBJECTS) $(CXXOBJECTS) $(DEPENDS) $(PRECOMP)
$(RM) -f $^