를 작성하는 나는어떻게 일반 규칙 기반 메이크
--Makefile
--source/
--boot.s
--kernel.c
--linker.ld
--build/
과 내가 패턴을 기반으로 규칙을 작성하는 방법을
###############################################################################
#
# A makefile script for generation of raspberry pi kernel images.
#
###############################################################################
# The toolchain to use. arm-none-eabi works, but there does exist
CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
# The intermediate directory for compiled object files.
BUILD = build/
# The directory in which source files are stored.
SOURCE = source/
CFLAGS = -march=armv8-a+crc \
-mcpu=cortex-a53 \
-mtune=cortex-a53 \
-mfpu=crypto-neon-fp-armv8 \
-mfloat-abi=hard \
-ftree-vectorize \
-funsafe-math-optimizations \
-O2 -pipe -ffreestanding
LDFLAGS = -T $(SOURCE)linker.ld -ffreestanding -O2 -nostdlib
# The name of the output file to generate.
TARGET = kernel.img
.PHONY: all clean run
# Rule to make everything.
all: $(TARGET)
# Rule to remake everything. Does not include clean.
rebuild: clean all
#Rule to invoke qemu
run:
qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $(BUILD)kernel.elf
$(TARGET): kernel.elf
arm-none-eabi-objcopy $(BUILD)kernel.elf -O binary $(BUILD)kernel.img
kernel.elf: boot.o kernel.o
$(LD) $(LDFLAGS) -o $(BUILD)kernel.elf $(BUILD)boot.o $(BUILD)kernel.o
boot.o: $(SOURCE)boot.s
$(CC) $(CFLAGS) -c $(SOURCE)boot.s -o $(BUILD)boot.o
kernel.o: $(SOURCE)boot.s
$(CC) $(CFLAGS) -c $(SOURCE)kernel.c -o $(BUILD)kernel.o
# Rule to clean files.
clean :
-rm -f $(BUILD)*
-rm -f *.o
-rm -f *.elf
-rm -f *.img
메이크
다음 사용하여 내 소스를 컴파일 폴더 구조 다음습니까? 많은 스택 오버플로 해답을 시도했지만 제대로 작동하지 못했습니다.처음에 와일드 카드를 사용하여 내 소스를 나열했지만 소스 목록에 [source/boot.s source/kernel.c]가 있었기 때문에 적절한 대상을 쓸 수 없었습니다. 소스 파일 자체에 오브젝트 파일을 생성합니다.
소스를 유지하면서 디렉토리를 다르게 만드는 데 어려움을 겪고있었습니다. 어떤 도움을 주셔서 감사합니다. @MadScientist에 따라
---------- 완벽한 솔루션 -----------
###############################################################################
#
# A makefile script for generation of raspberry pi kernel images.
#
###############################################################################
# The toolchain to use. arm-none-eabi works, but there does exist
CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
# The intermediate directory for compiled object files.
BUILD = build/
# The directory in which source files are stored.
SOURCE = source/
CFLAGS = -march=armv8-a+crc \
-mcpu=cortex-a53 \
-mtune=cortex-a53 \
-mfpu=crypto-neon-fp-armv8 \
-mfloat-abi=hard \
-ftree-vectorize \
-funsafe-math-optimizations \
-O2 -pipe -ffreestanding
LDFLAGS = -T $(SOURCE)linker.ld -ffreestanding -O2 -nostdlib
SOURCES := $(wildcard $(SOURCE)*.s) $(wildcard $(SOURCE)*.c)
OBJECTS := $(patsubst $(SOURCE)%,$(BUILD)%.o,$(basename $(SOURCES)))
# The name of the output file to generate.
TARGET = kernel.img
.PHONY: all clean run
# Rule to make everything.
all: $(BUILD)$(TARGET)
# Rule to remake everything. Does not include clean.
rebuild: clean all
#Rule to invoke qemu
run:
qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $(BUILD)kernel.elf
$(BUILD)%.o : $(SOURCE)%.s
$(CC) $(CFLAGS) -c $< -o [email protected]
$(BUILD)%.o : $(SOURCE)%.c
$(CC) $(CFLAGS) -c $< -o [email protected]
$(BUILD)$(TARGET): $(BUILD)kernel.elf
arm-none-eabi-objcopy $< -O binary [email protected]
$(BUILD)kernel.elf: $(OBJECTS)
$(LD) $(LDFLAGS) -o [email protected] $^
# Rule to clean files.
clean :
-rm -f $(BUILD)*
-rm -f *.o
-rm -f *.elf
-rm -f *.img
당신은 내가 많은 [것을] 시도 "라고하지만, 그것을 일하게 만들지 못했습니다. " 질문을 할 때, 시도한 것을 보여주고, 달린 명령을 보여주고, 결과를 보여주고 (의역을 말하지 않고 잘라내어 붙여 넣기) 결과가 왜 당신이 원하는 것이 아니 었는지 설명하십시오. – MadScientist
오버플로 스택을 새로 도입했습니다. 내 질문을 편집하고 자세한 내용을 추가하겠습니다. – zero