1

I have this Makefile where I'm having some troubles on simply set some variables:

my_stage:   
    echo "FULL_NAME=$(FULL_NAME)"
    echo "MY_NAME=$(MY_NAME)"

    $(eval SOME_NAME=$(shell sh -c "echo ${FULL_NAME} | cut -d"-" -f 2"))
    echo "SOME_NAME=$(SOME_NAME)"

    $(eval NAME_ONLY=$(shell sh -c "echo ${SOME_NAME}-only))
    echo "NAME_ONLY=$(NAME_ONLY)"

    $(eval RIGHT_NAME=$(shell sh -c "echo ${SOME_NAME}-right))

    $(eval NAME_APPENDED=$(shell sh -c "echo ${RIGHT_NAME}.${MY_NAME}))
    echo "NAME_APPENDED=$(NAME_APPENDED)"

The pretended result is:

FULL_NAME=Shop-with-me
MY_NAME=Mariana
SOME_NAME=with
NAME_ONLY=with-only
NAME_APPENDED=with-right.Mariana

However, the current result is:

FULL_NAME=Shop-with-me
MY_NAME=Mariana
SOME_NAME=with
NAME_ONLY=
NAME_APPENDED=

Can someone help me figuring out what is happening? What I'm doing wrong?

I already tried this too (but without success):

my_stage:   
    echo "FULL_NAME=$(FULL_NAME)"
    echo "MY_NAME=$(MY_NAME)"

    $(eval SOME_NAME=$(shell sh -c "echo ${FULL_NAME} | cut -d"-" -f 2"))
    echo "SOME_NAME=$(SOME_NAME)"

    NAME_ONLY = ${SOME_NAME}-only
    echo "NAME_ONLY=$(NAME_ONLY)"

    RIGHT_NAME = ${SOME_NAME}-right

    NAME_APPENDED = ${RIGHT_NAME}.${MY_NAME}
    echo "NAME_APPENDED=$(NAME_APPENDED)"
0

When you use curly braces, like ${FOO}, in your command, you refer to a a shell variable, as defined in the shell invoking make.

When you use parens, like $(fOO), in your command, you refer to the make's variable.

Since you only set make's variables, obviously references to shell variables of the same name would result in empty values.

So $(eval NAME_ONLY=$(shell sh -c "echo $(SOME_NAME)-only)) should work.

Simple $(eval NAME_ONLY = $(SOME_NAME)-only) should work in a rule. You don't need to invoke shell for that.

You can also consider using make's text functions, like subst.

0

perhaps .ONESHELL will do what intended.

since gnu make launches a new process for each recipe line by default, the variable settings are not propagated to the recipe below. .ONESHELL tries to runs all recipes of that target in a single shell invocation

https://www.gnu.org/software/make/manual/make.html#One-Shell .ONESHELL:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.