从makefile中传递shell脚本中的参数并获取结果?

时间:2012-11-05 09:18:00

标签: shell makefile gnu-make

我有一个makefile,从那里我想调用一个shell脚本,它会做一些事情并将结果返回给makefile。

详细说明: -

从我的make文件中,我按如下方式调用shell脚本: -

source = $(PWD)
target = $(ROOT)
SCRIPT:= /home/........./temp.sh
FUNCTION:=$(shell $(SCRIPT $source $target))`

Shell脚本“temp.sh”: -

source=$1
target=$2

echo There are $# arguments to $0: $*
common_part=$source # for now
result="" # for now

while [[ "${target#$common_part}" == "${target}" ]]; do
    common_part="$(dirname $common_part)"

    if [[ -z $result ]]; then
        result=".."
    else
        result="../$result"
    fi
done

if [[ $common_part == "/" ]]; then
    result="$result/"
fi

forward_part="${target#$common_part}"

if [[ -n $result ]] && [[ -n $forward_part ]]; then
    result="$result$forward_part"
elif [[ -n $forward_part ]]; then
    result="${forward_part:1}"
fi

echo "Result=$result"
  • 我没有看到Shell-Script的“echo语句”,原因可能是什么?
  • 如何将结果返回到makefile?
  • 这是从make-file调用脚本的正确方法吗?

我是这个领域的新手。

1 个答案:

答案 0 :(得分:2)

您的调用语法错误;你想要

FUNCTION:=$(shell $(SCRIPT) $(source) $(target))

插值的Makefile变量需要在其名称周围加上括号,除非它们是单字母。