improve makefile

This commit is contained in:
Mathieu Maret 2022-03-14 20:27:46 +01:00
parent 787b4617ae
commit 27e11dd6c7

View File

@ -1,4 +1,5 @@
#CROSS=aarch64-none-elf-
# Used to generated .d file that deal with header dependencies
CPPFLAGS = -MMD
CROSS=aarch64-linux-gnu-
CC=$(CROSS)gcc
LD=$(CROSS)ld
@ -6,18 +7,28 @@ CFLAGS=-Wall -Wextra -ffreestanding -march=armv8-a+crc -mcpu=cortex-a53
LDSCRIPT=rpi3.ld
OBJS=crt0.o uart.o hello.o
gasmsrc=$(wildcard *.S)
gasmobj=$(gasmsrc:%.S=%.o)
csrc=$(wildcard *.c)
cobj=$(csrc:%.c=%.o)
deps=$(csrc:%.c=%.d) $(gasmsrc:%.S=%.d)
all:kernel.bin
kernel.elf: $(OBJS) $(LDSCRIPT)
$(LD) -o $@ $(OBJS) -T$(LDSCRIPT) -Map kernel.map
kernel.elf: $(cobj) $(gasmobj) $(LDSCRIPT)
$(LD) $(LDFLAGS) -o $@ $(cobj) $(gasmobj) -T$(LDSCRIPT) -Map kernel.map
kernel.bin: kernel.elf
$(CROSS)objcopy -O binay -B aarch64 $< $@
$(CROSS)objcopy -O binary $< $@
clean:
rm -rf $(OBJS) *.bin *.elf *.map
rm -rf $(cobj) $(gasmobj) $(deps) *.bin *.elf *.map
run: kernel.bin
qemu-system-aarch64 -machine raspi3b -kernel $<
ifneq ($(MAKECMDGOALS),clean)
-include $(deps)
endif