makefile - ARM GNU Makefile 文件夹依赖时间戳问题

标签 makefile dependencies directory gnu

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

让我解释一下。有一个包含所有源文件的文件夹 sources。在 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)

附言::

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)

最佳答案

你想要做的是让 $(BUILD) 成为 order-only prerequisite :

$(BUILD)%.o: $(SOURCE)%.s | $(BUILD)

关于makefile - ARM GNU Makefile 文件夹依赖时间戳问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18642017/

相关文章:

java - 从 jar(war/ear) 获取依赖项?

检索区分大小写路径的 Pythonic 方式?

gcc - 这些 Makefile 结构是什么意思?

gcc - 创建一个简单的 Makefile 来构建一个共享库

gradle - 有没有办法从build.gradle中获取依赖项的版本?

c# - Windows 中的文件夹有 ID 吗?或 GUID?

bash - 如何使用 csv 文件将一个文件夹拆分为多个文件夹?

c - 这个makefile有什么作用?

build - 如何构建freebsd内核?

java - 如何管理库冲突? (相同的包,不同的版本)