【发布时间】:2020-04-13 17:51:11
【问题描述】:
我有一个 Makefile,我需要在其中将图像名称传递给另一个脚本,但问题是,图像名称在其行中有:和 - 例如:image.name-v1:latest。根据 google make 文件具有 : in 变量会导致问题。如何在 Makefile 中解决此问题。下面是我正在尝试的示例代码,其中 IMAGE 具有 image.name-v1:latest
IMAGE2 ?= ''
.PHONY: image
image:
IMAGE2 := $(subst :,\:,$(IMAGE_R)) ## IMAGE_R is a run time variable for make target
rr/image.sh $(IMAGE2)
错误:
IMAGE2 := docker-rs\:latest ## Test Image using Image Reference
/bin/sh: 1: IMAGE2: not found
Makefile:75: recipe for target 'image' failed
make: *** [image] Error 127
外壳脚本:image.sh
#!/bin/bash
set -ex
IMAGE="$1"
echo "Image: $IMAGE"
【问题讨论】:
-
您收到此特定错误的原因是
IMAGE2 := ...是一个makefile 行,但您通过在image:目标之后使用TAB 缩进它来将其放入配方中。所有配方行都传递给 shell 以运行。 shell 不能“运行”这个 make 变量赋值。您需要将IMAGE2 := ...行保留在配方的外部,就像您对IMAGE2 ?= ''行所做的那样。看看@code_fodder 是如何在下面写的。 -
但这是一个传递给图像目标的变量,那么如何将它传递给其他地方呢?
-
对不起,我不明白这个问题。除了高级用途之外,在 makefile 中声明的所有 make 变量都是全局变量,它们在所有配方中都可用。
-
感谢这个工作,只是把 IMAGE2 的外在制作配方
标签: shell sed makefile gnu-make