-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.simple
61 lines (44 loc) · 1.27 KB
/
Makefile.simple
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
# Define toolchain
CROSS_COMPILE ?= aarch64-elf-
CC := $(CROSS_COMPILE)gcc
AS := $(CROSS_COMPILE)as
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
SIZE := $(CROSS_COMPILE)size
# Set the architecture-specific flags
ARCH_FLAGS := -march=armv8-a
# Source directories
SRC_DIR := src/ports/simple-arm
# Compiler and linker flags
CFLAGS := $(ARCH_FLAGS) -Wall -Werror -std=c99 -nostdlib -ffreestanding -O0 -mgeneral-regs-only
ASFLAGS := $(ARCH_FLAGS)
LDFLAGS := -nostdlib -T $(SRC_DIR)/linker-simple.ld --gc-sections
# Source files
SRC_C := $(SRC_DIR)/main_simple.c $(SRC_DIR)/system_simple.c
SRC_ASM := $(SRC_DIR)/startup.S
# Build directory
BUILD_DIR := simple-build
# Object files
OBJ_C := $(SRC_C:%.c=$(BUILD_DIR)/%.o)
OBJ_ASM := $(SRC_ASM:%.S=$(BUILD_DIR)/%.o)
OBJ := $(OBJ_C) $(OBJ_ASM)
# Output binary
TARGET := $(BUILD_DIR)/firmware
.PHONY: all clean
all: $(TARGET).bin
# Create build directories
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
@mkdir -p $(dir $(OBJ_C))
@mkdir -p $(dir $(OBJ_ASM))
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: %.S | $(BUILD_DIR)
$(AS) $(ASFLAGS) $< -o $@
$(TARGET).elf: $(OBJ)
$(LD) $(LDFLAGS) -o $@ $^
$(SIZE) $@
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@
clean:
rm -rf $(BUILD_DIR)