LdB-ECM / Raspberry-Pi

My public Baremetal Raspberry Pi code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please help with a makefile that puts src in its own dir

xlar54 opened this issue · comments

Hi, I am using your code as a base for mine, but the problem is that I cant seem to put .s and .c in a src folder. Id like to have:

project
---src
---obj
---target

Here's the makefile. It builds, but complains about not being able to find _start

`TOOL = arm-none-eabi
CFLAGS = -nostdlib -nodefaultlibs -nostartfiles -ffreestanding -fno-asynchronous-unwind-tables -fomit-frame-pointer -Wall -O3 -march=armv8-a -mfpu=neon-vfpv4 -mfloat-abi=hard -mtune=cortex-a53 -mno-unaligned-access -fno-tree-loop-vectorize -fno-tree-slp-vectorize -Wno-nonnull-compare -lc -lm -lgcc
LINKER_FLAGS = --no-wchar-size-warning --no-undefined -gc-sections --build-id=none -Bdynamic

BUILD_DIR = obj
SOURCE_DIR = src
TARGET_DIR = target

CSOURCE := $(wildcard $(SOURCE_DIR)/.c)
ASOURCE := $(wildcard $(SOURCE_DIR)/
.s)

_COBJECT := $(patsubst %.c,%.o, $(CSOURCE))
_AOBJECT := $(patsubst %.s,%.o, $(ASOURCE))
AOBJECT = $(addprefix $(BUILD_DIR)/, $(notdir $(_AOBJECT)))
COBJECT = $(addprefix $(BUILD_DIR)/, $(notdir $(_COBJECT)))

all: kernel

Create the final binary

kernel: theelf
$(TOOL)-objcopy $(BUILD_DIR)/kernel.elf -O binary $(TARGET_DIR)/kernel8-32.img

Link all of the objects

theelf: $(AOBJECT) $(COBJECT)
$(TOOL)-ld $(LINKER_FLAGS) $(AOBJECT) $(COBJECT) -L. -Map $(BUILD_DIR)/kernel.map -T link32.ld -o $(BUILD_DIR)/kernel.elf

#build c files
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c
$(TOOL)-gcc -c $< -o $@ $(CFLAGS)

#build s files (Assembly)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.s
$(TOOL)-as $< -o $@

clean:
rm $(BUILD_DIR)/.o
rm $(BUILD_DIR)/
.map
rm $(BUILD_DIR)/.elf
rm $(TARGET_DIR)/
.img
`

Is this what you are trying to do it will just echo the filenames to screen

https://github.com/LdB-ECM/Exchange/blob/master/Makefile