c - 在规则中使用 makefile 文件作为先决条件
问题描述
我对make没有经验,想复制一些第三方SDK提供的构建结构,并将其适应我自己的编译器和项目。
问题是我发现使用makefile作为先决条件生成了一些规则,例如:
...
$(eval $(1): Makefile | $(dir $(1)).) \
...
或者
$(OUTPUT_DIRECTORY)/%.inc: Makefile | $(OUTPUT_DIRECTORY)
$(info Generating $@)
$(NO_ECHO)$(call dump, $(call target_specific, INC_PATHS, $*)) > $@
最初,他们的 makefile 是大写的(Makefile),而我正在处理的是小写(makefile)。无论如何,当我尝试当前的更改时,会出现此错误:
*** No rule to make target 'Makefile', needed by '...'
我认为这是由于大写,所以在两个地方都改为小写并再次尝试,但这次错误是makefile被视为C文件(这是我的猜测......)
"makefile", line 1: error #171: expected a declaration
-include makefile.local
^
"makefile", line 67: error #8: missing closing quote
${CG_TOOL_ROOT}/include"
^
"makefile", line 99: error #10: "#" not expected here
.SUFFIXES: # ignore built-in rules
^
"makefile", line 100: error #10: "#" not expected here
%.d: # don't try to make .d files
^
"makefile", line 100: error #8: missing closing quote
%.d: # don't try to make .d files
这里可能是什么问题?有什么我想念的吗?
编辑 1: 这些是我要使用的文件。
Nordic 将这些作为其 SDK 的一部分提供,用于使用用于 ARM 平台的 arm-gcc 进行开发。Makefile
每个项目都有一个,Makefile.common
并且 main 中包含一个Makefile
。
另一方面,我试图理解和复制相同的内容,但对于另一个具有不同选项和语法的专有编译器(TI 的 cl430 用于 MSP430 平台)。从原始Makefile.common
版本中,我删除了对 gnu-arm 套件的一些引用,并将其替换为适当的编译工具。在中,makefile
我还尝试复制与原版相同的结构,但使用我的来源和选项。
为了清楚起见,原件是大写的,我的是小写的。
编辑2:
运行后make --debug --print-data-base
我发现了这个:
首次尝试构建文件时出现错误:
Updating goal targets....
File 'default' does not exist.
File 'test_project' does not exist.
File '_build/test_project.out' does not exist.
File '_build/test_project/<SOURCE_FILE>.c.o' does not exist.
Must remake target '_build/test_project/<SOURCE_FILE>.c.o'.
Building file: "makefile"
Invoking: MSP430 Compiler
"cl430" -vmspx --use_hw_mpy=F5 <... a lot of options ...> --obj_directory="./_build" "makefile"
"makefile", line 1: error #171: expected a declaration
-include makefile.local
^
[ ... more errors ...]
但是,从调试和数据库信息中,我发现源文件规则确实需要makefile,并且makefile不是目标,而是以某种方式试图构建它:
# Not a target:
makefile:
# Implicit rule search has been done.
# Last modified 2020-02-25 11:43:33.609423171
# File has been updated.
# Successfully updated.
_build/test_project/<SOURCE_FILE>.c.o: makefile | _build/test_project/.
# Implicit rule search has been done.
# Implicit/static pattern stem: '_build/test_project/<SOURCE_FILE>'
# Modification time never checked.
# File has been updated.
# Failed to be updated.
# automatic
# @ := _build/test_project/<SOURCE_FILE>.c.o
# automatic
# % :=
# automatic
# * := _build/test_project/<SOURCE_FILE>
# automatic
# + := makefile
# automatic
# | := _build/test_project/.
# automatic
# < := makefile
# automatic
# ^ := makefile
# automatic
# ? := makefile
# variable set hash-table stats:
# Load=8/32=25%, Rehash=0, Collisions=1/30=3%
# recipe to execute (from 'makefile.common', line 192):
@echo 'Building file: "$<"'
@echo 'Invoking: MSP430 Compiler'
"${CG_TOOL_ROOT}/bin/cl430" -vmspx --use_hw_mpy=F5 <... a lot of options ...> "$(shell echo $<)"
@echo 'Finished building: "$<"'
@echo ' '
解决方案
这种依赖Makefile
是为了确保它Makefile
在更改时重建。例如,如果您更改或编译或链接规则,则此依赖项会触发重建(提供的目标文件依赖于CFLAGS
,因为它们应该)。不依赖这些更改不会导致重建。Makefile
Makefile
Makefile
"makefile", line 1: error #171: expected a declaration
建议形式的错误消息makefile
作为源文件传递给产生错误消息的 C 编译器。
规则最有可能做到$(filter-out Makefile,$^)
。您需要替换所有出现的Makefile
to makefile
。
*** No rule to make target 'Makefile', needed by '...'
意味着这Makefile
仍然是某些目标的先决条件。您可以通过将--debug --print-data-base
命令行选项传递给make
.
推荐阅读
- javascript - 关于消息错误 bot.on('message', async (msg) => { if (msg.author.bot) return; await msg.replay() });
- c - 用户输入字符串后如何检查特定字符?
- c# - 这里使用什么类型的构造函数/方法?
- python - 使用 factory_boy 自定义创建相关子工厂
- php - Composer 不索引类
- sql - 在 Postgres 中执行 SELECT 语句时,如何从 JSONB 字段中获取 JSON 对象列表而不是 ID 列表?
- javascript - 不和谐音乐机器人循环
- google-analytics - 如何在我的网站中使用 API 显示 Google Analytics
- c - 为什么需要使用精确的返回地址来执行 shellcode?
- flutter - dart/flutter BMI 代码返回 bmi 值,但其他值错误