简体   繁体   English

按顺序使用命令运行makefile

[英]Run makefile with command in order

I've the following Makefile which run all the target when you enter make in the CLI, I know that you can run the make with specific target but is there a way to run the make with sevral of targets ? 当您在CLI中输入make时,我有以下运行所有​​目标的Makefile,我知道您可以使用特定的目标运行make,但是有没有一种方法可以通过目标的几个运行make?

for example via the cli run module1 pack cleanup 例如通过cli run module1 pack cleanup

with this order 用这个命令

  1. module1 模块1
  2. pack
  3. cleanup 清理

(for this just module2 will not run) and I dont want to create new target for the 3 steps above This is the make for example (为此,module2将不会运行),并且我不想为上述3个步骤创建新目标。

all: module1 module2

.PHONY: module1
module1:
    @echo "run module 1"
    DIR=$(PWD)
    @echo $(DIR)

.PHONY: module2
module2:
    @echo "run module2”

pack:
    pack $(DIR)

cleanup: 
    gbt clean $(DIR)

You can use MAKECMDGOALS for this. 您可以为此使用MAKECMDGOALS Something like: 就像是:

PACK := $(filter pack,$(MAKECMDGOALS))
CLEANUP := $(filter cleanup,$(MAKECMDGOALS))

module1: $(PACK) $(CLEANUP)
        ...

module2: $(PACK) $(CLEANUP)
        ...

pack:
        pack $(DIR)
cleanup:
        git clean $(DIR)

If you don't give the pack or cleanup targets on the command line then the associated variable PACK and CLEANUP will be the empty string and won't be listed as a prerequisite of module1 or module2 etc. 如果您未在命令行中指定packcleanup目标,则关联的变量PACKCLEANUP将为空字符串,并且不会被列为module1module2等的先决条件。

You do not want to run them "in order". 您不想“按顺序”运行它们。 The entire purpose of make is for it to decide what to do and in what order. make的全部目的是决定要做什么和以什么顺序进行。 A Makefile is for listing the rules and dependencies so make can work properly. Makefile用于列出规则和依赖性,因此make可以正常工作。

If you want command run in order, write a script. 如果要命令按顺序运行,请编写脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM