Why does GNU make's eval convert a list to a scalar?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm trying to to use eval to define a few make variables, but implicitly it seems to convert a list into a scalar. I can't seem to figure out how to avoid this behavior. Here's my current Makefile:
foo_man_srcs := a.c b.c
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
$(eval $(call GEN_OBJS,foo))
all:
echo "foo_gen_objs: $(foo_gen_objs)"
echo "foo_man_objs: $(foo_man_objs)"
and here is the current behavior I observe:
$ make
echo "foo_gen_objs: objdir/a.o b.o"
foo_gen_objs: objdir/a.o b.o
echo "foo_man_objs: objdir/a.o objdir/b.o"
foo_man_objs: objdir/a.o objdir/b.o
My expectation was that both $(foo_gen_objs) and $(foo_man_objs) would evaluate to the same value, but instead eval seems to treat $$($(1)_srcs) as a scalar rather than as a list. How can I fix this?
make gnu-make
add a comment |Â
up vote
0
down vote
favorite
I'm trying to to use eval to define a few make variables, but implicitly it seems to convert a list into a scalar. I can't seem to figure out how to avoid this behavior. Here's my current Makefile:
foo_man_srcs := a.c b.c
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
$(eval $(call GEN_OBJS,foo))
all:
echo "foo_gen_objs: $(foo_gen_objs)"
echo "foo_man_objs: $(foo_man_objs)"
and here is the current behavior I observe:
$ make
echo "foo_gen_objs: objdir/a.o b.o"
foo_gen_objs: objdir/a.o b.o
echo "foo_man_objs: objdir/a.o objdir/b.o"
foo_man_objs: objdir/a.o objdir/b.o
My expectation was that both $(foo_gen_objs) and $(foo_man_objs) would evaluate to the same value, but instead eval seems to treat $$($(1)_srcs) as a scalar rather than as a list. How can I fix this?
make gnu-make
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to to use eval to define a few make variables, but implicitly it seems to convert a list into a scalar. I can't seem to figure out how to avoid this behavior. Here's my current Makefile:
foo_man_srcs := a.c b.c
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
$(eval $(call GEN_OBJS,foo))
all:
echo "foo_gen_objs: $(foo_gen_objs)"
echo "foo_man_objs: $(foo_man_objs)"
and here is the current behavior I observe:
$ make
echo "foo_gen_objs: objdir/a.o b.o"
foo_gen_objs: objdir/a.o b.o
echo "foo_man_objs: objdir/a.o objdir/b.o"
foo_man_objs: objdir/a.o objdir/b.o
My expectation was that both $(foo_gen_objs) and $(foo_man_objs) would evaluate to the same value, but instead eval seems to treat $$($(1)_srcs) as a scalar rather than as a list. How can I fix this?
make gnu-make
I'm trying to to use eval to define a few make variables, but implicitly it seems to convert a list into a scalar. I can't seem to figure out how to avoid this behavior. Here's my current Makefile:
foo_man_srcs := a.c b.c
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
$(eval $(call GEN_OBJS,foo))
all:
echo "foo_gen_objs: $(foo_gen_objs)"
echo "foo_man_objs: $(foo_man_objs)"
and here is the current behavior I observe:
$ make
echo "foo_gen_objs: objdir/a.o b.o"
foo_gen_objs: objdir/a.o b.o
echo "foo_man_objs: objdir/a.o objdir/b.o"
foo_man_objs: objdir/a.o objdir/b.o
My expectation was that both $(foo_gen_objs) and $(foo_man_objs) would evaluate to the same value, but instead eval seems to treat $$($(1)_srcs) as a scalar rather than as a list. How can I fix this?
make gnu-make
edited Dec 22 '17 at 17:27
asked Dec 22 '17 at 17:17
user65369
1,00164
1,00164
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
The solution is quite simple: you should escape the $ signs of the addprefix() functions:
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $$(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $$(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
But it's more important to understand how you can debug this sort of problems by yourself. Basically, you just have to replace "eval" with "info", and make will print the input of eval instead of parsing it.
In your example, substituting "eval" with "info" and then calling make yields:
foo_srcs := a.c b.c
foo_gen_objs := objdir/$(foo_srcs:.c=.o)
foo_man_objs := objdir/a.o objdir/b.o
As you can see, call() expanded the addprefix() functions before eval() is called. If you fix your makefile as I wrote above you'll get:
foo_srcs := a.c b.c
foo_gen_objs := $(addprefix objdir/,$(foo_srcs:.c=.o))
foo_man_objs := $(addprefix objdir/,a.o b.o)
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The solution is quite simple: you should escape the $ signs of the addprefix() functions:
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $$(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $$(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
But it's more important to understand how you can debug this sort of problems by yourself. Basically, you just have to replace "eval" with "info", and make will print the input of eval instead of parsing it.
In your example, substituting "eval" with "info" and then calling make yields:
foo_srcs := a.c b.c
foo_gen_objs := objdir/$(foo_srcs:.c=.o)
foo_man_objs := objdir/a.o objdir/b.o
As you can see, call() expanded the addprefix() functions before eval() is called. If you fix your makefile as I wrote above you'll get:
foo_srcs := a.c b.c
foo_gen_objs := $(addprefix objdir/,$(foo_srcs:.c=.o))
foo_man_objs := $(addprefix objdir/,a.o b.o)
add a comment |Â
up vote
1
down vote
The solution is quite simple: you should escape the $ signs of the addprefix() functions:
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $$(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $$(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
But it's more important to understand how you can debug this sort of problems by yourself. Basically, you just have to replace "eval" with "info", and make will print the input of eval instead of parsing it.
In your example, substituting "eval" with "info" and then calling make yields:
foo_srcs := a.c b.c
foo_gen_objs := objdir/$(foo_srcs:.c=.o)
foo_man_objs := objdir/a.o objdir/b.o
As you can see, call() expanded the addprefix() functions before eval() is called. If you fix your makefile as I wrote above you'll get:
foo_srcs := a.c b.c
foo_gen_objs := $(addprefix objdir/,$(foo_srcs:.c=.o))
foo_man_objs := $(addprefix objdir/,a.o b.o)
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The solution is quite simple: you should escape the $ signs of the addprefix() functions:
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $$(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $$(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
But it's more important to understand how you can debug this sort of problems by yourself. Basically, you just have to replace "eval" with "info", and make will print the input of eval instead of parsing it.
In your example, substituting "eval" with "info" and then calling make yields:
foo_srcs := a.c b.c
foo_gen_objs := objdir/$(foo_srcs:.c=.o)
foo_man_objs := objdir/a.o objdir/b.o
As you can see, call() expanded the addprefix() functions before eval() is called. If you fix your makefile as I wrote above you'll get:
foo_srcs := a.c b.c
foo_gen_objs := $(addprefix objdir/,$(foo_srcs:.c=.o))
foo_man_objs := $(addprefix objdir/,a.o b.o)
The solution is quite simple: you should escape the $ signs of the addprefix() functions:
define GEN_OBJS =
$(1)_srcs := a.c b.c
$(1)_gen_objs := $$(addprefix objdir/,$$($(1)_srcs:.c=.o))
$(1)_man_objs := $$(addprefix objdir/,$(foo_man_srcs:.c=.o))
endef
But it's more important to understand how you can debug this sort of problems by yourself. Basically, you just have to replace "eval" with "info", and make will print the input of eval instead of parsing it.
In your example, substituting "eval" with "info" and then calling make yields:
foo_srcs := a.c b.c
foo_gen_objs := objdir/$(foo_srcs:.c=.o)
foo_man_objs := objdir/a.o objdir/b.o
As you can see, call() expanded the addprefix() functions before eval() is called. If you fix your makefile as I wrote above you'll get:
foo_srcs := a.c b.c
foo_gen_objs := $(addprefix objdir/,$(foo_srcs:.c=.o))
foo_man_objs := $(addprefix objdir/,a.o b.o)
answered Dec 22 '17 at 17:52
Simple.guy
111
111
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412561%2fwhy-does-gnu-makes-eval-convert-a-list-to-a-scalar%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password