嘿伙计我在这里有一点问题。我想为我的新树莓pi开发一个小内核并使用这个课程:http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ 了解它。好吧,当我从这个站点下载一个包含多个源文件的示例时,它会正确编译第一个,然后告诉我以下内容:make * 没有规则构建目标'build /','build需要/gpio.o'.Stop。
让我解释一下。有一个包含所有源文件的文件夹源。在makefile中,这些文件被编译为build文件夹中的.o文件,但在编译汇编程序文件时,build文件夹也被设置为依赖项。因此,当第一个文件被编译并且构建文件夹创建时,文件夹时间戳已过时,第二个编译文件不能使用此目录作为依赖....这是要解决的问题,但我不知道如何....
这是makefile:)
ARMGNU ?= arm-none-eabi
# The intermediate directory for compiled object files.
BUILD = build/
# The directory in which source files are stored.
SOURCE = source/
# The name of the output file to generate.
TARGET = kernel.img
# The name of the assembler listing file to generate.
LIST = kernel.list
# The name of the map file to generate.
MAP = kernel.map
# The name of the linker script to use.
LINKER = kernel.ld
# The names of all object files that must be generated. Deduced from the
# assembly code files in source.
OBJECTS := $(patsubst $(SOURCE)%.s,$(BUILD)%.o,$(wildcard $(SOURCE)*.s))
# Rule to make everything.
all: $(TARGET) $(LIST)
# Rule to remake everything. Does not include clean.
rebuild: all
# Rule to make the listing file.
$(LIST) : $(BUILD)output.elf
$(ARMGNU)-objdump -d $(BUILD)output.elf > $(LIST)
# Rule to make the image file.
$(TARGET) : $(BUILD)output.elf
$(ARMGNU)-objcopy $(BUILD)output.elf -O binary $(TARGET)
# Rule to make the elf file.
$(BUILD)output.elf : $(OBJECTS) $(LINKER)
$(ARMGNU)-ld --no-undefined $(OBJECTS) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER)
# Rule to make the object files.
$(BUILD)%.o: $(SOURCE)%.s $(BUILD)
$(ARMGNU)-as -I $(SOURCE) $< -o $@
$(BUILD):
mkdir $@
# Rule to clean files.
clean :
-rm -rf $(BUILD)
-rm -f $(TARGET)
-rm -f $(LIST)
-rm -f $(MAP)
PS ::
YEEAAYY我已经得到了它。为此工作了好几天但现在:) 再看一下这个例子的页面:`OBJDIR:= objdir OBJS:= $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)
$(OBJDIR)/%.o : %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
all: $(OBJS)
$(OBJS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)`
我刚从目标中删除了$(BUILD)文件夹依赖项,并写道:
$(OBJECTS): | $(BUILD)
所以现在它在我改变的几行中非常完美:
$(BUILD)%.o: $(SOURCE)%.s
$(ARMGNU)-as -I $(SOURCE) $< -o $@
$(OBJECTS): | $(BUILD)