代码之家  ›  专栏  ›  技术社区  ›  tulamba

当目标嵌入到包含的生成文件中时,找不到Target命令

  •  1
  • tulamba  · 技术社区  · 8 年前

    我试图在一个Makefile上运行GNU Make,比如Makefile1,它包含另一个Makefile2。下面是Makefile1的外观

    include absolute_path to Makefile2
    
    
    target_from_Makefile2: Dependencies
                  run_target_from_Makefile2
    

    下面是Makefile2的样子

    run_target_from_Makefile2: Dependencies
         run_xyz
    

    这是我看到的错误

    make: run_target_from_Makefile2: Command not found
    Makefile1:5: recipe for target 'run_target_from_Makefile2' failed
    make: *** [target_from_Makefile2] Error 127
    
    2 回复  |  直到 8 年前
        1
  •  3
  •   sthames42    8 年前

    生成文件的格式为

    targetFile: dependency1 dependency2 ...
            run_command_to_build_targetFile
    
    dependency1:
            run_command_to_build_dependency1
    
    dependency2:
            run_command_to_build_dependency2
    

    将makefile 1更改为:

    include absolute_path to Makefile2
    
    
    target_from_Makefile2: Dependencies run_target_from_Makefile2
    

    您应该停止获取错误,但构建过程有点不清楚。如果需要更多帮助,请发布一些更明确的代码。

        2
  •  3
  •   MadScientist    8 年前

    制作配方是一个shell脚本。调用一个shell,并将配方的文本交给shell运行。makefile中目标的名称不是shell脚本命令,因此不能将其用作shell命令来运行。

    您可以将另一个目标声明为先决条件:

    target_from_Makefile2: Dependencies run_target_from_Makefile2
    

    因此,makefile2中的目标是一个先决条件,或者您可以像这样使用递归make(但在这种情况下,没有必要包括makefile2):

    target_from_Makefile2: Dependencies
              $(MAKE) -f path_to_makefile2 run_target_from_Makefile2