-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
87 lines (65 loc) · 2.53 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# InfOS
#
# Copyright (C) University of Edinburgh 2016. All Rights Reserved
# Tom Spink <[email protected]>
#
export MAKEFLAGS += -rR --no-print-directory
export q := @
export arch ?= x86
__default: all
export top-dir := $(CURDIR)
export build-dir := $(top-dir)/build
export inc-dir := $(top-dir)/include
export out-dir := $(top-dir)/out
-include $(build-dir)/Makefile.include
export common-flags := -I$(inc-dir) -nostdinc -nostdlib -g -Wall -O3 -std=gnu++17 -fno-pic
export common-flags += -mcmodel=kernel
export common-flags += -ffreestanding -fno-builtin -fno-omit-frame-pointer -fno-rtti -fno-exceptions -fno-stack-protector
export common-flags += -fno-delete-null-pointer-checks -mno-red-zone
export common-flags += -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4 -mno-avx -mno-aes -mno-sse4a -mno-fma4
export cxxflags := $(common-flags)
export asflags := $(common-flags)
export ldflags := -nostdlib -z nodefaultlib
export target := $(out-dir)/infos-kernel
export toplevel-obj := $(top-dir)/infos-kernel.o
export linker-script := $(top-dir)/kernel.ld
export source-dirs := arch/$(arch) kernel/ util/ drivers/ mm/ fs/
ifneq ($(wildcard $(top-dir)/oot/.),)
export source-dirs += oot/
endif
export main-cpp-src := $(patsubst %,$(top-dir)/%,$(shell find $(source-dirs) | grep -E "\.cpp$$"))
export main-as-src := $(patsubst %,$(top-dir)/%,$(shell find $(source-dirs) | grep -E "\.S$$"))
export main-obj := $(main-cpp-src:.cpp=.o) $(main-as-src:.S=.o)
export main-dep := $(main-obj:.o=.d)
all: $(target)
@echo
@echo " InfOS kernel build complete: $(target)"
@echo
clean: .FORCE
rm -f $(target) $(toplevel-obj) $(main-dep) $(main-obj)
sources: .FORCE
@echo $(main-cpp-src)
$(target): $(toplevel-obj) $(linker-script) $(out-dir)
@echo " LD $(BUILD-TARGET).64"
$(q)$(ld) -n -o [email protected] -T $(linker-script) $(ldflags) $(toplevel-obj)
@echo " OBJCOPY $(BUILD-TARGET)"
$(q)$(objcopy) --input-target=elf64-x86-64 --output-target=elf32-i386 [email protected] $@
$(toplevel-obj): $(main-obj)
@echo " LD $(BUILD-TARGET)"
$(q)$(ld) -r -o $@ $(ldflags) $^
$(out-dir):
@echo " MKDIR $(BUILD-TARGET)"
$(q)mkdir $@
%.o: %.cpp %.d
@echo " CXX $(BUILD-TARGET)"
$(q)$(cxx) -c -o $@ $(cxxflags) $<
%.o: %.S %.d
@echo " AS $(BUILD-TARGET)"
$(q)$(cxx) -c -o $@ $(asflags) $<
%.d: %.cpp
$(q)$(cxx) -M -MT $(@:.d=.o) -o $@ $(cxxflags) $<
%.d: %.S
$(q)$(cxx) -M -MT $(@:.d=.o) -o $@ $(cxxflags) $<
-include $(main-dep)
.PHONY: __default all clean .FORCE