-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (64 loc) · 1.61 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
69
70
71
72
73
74
75
76
77
78
79
80
# run :
# chmod +x compile.sh
# chmod +x build.sh
# chmod +x src/modules/mod_asm.lnk
# ./compile.sh
# ./build.sh
#
# clean :
# # Deleting all build files
# rm -rf build/kernel build/*.o build/*.img
#
# autorun :
# chmod +x autorun.sh
# ./autorun.sh
#
# emulate :
# # Run with QEMU
# qemu-system-i386 build/disk.img
KERNEL_IMG=kernel.bin
CC=i686-elf-gcc
AS=i686-elf-as
NASM=nasm
LD=i686-elf-gcc
#LD=i686-elf-ld
CFLAGS = -ggdb -m32 -O0 -Wall -Wextra -std=gnu99 -ffreestanding -I src
AFLAGS = -m32 -ggdb
LDFLAGS = $(CFLAGS) -nostdlib -lgcc -Wl,--build-id=none
NASMFLAGS = -f elf32
## END CONFIGURABLE ##
## Gather the necessary assembly files
NASM_FILES=$(shell find . -name \*.nasm -print)
NASM_OBJ=$(patsubst %.nasm,%.o,$(NASM_FILES))
ASM_FILES=$(shell find . -name \*.s -print)
ASM_OBJ=$(patsubst %.s,%.o,$(ASM_FILES))
## Gather the necessary C files
C_FILES=$(shell find . -name \*.c -print)
C_OBJ=$(patsubst %.c,%.o,$(C_FILES))
DEPFILES=$(patsubst %.c,./deps/%.d,$(C_FILES))
OBJECTS=$(ASM_OBJ) $(C_OBJ)
# clean:
# -@find . -name "*.o" -type f -delete
# -@rm -R deps
all: $(KERNEL_IMG)
## Depfiles contain inter-file dependencies
-include $(DEPFILES)
clean:
-@find . -name "*.o" -type f -delete
-@rm -R deps
-@rm -rf disk.img kernel.bin
# -@rm f32.disk
$(KERNEL_IMG) : $(OBJECTS) link.ld
sudo chmod +x build.sh
./build.sh
## $(basename $(NASM_FILES))
%.o : %.nasm
@echo -e "[MM]\t\t" $@
$(NASM) $(NASMFLAGS) -o $@ $<
link.ld : $(NASM_OBJ)
$(LD) $(LDFLAGS) -T src/link.ld -o $(KERNEL_IMG) $(OBJECTS)
deps/%.d : %.c
@mkdir -p deps
@mkdir -p `dirname $@`
@echo -e "[MM]\t\t" $@
@$(CC) $(CFLAGS) -MM $< -MF $@