3

我想为我的新树莓派开发一个小内核并使用本课程:http ://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ 来理解它。好吧,当我从这个站点下载一个包含多个源文件的示例时,它会正确编译第一个文件,然后告诉我以下内容:make *** no rule to build target 'build/', required by 'build/gpio.o' 。停止。

让我解释。有一个文件夹 source 包含所有源文件。在 makefile 中,这些文件被编译为 build 文件夹中的 .o 文件,但是 build 文件夹在编译汇编文件时也被设置为依赖项。因此,当编译第一个文件并创建构建文件夹时,文件夹时间戳已过时,第二个编译文件不能将此目录用作依赖项。这是要解决的问题,但我不知道如何解决。

这是生成文件:

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)
4

1 回答 1

1

你想要做的是只做$(BUILD)一个订单的先决条件

$(BUILD)%.o: $(SOURCE)%.s | $(BUILD)
于 2013-09-05T17:17:56.007 回答