【问题标题】:Run partially build of Makefile运行 Makefile 的部分构建
【发布时间】:2018-08-01 13:28:32
【问题描述】:

我有下面的makefile,看起来像下面

PROJ_DIR := $(CURDIR)
all: pre app app1 app2 app3
apps = app app1 app2 app3 
pre:
  mkdir temp
app:
    cd PROJ_DIR/app ; npm install

app1:
    cd PROJ_DIR/app1 ; npm install
...
#Need to wait to app1...n to finish the install process in order to proceed and zip all the app installed artifacts
build:$(apps)
     #zip all the apps artifacts

clean:build
    rm -rf test

现在,当我使用 make 运行它时,一切都按预期运行。 问题是我想像这样运行部分构建

make -j1 pre app1 build clean(在序列中只有 app1 应该运行而不是 app2 app3 等)这里我有一个问题,因为我有 apps 预请求(来自 Renaud 的提示)这有助于等待我使用make 执行整个make,但如果我想部分运行它,它仍然会运行它们(所有应用程序),是否有一个技巧可以帮助执行类型?

【问题讨论】:

  • build 依赖于$(apps),后者扩展为app app1 app2 app3。如果build 可以在没有这些目标的情况下完成工作,那么为什么它们是依赖项?你可以删除它们。相反,如果build 确实需要先构建这些目标,您希望它如何工作?
  • @Thomas - build 需要这个,如果所有应用程序执行都没有完成,它就无法启动,所以我问这里是否有一些技巧
  • 我现在只是在猜测您要完成的工作,但也许 order-only prerequisites 是您所需要的。比如:build: | $(apps).
  • @Thomas - 谢谢,我已经用命令make -j1 pre app1 build clean 尝试过(在应用程序前添加|)但我仍然看到app 正在运行,即使我输入了命令@ 987654339@
  • @Thomas - 也许我可以用条件声明apps = app app1 app2 app3?还要别的吗 ?如果我删除必要的 $(apps) 它适用于部分构建

标签: linux shell makefile gnu-make


【解决方案1】:

不确定我是否了解所有细节,但有一件重要的事情需要考虑:make 完全按照您的指示去做,不多也不少(希望如此)。所以,如果你告诉它 build 取决于你所有的应用程序,你不能指望 make 在它也做所有应用程序之前做 build。就是这么简单。就是这样

build: $(apps)

说:build 依赖于$(apps),或者换句话说,在完成$(apps) 之前不可能执行build

如果您只想构建一个应用程序,则需要除build之外的另一个目标...或者您需要更改apps make 变量的定义。猜猜看,这可能是最简单的事情,因为 make 让你在命令行上执行此操作:

$ make apps='app1' pre build clean

或者,如果您只想构建和打包 app1app2

$ make apps='app1 app2' pre build clean

默认情况下,在命令行上分配的变量优先于 Makefile 中的定义。执行make apps='app1' pre build clean 与编辑Makefile 以更改apps 的定义然后执行make pre build clean 完全相同。

【讨论】:

  • 哦,你真是个天才,这正是我需要的,让我检查一下
  • @RaynD:如果您的 Makefile 编写正确,所有依赖项都正确表达,不,您不需要 -j1。否则,您的 Makefile 就是我们所说的 not parallel safe,您必须使用 -j1。但是如果不查看完整的 Makefile,我们无法判断它是否是并行安全的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-01
  • 2017-12-30
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 2019-03-21
  • 2023-03-07
相关资源
最近更新 更多