如何在Makefile中具有多个(非文件)依赖项

问题描述 投票:1回答:1

我有以下格式的Makefile:

upload_image_local: build_image_local ; echo "This gets printed" ; upload_image

with

build_image_local: echo "This is build_image_local"
    ./my_shell_script_1.sh $(SOME_ENV_VAR_1)

upload_image: echo "This is upload_image"
    ./my_shell_script_2.sh $(SOME_ENV_VAR_2)

您可以知道,当我运行make upload_image_local时,我希望运行build_image_localupload_image。相反,我得到:

/bin/sh: upload_image: command not found

我知道文件相关性,我们在它们之间放置空格,但是在这里我不确定如何正确地分隔两个语句。我也尝试用分号和制表符将它们放在下一行(我知道这很重要):

upload_image_local:
    build_image_local ; echo "This gets printed" ; upload_image

在这种情况下,我得到:

/bin/sh: build_image_local: command not found
make: *** [upload_image_local] Error 127

运行此目标的正确方法是什么?另外,为什么echo命令无法正常打印?如果有问题,我将在Mac上并使用sh shell(如其所说)运行此Makefile。

bash macos makefile sh gnu-make
1个回答
0
投票

我真的建议您参加有关Make的教程。

为了达到预期的效果,我认为以下应该起作用:

all: upload_image

build_image_local:
    echo "This is build_image_local"
    ./my_shell_script_1.sh  $$SOME_ENV_VAR_1

upload_image_local: build_image_local
    echo "This gets printed"

upload_image: upload_image_local
    echo "This is upload_image"
    ./my_shell_script_2.sh $$SOME_ENV_VAR_2

[另外,我假设SOME_ENV_VAR_1SOME_ENV_VAR_2是shell变量,这就是为什么我将它们写为$$SOME_ENV_VAR_1$$SOME_ENV_VAR_2。如果它们是Makefile的变量,则将它们恢复到原来的状态。

还请记住,Makefile中的配方会生成一个子外壳,并且您需要确保您的环境变量可用于这些子外壳。

© www.soinside.com 2019 - 2024. All rights reserved.