在“alsa.mk”上运行 make 会导致 make 读取目录树中的每个文件

问题描述 投票:0回答:1

我对 Windows 环境中的 C/C++/C# 相当有经验,但对 Linux 和 makefile 完全是菜鸟。我想为 XCSoar 开发项目 (https://github.com/XCSoar) 做出贡献,因此我正在通过一个复杂的 makefile 项目进行工作,其中为每个项目定义了“辅助”(*.mk) 文件模块(.cpp)文件。辅助 make 文件“包含”在主 makefile(“Makefile”)的开头。我使用 vscode 查看一些辅助 .mk 文件,并决定尝试在随机 (home/XCSoar/build/alsa.mk) 辅助 .mk 文件上以调试 (-d) 模式运行“make”

这是文件:

ifeq ($(TARGET),ANDROID)
# Using ALSA directly makes no sense on Android
ENABLE_ALSA = n
else ifeq ($(ENABLE_SDL),y)
# If SDL is being used, we do not use ALSA directly
# unless it is explicitly activated
ENABLE_ALSA ?= n
else ifeq ($(TARGET_IS_LINUX),y)
# Enable ALSA for Linux by default
ENABLE_ALSA ?= y
else
# ALSA must be activated explicitly on all other platforms
ENABLE_ALSA ?= n
endif

ifeq ($(ENABLE_ALSA),y)

$(eval $(call pkg-config-library,ALSA,alsa))
ALSA_CPPFLAGS += -DENABLE_ALSA

endif

frank@M6700:~/7.42_tst/XCSoar$ make -d alsa.mk | less

这就是我得到的:

GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Reading makefile 'build/local-config.mk' (search path) (don't care) (no ~ expansion)...
Reading makefile 'build/make.mk' (search path) (no ~ expansion)...
Reading makefile 'build/thunk.mk' (search path) (no ~ expansion)...
Reading makefile 'build/bool.mk' (search path) (no ~ expansion)...
Reading makefile 'build/string.mk' (search path) (no ~ expansion)...
Reading makefile 'build/dirs.mk' (search path) (no ~ expansion)...
Reading makefile 'build/verbose.mk' (search path) (no ~ expansion)...
Reading makefile 'build/util.mk' (search path) (no ~ expansion)...

。 。 .

Reading makefile 'output/UNIX/dbg/src/Computer/Events.d' (search path) (no ~ 

expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/FlyingComputer.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideComputerAirData.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideComputerBlackboard.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideComputer.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideComputerInterface.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideRatioCalculator.d' (search path) (no ~ expansion)...
Reading makefile 'output/UNIX/dbg/src/Computer/GlideRatioComputer.d' (search path) (no ~ expansion)...

...

Considering target file 'build/make.mk'.
  Looking for an implicit rule for 'build/make.mk'.
  No implicit rule found for 'build/make.mk'.
  Finished prerequisites of target file 'build/make.mk'.
 No need to remake target 'build/make.mk'.
 Pruning file 'build/local-config.mk'.
 Considering target file 'Makefile'.
  Looking for an implicit rule for 'Makefile'.
  No implicit rule found for 'Makefile'.
  Finished prerequisites of target file 'Makefile'.
 No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'alsa.mk'.
 File 'alsa.mk' does not exist.
 Looking for an implicit rule for 'alsa.mk'.
 No implicit rule found for 'alsa.mk'.
 Finished prerequisites of target file 'alsa.mk'.
Must remake target 'alsa.mk'.

AFAICT,整个 home/build 目录树中的每个文件都考虑了“make” - 这是正常的吗?

TIA,

弗兰克

makefile debian
1个回答
0
投票

AFAICT,整个 home/build 目录树中的每个文件都考虑了“make” - 这是正常的吗?

TL;DR: 这似乎不是

make
正在做的事情,但是,是的,

正在做的事情在这种情况下似乎是正常的。

据我所知(以及我所期望的),
make
正在读取makefile以及直接或间接在其中的所有文件
include。我认为没有理由认为它读取源文件、标头、现有二进制文件、目标文件或本地库、源代码控制文件或文档文件,等等..它确实读取了一堆文件,但是肯定远不及“全部”。它读取大量文件的部分原因是这个特定包的构建系统的设计方式有些不寻常。

但是让我们退后一步。您似乎对

make

有一些严重的误解:

  1. “在‘alsa.mk’上运行 make”的想法表面上没有多大意义。

    make

    不是脚本语言,
    makefile不是脚本make
    规则也不是函数。 Makefile 有点像参考手册。当 
    make
     想要构建特定文件时,它会查阅当前正在使用的 makefile(如果有)来确定如何执行该构建,包括可能需要首先构建或更新哪些其他文件、如何构建 
    它们etc..为了方便起见,make
    确实有一种默认目标的感觉,如果您不另外指定一个,它将尝试构建该默认目标,但大多数makefile都会告知
    make
    如何构建多个不同的目标的东西,通常并不是所有的东西都被考虑在任何特定的
    make
    运行期间构建。

  2. Make 的

    include

     效果相当于文本插值,很像 C 预处理器的 
    #include
    。因此,
    旨在通过包含在更高级别的 makefile 中使用的 makefile 片段通常不是独立的。事实上,即使是分层(递归)make
     构建系统中的一些成熟的 makefile 也不能完全独立。您提供的特定文件非常符合这一脉络:它根本不提供任何构建规则——它只是设置一些变量,这些变量将在其他地方定义的一个或多个构建规则中使用。

  3. 您发出的特定命令,

    make -d alsa.mk

    ”,并不指示 
    make
     使用 
    alsa.mk
     来构建某些东西
    。相反,它指示
    make
     确保文件 
    alsa.mk
     本身是最新的,使用默认的 makefile 进行说明。这就是为什么 
    make
     读取默认的 makefile 以及直接或间接 
    include
     到其中的所有文件。

    如果您想要求

    make

     使用您指定的 makefile 而不是其默认值之一,那么 
    make
    -f
     选项即可达到此目的。例如,
    make -d -f alsa.mk
    。但同样,该特定文件不是独立的 makefile。我想你会对这个命令的结果感到失望。

如果您想学习如何创建基于

make

 的构建系统,那就太好了!但我强烈建议您从更简单的事情开始。 
make
已经存在很长时间了,并且有各种很好的教程。如果您是阅读手册的类型(我就是),那么您甚至可以考虑阅读 
GNU make
 手册
的前几章。这个版本的
make
 确实提供了相当数量的超出 
make
 POSIX 规范的扩展,因此您可能需要对可移植性问题保持一定的认识,但据我估计,现在它很容易成为最受欢迎和最广泛的 
make
,这让这些问题变得有点苍白。

但是,如果您只是想为使用基于

make

 的构建系统的项目做出贡献,那么您可能并不真正需要任何这些,至少一开始不需要。对于一个成熟的项目,您可以做很多事情,而不需要您修改其构建系统。

© www.soinside.com 2019 - 2024. All rights reserved.