-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
96 lines (78 loc) · 2.49 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
INCLUDE_DIR := include
SRC_DIR := src
BUILD_DIR := target
KERNEL_SOURCES := \
boot.s \
devices/aht20.c \
devices/lcd.c \
devices/mcp23017.c \
exception.c \
exception.s \
framebuffer.c \
gpio.c \
halt.c \
i2c.c \
init.c \
mailbox.c \
main.c \
printf.c \
pwm.c \
sleep.c \
string.c \
timer.c \
uart.c \
mmu.c \
emmc.c \
log.c \
malloc.c \
gpt.c \
random.c \
time.c \
devices/ds3231.c \
math.c \
ARMSTUB_SOURCES := armstub.s
CFLAGS_SHARED := -O2 -std=gnu2x -ffreestanding -nostdinc -mcpu=cortex-a72
CFLAGS := $(CFLAGS_SHARED) -iquote$(INCLUDE_DIR) -isystemsqlite -MMD -MP -include$(INCLUDE_DIR)/common.h -Wall -Wextra -Weverything -Wno-pre-c2x-compat -Wno-declaration-after-statement -Wno-gnu-empty-struct -Wno-c++-compat -Wno-gnu -Wno-c++98-compat -Wno-reserved-identifier -Wno-fixed-enum-extension -Wno-switch-enum -Wno-pedantic -g
CC := clang --target=aarch64-unknown-none
OBJCOPY := llvm-objcopy
LD := ld.lld -m aarch64linux
.DEFAULT_GOAL := images
-include $(patsubst %,$(BUILD_DIR)/%.d,$(KERNEL_SOURCES))
$(BUILD_DIR)/%.s.o: $(SRC_DIR)/%.s
mkdir -p $(shell dirname $@)
$(CC) -c $< -o $@
$(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.bin.o: %.bin
mkdir -p $(shell dirname $@)
$(OBJCOPY) -I binary -O elf64-littleaarch64 -B aarch64 $< $@
$(BUILD_DIR)/rust.a: rust rust/**
mkdir -p $(shell dirname $@)
cd $<; cargo build --manifest-path Cargo.toml --release --target aarch64-unknown-none
cp $(shell cargo metadata --manifest-path $</Cargo.toml --format-version 1 | jq --raw-output .target_directory)/aarch64-unknown-none/release/libpios_utils.a $@
$(BUILD_DIR)/kernel8.elf: linker.ld $(patsubst %,$(BUILD_DIR)/%.o,$(KERNEL_SOURCES)) $(BUILD_DIR)/rust.a
mkdir -p $(shell dirname $@)
$(LD) -T $^ -o $@
$(BUILD_DIR)/kernel8.img: $(BUILD_DIR)/kernel8.elf
mkdir -p $(shell dirname $@)
$(OBJCOPY) -O binary $< $@
$(BUILD_DIR)/armstub.elf: $(patsubst %,$(BUILD_DIR)/%.o,$(ARMSTUB_SOURCES))
mkdir -p $(shell dirname $@)
$(LD) --section-start=.text=0 $^ -o $@
$(BUILD_DIR)/armstub.img: $(BUILD_DIR)/armstub.elf
mkdir -p $(shell dirname $@)
$(OBJCOPY) -O binary $< $@
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: images
images: $(BUILD_DIR)/kernel8.img $(BUILD_DIR)/armstub.img
$(SD_DIR)/kernel8.img: $(BUILD_DIR)/kernel8.img
cp $< $@
$(SD_DIR)/config.txt: config.txt
cp $< $@
$(SD_DIR)/armstub.img: $(BUILD_DIR)/armstub.img
cp $< $@
.PHONY: install
install: $(SD_DIR)/kernel8.img $(SD_DIR)/config.txt $(SD_DIR)/armstub.img