Makefile学习笔记20|u-boot顶层Makefile06

Makefile学习笔记20|u-boot顶层Makefile06

  希望看到这篇文章的朋友能在评论区留下宝贵的建议来让我们共同成长,谢谢。

  这里是目录

配置规则

  如无必要,勿增实体。下面的分析都将基于 PYTHON_ENABLE=n 进行!!!

# This is y if U-Boot should not build any Python tools or libraries. Typically
# you would need to set this if those tools/libraries (typically binman and
# pylibfdt) cannot be built by your environment and are provided separately.
ifeq ($(NO_PYTHON),)
PYTHON_ENABLE=y
endif

# ===========================================================================
# Rules shared between *config targets and build targets

# Basic helpers built in scripts/
PHONY += scripts_basic
scripts_basic:
	$(Q)$(MAKE) $(build)=scripts/basic
	$(Q)rm -f .tmp_quiet_recordmcount

# To avoid any implicit rule to kick in, define an empty command.
scripts/basic/%: scripts_basic ;

PHONY += outputmakefile
# outputmakefile generates a Makefile in the output directory, if using a
# separate output directory. This allows convenient use of make in the
# output directory.
outputmakefile:
ifneq ($(KBUILD_SRC),)
	$(Q)ln -fsn $(srctree) source
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
endif
  1. scripts_basic:

这是一个 Makefile 规则,用于构建 scripts/basic 目录下的辅助工具。 ( Q ) 可能是一个隐藏命令输出的变量, (Q) 可能是一个隐藏命令输出的变量, (Q)可能是一个隐藏命令输出的变量,(MAKE) 是 make 的递归调用,$(build) 传递给这个递归 make 的参数。
该规则还包含一个删除文件 .tmp_quiet_recordmcount 的命令,该文件可能是之前构建步骤中生成的。

  1. To avoid any implicit rule...:

这条注释下面的规则定义了一个空命令,用来预防任何隐式规则生效。通常当定义了模式规则而且不想要任何默认的规则生效时会这么做。

  1. outputmakefile:

这个规则负责生成一个 Makefile 到输出目录,在使用单独的输出目录时,这样做可以方便在输出目录使用 make 命令。
如果设置了 KBUILD_SRC,表示我们在不同于源目录的地方进行构建,它会创建一个到源码树的软链接 source,然后调用 scripts/mkmakefile 脚本生成 Makefile。

  这些规则和变量定义是构建系统的一部分,确保 Makefile 能够适应不同的构建环境和工具链配置,同时保持构建过程的灵活性和可维护性。

多目标处理

# To make sure we do not include .config for any of the *config targets
# catch them early, and hand them over to scripts/kconfig/Makefile
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'.
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).

version_h := include/generated/version_autogenerated.h
timestamp_h := include/generated/timestamp_autogenerated.h
defaultenv_h := include/generated/defaultenv_autogenerated.h
dt_h := include/generated/dt.h
env_h := include/generated/environment.h

no-dot-config-targets := clean clobber mrproper distclean \
			 help %docs check% coccicheck \
			 ubootversion backup tests check pcheck qcheck tcheck \
			 pylint pylint_err _pip pip pip_test pip_release

config-targets := 0
mixed-targets  := 0
dot-config     := 1

ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
		dot-config := 0
	endif
endif

ifeq ($(KBUILD_EXTMOD),)
        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
                config-targets := 1
                ifneq ($(words $(MAKECMDGOALS)),1)
                        mixed-targets := 1
                endif
        endif
endif

  定义一些文件变量:version_h 和其他变量被设置成生成文件的路径,这些文件在构建过程中会由相应的脚本创建。我们输入的命令是 make TQM823L_defconfig,那么 config-targets = 1,mixed-targets = 0,dot-config = 1。

*config 处理

  这些规则专门用于处理如 menuconfig, defconfig 和其他类似的配置界面,这些界面提供了一个用户友好的接口来修改内核的 .config 文件。

# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
# in scripts/kconfig to make the *config target

KBUILD_DEFCONFIG := sandbox_defconfig
export KBUILD_DEFCONFIG KBUILD_KCONFIG

config: scripts_basic outputmakefile FORCE
	$(Q)$(MAKE) $(build)=scripts/kconfig $@

%config: scripts_basic outputmakefile FORCE
	$(Q)$(MAKE) $(build)=scripts/kconfig $@
  1. KBUILD_DEFCONFIG:

KBUILD_DEFCONFIG 变量设置了默认的配置文件名称。如果没有通过命令行给出特定的配置(例如,make x86_defconfig),则会使用此默认配置。
在这里,它默认设置为 sandbox_defconfig。我们这里应该是 TQM823L_defconfig。

  1. config 目标:

config 目标用于运行单一的 config 配置目标,它有三个先决条件:scripts_basic, outputmakefile, 和 FORCE。
scripts_basic 是一个 PHONY 规则,它确保在 scripts/basic 目录下的脚本被构建。
outputmakefile 生成输出(构建)目录中的 Makefile,这允许在输出目录中直接使用 make 命令。
FORCE 是一个总是会执行的 phony 目标,确保这个规则总是运行。

  1. %config 目标:

这是一个模式规则,%config 匹配所有以 config 结尾的目标(比如 menuconfig, oldconfig, 等)。
像 config 一样,它依赖于 scripts_basic, outputmakefile, 和 FORCE 目标。

  1. (𝑄) (MAKE) (𝑏𝑢𝑖𝑙𝑑)=𝑠𝑐𝑟𝑖𝑝𝑡𝑠/𝑘𝑐𝑜𝑛𝑓𝑖𝑔 $@

这行是用于执行实际的配置规则。 ( Q ) 是用于控制 m a k e 输出的变量, (Q) 是用于控制 make 输出的变量, (Q)是用于控制make输出的变量,(MAKE) 代表 make 工具的调用。
$(build)=scripts/kconfig 是一种传递给 make 的参数,指示 make 运行 scripts/kconfig 目录下的 Makefile 。
$@ 是 Makefile 的自动变量,代表当前目标的名称。

结尾

  没想到Makefile接下来一个 ifeq ($(config-targets),1) 就就到结尾了。。。

PHONY += FORCE
FORCE:

# Declare the contents of the PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
  1. PHONY += FORCE

这行代码将 FORCE 目标添加到 .PHONY 特殊变量 PHONY 中。.PHONY 列表包含了不代表文件的目标;无论文件是否存在,这些目标总是会被执行。这个做法用于确保对应的规则不受文件存在与否的影响。

  1. FORCE:

这里定义了一个标签为 FORCE 的规则。由于它没有命令序列,这个规则是空的。在 Makefile 中,空规则用于作为依赖,以确保直接或间接依赖于该规则的目标每次都会被执行,即使它们没有文件修改也是如此。

  1. .PHONY: $(PHONY)

.PHONY 是一个特殊的内置目标,用于告诉 Make 哪些目标是“phony”(伪目标),即不与文件相关联的目标。
本行将 PHONY 变量中定义的所有目标声明为 phony 目标。该变量被视为 Makefile 的一个集中方式来声明这些 phony 目标,以确保不论是否存在与目标同名的文件,目标都会被执行。
这最常用于 all, clean, distclean 等,以及在我们的例子中的 FORCE。

  都看到这里了,可以给个点赞或者评论吗?达瓦里希( ̄^ ̄)ゞ

  • 27
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值