我有以下格式的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_local
和upload_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。
我真的建议您参加有关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_1
和SOME_ENV_VAR_2
是shell变量,这就是为什么我将它们写为$$SOME_ENV_VAR_1
和$$SOME_ENV_VAR_2
。如果它们是Makefile的变量,则将它们恢复到原来的状态。
还请记住,Makefile中的配方会生成一个子外壳,并且您需要确保您的环境变量可用于这些子外壳。