-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
72 lines (53 loc) · 1.74 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
TARGET ?= aarch64-none-elf
CROSS ?= $(TARGET)
CC := $(CROSS)-gcc
CCFLAGS ?= -Wall -O2 -nostdlib -nostartfiles -ffreestanding -pie
XARGO ?= CARGO_INCREMENTAL=0 RUST_TARGET_PATH="$(shell pwd)" xargo
LD_LAYOUT := ext/layout.ld
RUST_BINARY := $(shell cat Cargo.toml | grep name | cut -d\" -f 2 | tr - _)
RUST_BUILD_DIR := target/$(TARGET)
RUST_DEBUG_LIB := $(RUST_BUILD_DIR)/debug/lib$(RUST_BINARY).a
RUST_RELEASE_LIB := $(RUST_BUILD_DIR)/release/lib$(RUST_BINARY).a
RUST_DEPS = Xargo.toml Cargo.toml build.rs $(LD_LAYOUT) src/*
EXT_DEPS = $(BUILD_DIR)/init.o
BUILD_DIR := build
KERNEL := $(BUILD_DIR)/$(RUST_BINARY)
RUST_LIB := $(BUILD_DIR)/$(RUST_BINARY).a
.PHONY: all clean check
VPATH = ext
all: $(KERNEL).hex $(KERNEL).bin
check:
@$(XARGO) check --target=$(TARGET)
$(RUST_DEBUG_LIB): $(RUST_DEPS)
@echo "+ Building $@ [xargo]"
@$(XARGO) build --target=$(TARGET)
$(RUST_RELEASE_LIB): $(RUST_DEPS)
@echo "+ Building $@ [xargo --release]"
@$(XARGO) build --release --target=$(TARGET)
ifeq ($(DEBUG),1)
$(RUST_LIB): $(RUST_DEBUG_LIB) | $(BUILD_DIR)
@cp $< $@
else
$(RUST_LIB): $(RUST_RELEASE_LIB) | $(BUILD_DIR)
@cp $< $@
endif
$(BUILD_DIR):
@mkdir -p $@
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
@echo "+ Building $@ [cc $<]"
@$(CC) $(CCFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: %.S | $(BUILD_DIR)
@echo "+ Building $@ [as $<]"
@$(CC) $(CCFLAGS) -c $< -o $@
$(KERNEL).elf: $(EXT_DEPS) $(RUST_LIB) | $(BUILD_DIR)
@echo "+ Building $@ [ld $^]"
@$(CROSS)-ld --gc-sections -o $@ $^ -T$(LD_LAYOUT)
$(KERNEL).hex: $(KERNEL).elf | $(BUILD_DIR)
@echo "+ Building $@ [objcopy $<]"
@$(CROSS)-objcopy $< -O ihex $@
$(KERNEL).bin: $(KERNEL).elf | $(BUILD_DIR)
@echo "+ Building $@ [objcopy $<]"
@$(CROSS)-objcopy $< -O binary $@
clean:
$(XARGO) clean
rm -rf $(BUILD_DIR)