-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNUmakefile
More file actions
138 lines (112 loc) · 3.6 KB
/
GNUmakefile
File metadata and controls
138 lines (112 loc) · 3.6 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Nuke built-in rules and variables.
MAKEFLAGS += -rR
.SUFFIXES:
# XORRISO
xorriso := xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus -apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label iso_root
iso_out := keystone.iso
# qemu cmd
qemucmd := qemu-system-x86_64 -m 1024M -cdrom $(iso_out) -serial stdio
# This is the name that our final executable will have.
# Change as needed.
override OUTPUT := keystone
# User controllable C compiler command.
CC := cc
# User controllable C flags.
CFLAGS := -g -O2 -pipe
# User controllable C preprocessor flags. We set none by default.
CPPFLAGS :=
# User controllable nasm flags.
NASMFLAGS := -F dwarf -g
# User controllable linker flags. We set none by default.
LDFLAGS :=
# Check if CC is Clang.
override CC_IS_CLANG := $(shell ! $(CC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?)
# If the C compiler is Clang, set the target as needed.
ifeq ($(CC_IS_CLANG),1)
override CC += \
-target x86_64-unknown-none
endif
# Internal C flags that should not be changed by the user.
override CFLAGS += \
-Wall \
-Wextra \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-PIC \
-m64 \
-march=x86-64 \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-mcmodel=kernel \
-Wno-error=unused-parameter \
-Wno-error=unused-variable \
-Werror \
# ignore -Werror=unused-parameter
# Internal C preprocessor flags that should not be changed by the user.
override CPPFLAGS := \
-I src \
$(CPPFLAGS) \
-DLIMINE_API_REVISION=3 \
-MMD \
-MP
# Internal nasm flags that should not be changed by the user.
override NASMFLAGS += \
-Wall \
-f elf64
# Internal linker flags that should not be changed by the user.
override LDFLAGS += \
-Wl,-m,elf_x86_64 \
-Wl,--build-id=none \
-nostdlib \
-static \
-z max-page-size=0x1000 \
-T linker.ld
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
# object and header dependency file names.
override SRCFILES := $(shell cd src && find -L * -type f | LC_ALL=C sort)
override CFILES := $(filter %.c,$(SRCFILES))
override ASFILES := $(filter %.S,$(SRCFILES))
override NASMFILES := $(filter %.asm,$(SRCFILES))
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
# Default target. This must come first, before header dependencies.
.PHONY: all
all: bin/$(OUTPUT)
# Include header dependencies.
-include $(HEADER_DEPS)
# Link rules for the final executable.
bin/$(OUTPUT): GNUmakefile linker.ld $(OBJ)
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@
# Compilation rules for *.c files.
obj/%.c.o: src/%.c GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.S files.
obj/%.S.o: src/%.S GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.asm (nasm) files.
obj/%.asm.o: src/%.asm GNUmakefile
mkdir -p "$$(dirname $@)"
nasm $(NASMFLAGS) $< -o $@
# iso make
iso:
cp bin/keystone iso_root/boot/keystone
$(xorriso) -o $(iso_out)
qemu:
$(qemucmd)
dev: clean all iso qemu
limineclean:
rm -rf limine iso_root/boot/limine iso_root/EFI iso_root/limine-bios-pxe.bin
limine:
./setup_limine.sh
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf bin obj iso_root/boot/keystone $(iso_out)