-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (42 loc) · 1.39 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
# This is the name that our final kernel executable will have.
# Change as needed.
KERNEL := yerbaos.elf
# It is highly recommended to use a custom built cross toolchain to build a kernel.
# We are only using "cc" as a placeholder here. It may work by using
# the host system's toolchain, but this is not guaranteed.
CC = cc
# User controllable CFLAGS.
CFLAGS = -Wall -Wextra -O2 -pipe
# Internal link flags that should not be changed by the user.
INTERNALLDFLAGS := \
-fno-pic -fpie \
-Wl,-static,-pie,--no-dynamic-linker,-ztext \
-static-pie \
-nostdlib \
-Tlinker.ld \
-z max-page-size=0x1000
# Internal C flags that should not be changed by the user.
INTERNALCFLAGS := \
-I. \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-pic -fpie \
-mgeneral-regs-only \
-mno-red-zone
# Use find to glob all *.c files in the directory and extract the object names.
CFILES := $(shell find ./ -type f -name '*.c')
OBJ := $(CFILES:.c=.o)
# Targets that do not actually build a file of the same name.
.PHONY: all clean
# Default target.
all: $(KERNEL)
# Link rules for the final kernel executable.
$(KERNEL): $(OBJ)
$(CC) $(INTERNALLDFLAGS) $(OBJ) -o $@
# Compilation rules for *.c files.
%.o: %.c
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
# Remove object files and the final executable.
clean:
rm -rf $(KERNEL) $(OBJ)