【问题标题】:Is there a variable to set so that "make" command searches for makefiles是否有要设置的变量,以便“make”命令搜索 makefile
【发布时间】:2016-08-24 05:46:18
【问题描述】:

有没有要设置的变量,让make命令搜索其他目录的makefile,而不是只搜索当前工作目录的makefile?

更新:场景是这样的,在我们的项目中,我们有一个脚本,主要是定义和设置一些环境变量。然后在没有makefile的根文件夹(构建)中给出一个make。因此,我认为“-c”或其他 make 选项对此没有帮助。 经过一番调查,我发现该 makefile 位于内部文件夹中并被调用。所以,我的问题是是否有任何环境变量使“make”命令在指定目录中搜​​索makefile(通过环境变量)。

【问题讨论】:

标签: makefile


【解决方案1】:

简短的回答是否定的,默认情况下,不可能在与启动它的目录不同的目录中搜索 makefile(或由于-C 选项而切换到 GNU make)。

您有两种选择:一种是使用上述-f 选项。

另一种方法是在调用make 之前将MAKEFILES 变量设置为要读取的makefile 列表。请注意,这必须是您要读取的实际文件,而不仅仅是包含它们的目录。这样做的缺点是永远不会从这些 makefile 中获取默认目标:请参阅https://www.gnu.org/software/make/manual/html_node/MAKEFILES-Variable.html,这意味着您需要始终在命令行上指定要构建的目标。

【讨论】:

  • MAKEFILES 是其中之一,脚本将 MAKEFILES 设置为包含我的 makefile 的内部目录结构的位置。
【解决方案2】:

对于根 makefile,您必须指定文件名,使用

make -f mymakefiledir/makefile

对于嵌套的makefile,有make -I MyMakefileDir

$man 制作

-f file, --file=file, --makefile=FILE
                Use file as a makefile.

-I dir, --include-dir=dir
                Specifies  a  directory  dir to search for included makefiles.  If
                several -I options are used to specify  several  directories,  the
                directories are searched in the order specified.  Unlike the argu‐
                ments to other flags of make, directories given with -I flags  may
                come directly after the flag: -Idir is allowed, as well as -I dir.
                This syntax is allowed for compatibility with the C preprocessor's
                -I flag.

【讨论】:

  • 针对我的特定场景更新了问题,其中 make 中的选项可能无济于事。
  • 假设你的环境变量是MyMakefileDir,你可以使用$export MyMakefile = $MyMakefileDir/makefile 定义一个新变量,然后make -f $MyMakefile?
  • 如果您的环境变量包含多个路径,您可以使用 sed 来拆分它们。 for i in `echo $PATH | sed "s/:/ /g"` do MyMakefile = $i/makefile make -f $MyMakefile done
【解决方案3】:

根据 GNU make 的联机帮助页。

If no -f option is present, make will look for the makefiles,GNUmakefile, 
makefile, and Makefile, in that order.

没有环境变量 make 将参考在其他目录中搜索 Makefile。为什么不在根文件夹中创建一个新的 makefile 来调用内部文件夹中的 makefile?

【讨论】:

    猜你喜欢
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2016-12-23
    相关资源
    最近更新 更多