-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
72 lines (53 loc) · 2.35 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
#############################################################################
# 4IF SEA "SysIF" Makefile
#############################################################################
default:kernel_for_qemu
all: kernel_for_qemu kernel_for_sdcard
kernel_for_qemu: build/kernel.elf build/kernel.list
kernel_for_sdcard: kernel_for_qemu build/kernel.img
remake: clean all
# options à passer au compilateur C
CFLAGS=-Wall -Werror -nostdlib -nostartfiles -ffreestanding -std=c17 -g -fomit-frame-pointer -nostartfiles -O0 -fdiagnostics-show-option
# options à passer à la fois au compilateur C et à l'assembleur
COMMON_FLAGS=-mcpu=arm1176jzf-s
# Object files (excluding kmain)
OBJECTS=$(addsuffix .o, $(addprefix build/, $(basename $(notdir $(wildcard src/*.[cs])))))
# non-default usage: "make KMAIN=test/my-kmain.c"
KMAIN ?= ./kmain.c
# check whether kmain does exists. typically this would get triggered
# by a command like "make KMAIN=" (i.e. with no value for KMAIN)
ifneq "$(shell test -f ''${KMAIN} && echo yes || echo no)" "yes"
$(error no such file: "${KMAIN}")
endif
# check whether we're dealing with a different kmain.c than last time:
# either updated/modified, or maybe another file, located somewhere else
ifneq "$(shell md5sum ${KMAIN})" "$(shell test -f build/kmain.md5 && cat build/kmain.md5)"
# if so, then our kmain.o has to be recompiled
.PHONY: build/kmain.o
endif
build:
mkdir -p build
# compilation C vers ELF
build/%.o: src/%.c $(wildcard src/*.h) | build
arm-none-eabi-gcc $(COMMON_FLAGS) $(CFLAGS) $< -c -o $@
# compilation du point d'entrée
build/kmain.o: $(KMAIN) $(wildcard src/*.h)
arm-none-eabi-gcc $(COMMON_FLAGS) $(CFLAGS) -I src $< -c -o $@
@#"let's silently remember the checksum of the most recent kmain.c we compiled"
@md5sum $(KMAIN) > build/kmain.md5
# assemblage .s vers ELF
build/%.o: src/%.s | build
arm-none-eabi-as -g $(COMMON_FLAGS) $< -c -o $@
# édition de liens
build/kernel.elf: $(OBJECTS) build/kmain.o
arm-none-eabi-ld $^ -o $@ -T src/sysif.ld -Map build/mapfile.map
# conversion de l'image pour transfert sur carte SD
build/kernel.img: build/kernel.elf
arm-none-eabi-objcopy $^ -O binary $@
# désassemblage
build/kernel.list: build/kernel.elf
arm-none-eabi-objdump -d -j .text -j .bss -j .stack -j .kernel_heap -j .user_stacks $< > $@
# nettoyage: effacer tous les fichiers générés
.PHONY:clean
clean:
rm -rf build