Why does GNU make's eval convert a list to a scalar?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question


























    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?







    share|improve this question
























      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?







      share|improve this question














      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?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 22 '17 at 17:27

























      asked Dec 22 '17 at 17:17









      user65369

      1,00164




      1,00164




















          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)





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            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






























            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)





            share|improve this answer
























              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)





              share|improve this answer






















                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)





                share|improve this answer












                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)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 22 '17 at 17:52









                Simple.guy

                111




                111






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?