-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.gcc
78 lines (58 loc) · 2.02 KB
/
Makefile.gcc
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
RPI_VERSION ?= 4
BOOTMNT ?= /mnt/dist
ARMGNU ?= aarch64-linux-gnu
COPS = -DRPI_VERSION=$(RPI_VERSION) -Wall -nostdlib -ffreestanding \
-Iinclude -mgeneral-regs-only -MMD
ASMOPS = -Iinclude
BUILD_DIR = build
SRC_DIR = src
DIST_DIR = dist
all : kernel8.img armstub
clean :
rm -rf $(BUILD_DIR) armstub/$(BUILD_DIR) *.elf *.o *.img > /dev/null 2> /dev/null || true
clean-all: clean
rm -rf $(DIST_DIR)
deploy:
@echo "Deploy to $(value BOOTMNT)"
@echo ""
cp $(DIST_DIR)/* $(BOOTMNT)/
sync
eject :
diskutil unmount /Volumes/boot
servedocs :
python -m http.server --directory docs &
$(BUILD_DIR)/%_c.o: $(SRC_DIR)/%.c
mkdir -p $(@D)
$(ARMGNU)-gcc $(COPS) -c $< -o $@
$(BUILD_DIR)/%_s.o: $(SRC_DIR)/%.S
mkdir -p $(@D)
$(ARMGNU)-gcc $(COPS) -c $< -o $@
armstub/$(BUILD_DIR)/%_s.o: armstub/$(SRC_DIR)/%.S
mkdir -p $(@D)
$(ARMGNU)-gcc $(COPS) -c $< -o $@
C_FILES = $(wildcard $(SRC_DIR)/*.c)
ASM_FILES = $(wildcard $(SRC_DIR)/*.S)
OBJ_FILES = $(C_FILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%_c.o)
OBJ_FILES += $(ASM_FILES:$(SRC_DIR)/%.S=$(BUILD_DIR)/%_s.o)
DEP_FILES = $(OBJ_FILES:%.o=%.d)
-include $(DEP_FILES)
kernel8.img: $(SRC_DIR)/linker.ld $(OBJ_FILES)
mkdir -p $(DIST_DIR)
@echo "Building for RPI $(value RPI_VERSION)"
@echo ""
$(ARMGNU)-ld -T $(SRC_DIR)/linker.ld -o $(BUILD_DIR)/kernel8.elf $(OBJ_FILES)
ifeq ($(RPI_VERSION), 4)
$(ARMGNU)-objcopy $(BUILD_DIR)/kernel8.elf -O binary $(DIST_DIR)/kernel8-rpi4.img
else
$(ARMGNU)-objcopy $(BUILD_DIR)/kernel8.elf -O binary $(DIST_DIR)/kernel8.img
endif
cp config.txt $(DIST_DIR)/
ARMSTUB_FILES = $(wildcard armstub/$(SRC_DIR)/*.S)
ARMSTUB_OBJ_FILES = $(ARMSTUB_FILES:armstub/$(SRC_DIR)/%.S=armstub/$(BUILD_DIR)/%_s.o)
ARMSTUB_DEP_FILES = $(ARMSTUB_OBJ_FILES:%.o=%.d)
-include $(ARMSTUB_DEP_FILES)
armstub: $(ARMSTUB_OBJ_FILES)
mkdir -p $(DIST_DIR)
$(ARMGNU)-ld --section-start=.text=0 -o armstub/$(BUILD_DIR)/armstub.elf $(ARMSTUB_OBJ_FILES)
$(ARMGNU)-objcopy armstub/$(BUILD_DIR)/armstub.elf -O binary $(DIST_DIR)/armstub-new.bin
.PHONY: all armstub clean clean-all deploy eject servedocs