Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass arguments in shell-script from a makefile and get back the results?

I have a makefile, from where I'd like to call a shell-script, which does something and return back the result to makefile.

Detailed description :-

From my make-file, I call the shell-script as follows :-

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

Shell Script "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"
  • I don't see Shell-Script's "echo statements", what could be the reason of same?
  • How can I get the result back to makefile?
  • Is this the right way to call a script from make-file?

I'm a newbie in this area.

like image 248
user1799483 Avatar asked Nov 21 '25 07:11

user1799483


1 Answers

Your invocation syntax is wrong; you want

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

Interpolated Makefile variables need to have a parenthesis around their name unless they are single-letter.

like image 67
tripleee Avatar answered Nov 22 '25 20:11

tripleee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!