Cool Goose
Cool Goose

Reputation: 998

Variable name in string doesn't evaluate

I am writing a makefile. In my use case name of variable is stored in another variable. I am trying to evaluate it from function but it is not evaluating correctly.

In the code I want "devinit" to evaluate to UART_init. What is mistake in my code?

VAR=MYDEV
MYDEV_init=UART_init


define create_kernels_c
    echo GGGGG $(VAR)
    baseinit=$$(echo $(VAR)_init);
    $$(eval devinit=\$$baseinit);
    echo devinit $$devinit;
endef


all:
    @$(call create_kernels_c)

Upvotes: 0

Views: 161

Answers (1)

Matt
Matt

Reputation: 15081

Use variable substitution twice and do not forget about .ONESHELL: (or append ;\<CR> everywhere):

VAR=MYDEV
MYDEV_init=UART_init


define create_kernels_c
    echo GGGGG $(VAR)
    devinit=$($(VAR)_init)
    echo devinit $$devinit
endef


.ONESHELL:
all:
    @$(call create_kernels_c)

Upvotes: 1

Related Questions