-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (86 loc) · 3 KB
/
Makefile
File metadata and controls
110 lines (86 loc) · 3 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
110
PHYS_KBASE := 0x0000000000200000
VIRT_KBASE := 0xFFFFFFFF80000000
CC := gcc
CFLAGS := -g -m64 -Wall -Wextra \
-mno-red-zone -mcmodel=large \
-nostdlib -nostdinc -ffreestanding \
-DSTAGE3 -D__PHYS_KBASE=$(PHYS_KBASE) \
-D__VIRT_KBASE=$(VIRT_KBASE)
CXX := g++
CXXFLAGS := -g -m64 -Wall -Wextra \
-mno-red-zone -mcmodel=large \
-nostdlib -nostdinc -ffreestanding \
-DSTAGE3 -D__PHYS_KBASE=$(PHYS_KBASE) \
-D__VIRT_KBASE=$(VIRT_KBASE) \
-fno-rtti -nostartfiles -fno-exceptions \
-fno-stack-protector -std=c++0x -fno-builtin \
-nodefaultlibs
LD := ld
LDFLAGS := --defsym PHYS_KBASE=$(PHYS_KBASE) \
--defsym VIRT_KBASE=$(VIRT_KBASE) \
--warn-common
KERNEL := stage3
MAP := stage3.map
BOOT_IMAGE := boot
BOOT_ISO := boot.iso
# Directories
ROOT := $(shell pwd)
SRC := $(ROOT)/src
INCLUDE := $(ROOT)/include
# File list
INCLUDES := $(INCLUDE) $(INCLUDE)/libc $(INCLUDE)/libc/c++ $(INCLUDE)/bootstrap
SOURCES :=
include make/Makefile.bootstrap
include make/Makefile.core
include make/Makefile.libc
OBJECTS := $(patsubst %.cpp,%.o, $(patsubst %.S,%.o, $(SOURCES:.c=.o)))
CC_INCLUDES := $(addprefix -I, $(INCLUDES))
# Main target
all: $(BOOT_IMAGE) $(MAP)
runb: $(BOOT_ISO)
bochs -f ./extra/bochsrc
rund: $(KERNEL)
qemu-system-x86_64 -kernel $(KERNEL) -net none -m 64 -no-reboot -no-shutdown -s -monitor stdio
run: $(KERNEL)
qemu-system-x86_64 -kernel $(KERNEL) -net none -m 64 -no-reboot
$(BOOT_IMAGE): $(KERNEL)
ifeq ($(wildcard $(BOOT_IMAGE)), )
./extra/mkboot.sh $(BOOT_IMAGE) $<
else
@echo [GEN] $(subst $(PWD)/,,$@) from $(subst $(PWD)/,,$<)
@./extra/mount.sh $@ $<
endif
$(BOOT_ISO): $(KERNEL)
@echo [GEN] $(subst $(PWD)/,,$@) from $(subst $(PWD)/,,$<)
@./extra/mkiso.sh $@ $<
$(KERNEL): $(OBJECTS) $(SRC)/bootstrap/linker.lds
@echo [LD] $(subst $(PWD)/,,$@)
@$(LD) $(LDFLAGS) -T $(SRC)/bootstrap/linker.lds -o $@ $(OBJECTS)
$(MAP): $(KERNEL)
@echo [MAP] $(subst $(PWD)/,,$@)
@nm -C $< | cut -d ' ' -f 1,3 | sort > $@
# Create objects from C++ source code
%.o: %.cpp
@echo [CXX] $(subst $(PWD)/,,$@)
@$(CXX) $(CC_INCLUDES) -c $< $(CXXFLAGS) -o $@
# Create objects from C source code
%.o: %.c
@echo [CC] $(subst $(PWD)/,,$@)
@$(CC) $(CC_INCLUDES) -c $< $(CFLAGS) -o $@
# Create objects from assembler (.S) source code
%.o: %.S
@echo [AS] $(subst $(PWD)/,,$@)
@$(CC) $(CC_INCLUDES) -c $< $(CFLAGS) -DASM_SOURCE=1 -DASM_FILE=1 -o $@
# Clean directory
clean:
@echo [RM] \*~
@find . -name '*~' -print | xargs rm -f
@echo [RM] \*.o
@find . -name '*.o' -print | xargs rm -f
distclean:
@echo [RM] \*~
@find . -name '*~' -print | xargs rm -f
@echo [RM] \*.o
@find . -name '*.o' -print | xargs rm -f
@echo [RM] $(BOOT_IMAGE) $(BOOT_ISO) $(KERNEL) $(MAP)
@rm -f $(BOOT_IMAGE) $(BOOT_ISO) $(KERNEL) $(MAP)