是否有一个变量可以设置为;制造;命令搜索makefile

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

是否有要设置的变量,以便
make
command在其他目录中搜索makefiles,而不是仅在当前工作目录中搜索makefiles

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

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

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

$man make

-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.

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

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

$man make

-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.

根据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?

根据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?

简短的回答是“否”,默认情况下,不可能让makefiles在不同的目录中搜索makefiles(或由于GNU make的
-C
选项而切换到的目录)

您有两个选项:一个是如上所述使用
-f
选项


另一个是将
MAKEFILES
变量设置为在调用
make
之前要读入的makefile列表。注意,这必须是您想要读取的实际文件,而不仅仅是包含它们的目录。这样做的缺点是永远不会从这些makefiles中获取默认目标:查看这意味着您需要始终在命令行上指定要构建的目标。

简短的回答是“否”,不可能在不同的目录中搜索makefiles,而不是在启动makefiles的目录中(或由于GNU make的
-C
选项而切换到)

您有两个选项:一个是如上所述使用
-f
选项


另一种方法是在调用
make
之前,将
MAKEFILES
变量设置为要读入的makefile列表。请注意,这必须是要读入的实际文件,而不仅仅是包含它们的目录。其缺点是,默认目标永远不会从这些makefile中获取:查看这意味着您将需要始终在命令行上指定要生成的目标。

可能重复的@IanAuld Updated my question此问题的答案有用吗?可能重复的@IanAuld Updated my question此问题的答案有用吗?针对我的特定场景更新了问题,make中的选项可能没有帮助。想象一下您的环境变量是MyMakefileDir,您可以使用$export MyMakefile=$MyMakefileDir/makefile定义一个新变量,然后生成-f$MyMakefile吗?如果您的环境变量包含多个路径,您可以使用sed来拆分它们。
对于`echo$PATH | sed“s/://g”中的i`do MyMakefile=$i/makefile make-f$MyMakefile done
更新了我的特定场景的问题,其中make中的选项可能没有帮助。假设您的环境变量是MyMakefileDir,您是否可以使用$export MyMakefile=$MyMakefileDir/makefile定义一个新变量,然后生成-f$MyMakefile?如果您的环境变量包括mul对于'echo$PATH | sed“s/://g”中的i,可以使用sed拆分多个路径`do MyMakefile=$i/makefile make-f$MyMakefile doneMAKEFILES是一个,脚本将MAKEFILES设置为包含我的makefile的内部目录结构的位置。MAKEFILES是一个,脚本将MAKEFILES设置为包含我的makefile的内部目录结构的位置。