From 27e11dd6c7b566194957e6c8e0023b6c03b12b87 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 14 Mar 2022 20:27:46 +0100 Subject: [PATCH] improve makefile --- Makefile | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0986317..d2c8aaf 100644 --- a/Makefile +++ b/Makefile @@ -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