-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
69 lines (51 loc) · 1.38 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
# MAkefile for tutorials from
# http://www.jamesmolloy.co.uk/tutorial_html/1.-Environment%20setup.html
ASM_SRC = src/boot.s \
src/gdt.s \
src/idt.s \
src/interrupt.s
C_SRC = src/main.c \
src/common.c \
src/string.c \
src/printf.c \
src/monitor.c \
src/descriptor_tables.c \
src/isr.c
KERNEL=bin/kernel
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector
LDFLAGS = -melf_i386 -Tlink.ld
ASFLAGS = -felf
all: link image run
SOURCES = $(ASM_SRC) $(C_SRC)
ASM_OBJS = $(patsubst src/%.s,obj/%.o,$(ASM_SRC))
C_OBJS = $(patsubst src/%.c,obj/%.o,$(C_SRC))
OBJS = $(ASM_OBJS) $(C_OBJS)
DEPS = $(patsubst src/%.c,.deps/%.d,$(C_SRC))
-include $(DEPS)
image: link
./update_image.sh
run: image
./run_bochs.sh
obj:
mkdir obj
clean:
rm -f $(OBJS)$(KERNEL)
link: obj $(OBJS) bin
ld $(LDFLAGS) -o $(KERNEL) $(OBJS)
bin:
mkdir bin
.PHONY: image link run clean all
obj/%.o: src/%.s
nasm $(ASFLAGS) $<
mv $(patsubst %.s,%.o,$<) $@
obj/%.o: src/%.c
$(CC) $(CFLAGS) -o $@ -c $<
# MF: write rule to file
# MG: assume missing headers will be generated, don't barf
# MM: generate dependency rule for prerequisite, skip system headers
# MP: add phony target for each header to prevent missing header errors
# MT: add target for generated dependency
.deps/%.d: src/%.c
mkdir -p .deps
$(CC) $(CFLAGS) -MF"$@" -MG -MM -MP -MT"$@" -MT"$(patsubst src/%.c,obj/%.o,$<)" "$<"