-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (45 loc) · 1.11 KB
/
Makefile
File metadata and controls
62 lines (45 loc) · 1.11 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
# change application name here (executable output name)
TARGET=kernel
LINKERSCRIPT=link.ld
# compiler
CC=gcc
ASM=nasm
QEMU=qemu-system-i386 -kernel
LD=ld
# Specific C compiler flags
# OPT=-O2
OPT=-ggdb
WARN=-Wall -Wextra
STD=c11
# compiler, assembler, linker flags
CCFLAGS= -m32 $(WARN) -std="$(STD)" $(OPT) -fno-stack-protector #-pipe
ASMFLAGS= -f elf32
LINKERFLAGS= -m elf_i386 -T $(LINKERSCRIPT)
# source files
CCSRCS = $(wildcard *.c)
ASMSRCS = $(wildcard *.asm)
SRCS = $(CCSRCS) $(ASMSRCS)
# object files
CCOBJS = $(patsubst %.c, %_c.o, $(CCSRCS))
ASMOBJS = $(patsubst %.asm, %_asm.o, $(ASMSRCS))
OBJS = $(CCOBJS) $(ASMOBJS)
.PHONY: default all run clean debug
default: $(TARGET)
all: default
%_c.o: %.c
$(CC) $(CCFLAGS) -c $< -o $@
%_asm.o: %.asm
$(ASM) $(ASMFLAGS) $< -o $@
$(TARGET): $(OBJS)
$(LD) $(LINKERFLAGS) -o $(TARGET) $(OBJS)
run: all
$(QEMU) $(TARGET)
debug: default
$(QEMU) $(TARGET) -s -S &
# -s means it'll listen for gdb connection
# -S means freeze and wait for a gdb connection
gdb: debug
gdb $(TARGET) -ex "target remote :1234"
.PRECIOUS: $(TARGET) $(OBJS)
clean:
rm -f *.o $(TARGET)