-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
87 lines (65 loc) · 2 KB
/
Copy pathMakefile
File metadata and controls
87 lines (65 loc) · 2 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
CC = x86_64-elf-gcc
LD = x86_64-elf-gcc
AS = x86_64-elf-as
RM = rm -rf
OUTPUT_DIR = build
CPPFLAGS += -I"./include" -I"./cdi" -I"./driver" -I"./Include" -I"./loader" -I"./mm" -I"./tasks" -I"./util" -I"./vfs" -I"."
CFLAGS += -gdwarf-4 -Wall -Wextra -fmessage-length=0 -ffreestanding -fno-stack-protector -mno-red-zone -fno-omit-frame-pointer -std=gnu99 -mcx16 -mno-sse
LDFLAGS += -nostdlib -static -T./kernel.ld -z max-page-size=0x1000
C_SRCS = $(shell find -name '*.c' ! -path './lib/stdlibc/math.c')
S_SRCS = ./interrupts.S ./start.S
C_OBJS = $(patsubst ./%,$(OUTPUT_DIR)/%,$(C_SRCS:.c=.o))
S_OBJS = $(patsubst ./%,$(OUTPUT_DIR)/%,$(S_SRCS:.S=.o))
OBJS := $(C_OBJS) $(S_OBJS)
DEPS := $(OBJS:.o=.d)
ifeq ($(BUILD_CONFIG), release)
CFLAGS += -O3
else
CFLAGS += -Og
endif
#get git information
DIRTY=
ifneq ($(shell git diff --shortstat 2> /dev/null),)
DIRTY=-dirty
endif
GIT_COMMIT_ID=$(shell git rev-parse HEAD)$(DIRTY)
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
.PHONY: all
all: kernel libc
.PHONY: release
release:
$(MAKE) BUILD_CONFIG=$@
.PHONY: install-headers
install-headers:
$(MAKE) -C lib install-headers
.PHONY: install-libc
install-libc:
$(MAKE) -C lib install
.PHONY: libc
libc:
$(MAKE) BUILD_CONFIG=$(BUILD_CONFIG) -C lib
.PHONY: kernel
kernel: $(OUTPUT_DIR)/kernel
#Pull in dependency info for *existing* .o files
-include $(DEPS)
$(OUTPUT_DIR)/kernel: CPPFLAGS += -DBUILD_KERNEL
$(OUTPUT_DIR)/kernel: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
$(OUTPUT_DIR)/driver/ext2/%: CPPFLAGS += -I"./driver/ext2/libext2/include"
$(OUTPUT_DIR)/version.o: force_build
$(OUTPUT_DIR)/version.o: CPPFLAGS += -DGIT_BRANCH=$(GIT_BRANCH) -DGIT_COMMIT_ID=$(GIT_COMMIT_ID)
$(OUTPUT_DIR)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -MT $@ -c $< -o $@
$(OUTPUT_DIR)/%.o: %.S
@mkdir -p $(@D)
$(AS) -64 --defsym BUILD_KERNEL= -o $@ $<
.PHONY: clean
clean: clean-kernel clean-libc
.PHONY: clean-kernel
clean-kernel:
-$(RM) $(OUTPUT_DIR)
.PHONY: clean-libc
clean-libc:
-$(MAKE) -C lib clean
force_build: