forked from GrassLab/osc2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
35 lines (27 loc) · 810 Bytes
/
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
CC := aarch64-linux-gnu-gcc
LD := aarch64-linux-gnu-ld
OBJCOPY := aarch64-linux-gnu-objcopy
CCFLAGS := -MMD -g -Iinclude -fno-stack-protector -ffreestanding -nostdinc -nostdlib -DKERNEL
TARGET_NAME := kernel8
TARGET := $(TARGET_NAME).img
SRC := $(wildcard src/*.c)
ASRC := $(wildcard src/*.S)
OBJ = $(patsubst %.c, build/%.o, $(notdir $(SRC)))
OBJ += $(patsubst %.S, build/%.o, $(notdir $(ASRC)))
all: build $(TARGET)
$(TARGET): $(OBJ)
@# link object files to elf file
$(LD) -T linker.ld -o $(TARGET_NAME).elf $^
@# conver elf file to a raw binary image
$(OBJCOPY) -O binary $(TARGET_NAME).elf $(TARGET)
build/%.o: src/%.c
$(CC) $(CCFLAGS) -c $< -o $@
build/%.o: src/%.s
$(CC) $(CCFLAGS) -c $< -o $@
build:
mkdir -p build
clean:
rm -f $(TARGET)
rm -f *.elf
rm -rf build
-include $(OBJ:.o=.d)