-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
executable file
·91 lines (66 loc) · 1.5 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
# Makefile for my bare metal rpi project
MAKEFLAGS := -j 1
# VARIABLES
#==================
# tools
PREFIX?=arm-none-eabi-
FLAGS=-mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s
LINKER=kernel.ld
# directoris
BUILD=build/
SOURCE=source/
TMP=tmp/
# files
OBJECTS := $(patsubst $(SOURCE)%.S,$(TMP)%.o,$(wildcard $(SOURCE)*.S))
ELF=$(TMP)kernel.elf
TARGET=$(BUILD)kernel.img
LIST=kernel.list
MAP=kernel.map
NM=kernel.nm
# TARGETS
#==================
# BUILD
#---------------
# Build everything, and include help files
all: $(TARGET) disassemble
# Build object files
$(TMP)%.o: $(SOURCE)%.s $(TMP)
$(PREFIX)as -I $(SOURCE) $< -o $@
# Assemble the code to and elf file
$(ELF): $(OBJECTS) $(LINKER)
$(PREFIX)ld --no-undefined $(OBJECTS) -Map $(MAP) -o $(ELF) -T $(LINKER)
# Turn the elf into a binary image
$(TARGET): $(ELF)
$(PREFIX)objcopy $(ELF) -O binary $(TARGET)
# DISASSEMBLY
#---------------
# Disassemble the elf
disassemble: $(LIST) $(NM)
# Generate listing file
$(LIST): $(ELF)
$(PREFIX)objdump -D $(ELF) > $(LIST)
# Generate symbol list
$(NM): $(ELF)
$(PREFIX)nm $(ELF) > $(NM)
#---------------
# OTHERS
#===================
# Clean up everything
clean:
rm -f $(LIST) $(MAP) $(TARGET)
rm -rf $(TMP)
$(TMP):
mkdir $@
# rebuild everything
rebuild: clean all
# install image to SD
install:
cp build/kernel.img /run/media/andreas/boot/
auto: all
udisksctl mount -b /dev/mmcblk0p1
make install
udisksctl unmount -b /dev/mmcblk0p1
# aliases:
list: $(LIST)
nm: $(NM)
#---------------