linux - 运行部分构建的 Makefile

标签 linux shell makefile gnu-make

我有下面的 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 pre-requestie(来自 Renaud 的提示),当我用 make 执行整个 make 时,它​​有助于等待,但如果我想部分运行它它仍然运行它们所有(所有应用程序),是否有一个技巧可以帮助执行类型?

最佳答案

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

build: $(apps)

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

如果您只想使用一个应用程序进行构建,则需要除 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 完全相同干净

关于linux - 运行部分构建的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51634573/

相关文章:

android - 简化构建多个可执行文件的 Android.mk 文件

linux - 如何找到在给定时刻运行的 linux 操作系统的进程?

bash - 从 grep 中获取空白字符到数组中

python - 如何在 WIndows 10 中打开 Python IDLE (Shell WIndow)?

执行shell管道和重定向的C程序

c++ - g++即使指定了标题也找不到标题

Linux:程序的 CPU 和内存使用情况

linux - 除了 procmail 之外,还有哪些 Unix 工具可以通过管道发送 "read"电子邮件?

Java grph 库 : Exception on toools. os.OperatingSystem.getLocalOS()

linux - Makefile 不生成目标代码或可执行文件