Makefile strange variable substitution2019 Community Moderator ElectionPlease explain what happens when I run...

Single word request: Harming the benefactor

'The literal of type int is out of range' con número enteros pequeños (2 dígitos)

How to draw cubes in a 3 dimensional plane

What are actual Tesla M60 models used by AWS?

Why does Captain Marvel assume the people on this planet know this?

Does the nature of the Apocalypse in The Umbrella Academy change from the first to the last episode?

Makefile strange variable substitution

weren't playing vs didn't play

Do I really need to have a scientific explanation for my premise?

Recommendation letter by significant other if you worked with them professionally?

Plausibility of Mushroom Buildings

Error during using callback start_page_number in lualatex

Does "Until when" sound natural for native speakers?

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

Vocabulary for giving just numbers, not a full answer

PTIJ: wiping amalek’s memory?

Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?

Signed and unsigned numbers

Find longest word in a string: are any of these algorithms good?

Conservation of Mass and Energy

Declaring and defining template, and specialising them

Is "history" a male-biased word ("his+story")?

What's the "normal" opposite of flautando?

Was Luke Skywalker the leader of the Rebel forces on Hoth?



Makefile strange variable substitution



2019 Community Moderator ElectionPlease explain what happens when I run this Makefileuse bash to pass 2 variables to a MakefileHow can i make use of makefile exported values while running script fileMakefile include env fileOutput to multiple files with MakefileIs there away to tell make to apply a rule to every file that matches a pattern?Folder exclusion formatting issueHow can I refactor this Makefile to not use fake .out outputs?Makefile fails when trying to run a C programCan't access files from within makefile












2















My Makefile looks like this:



%.foo: %.bar
cp $< $@

test: *.foo
echo *.foo


I have 2 files in the directory: a.bar and b.bar. When I run make test it outputs:



cp b.bar *.foo
echo *.foo
*.foo


It also creates a file *.foo in the current directory.



I am actually expecting to see this:



cp a.bar a.foo
cp b.bar b.foo
echo *.foo
a.foo b.foo


And also creating a.foo and b.foo. How to achieve that?










share|improve this question



























    2















    My Makefile looks like this:



    %.foo: %.bar
    cp $< $@

    test: *.foo
    echo *.foo


    I have 2 files in the directory: a.bar and b.bar. When I run make test it outputs:



    cp b.bar *.foo
    echo *.foo
    *.foo


    It also creates a file *.foo in the current directory.



    I am actually expecting to see this:



    cp a.bar a.foo
    cp b.bar b.foo
    echo *.foo
    a.foo b.foo


    And also creating a.foo and b.foo. How to achieve that?










    share|improve this question

























      2












      2








      2








      My Makefile looks like this:



      %.foo: %.bar
      cp $< $@

      test: *.foo
      echo *.foo


      I have 2 files in the directory: a.bar and b.bar. When I run make test it outputs:



      cp b.bar *.foo
      echo *.foo
      *.foo


      It also creates a file *.foo in the current directory.



      I am actually expecting to see this:



      cp a.bar a.foo
      cp b.bar b.foo
      echo *.foo
      a.foo b.foo


      And also creating a.foo and b.foo. How to achieve that?










      share|improve this question














      My Makefile looks like this:



      %.foo: %.bar
      cp $< $@

      test: *.foo
      echo *.foo


      I have 2 files in the directory: a.bar and b.bar. When I run make test it outputs:



      cp b.bar *.foo
      echo *.foo
      *.foo


      It also creates a file *.foo in the current directory.



      I am actually expecting to see this:



      cp a.bar a.foo
      cp b.bar b.foo
      echo *.foo
      a.foo b.foo


      And also creating a.foo and b.foo. How to achieve that?







      make






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      Martin ŽdilaMartin Ždila

      155115




      155115






















          2 Answers
          2






          active

          oldest

          votes


















          3














          In this case you need to handle wildcards explicitly, with the wildcard function (at least in GNU Make):



          %.foo: %.bar
          cp $< $@

          foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

          test: $(foos)
          echo $(foos)


          $(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.






          share|improve this answer































            3














            There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.



            You can verify this by running make -d test.



            You can get the effect you want by generating the list of targets based on list of prerequisites.



            TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
            %.foo: %.bar
            @cp $< $@
            test: $(TARGETS)
            @echo $(TARGETS)
            echo *.foo





            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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              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%2f505735%2fmakefile-strange-variable-substitution%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              In this case you need to handle wildcards explicitly, with the wildcard function (at least in GNU Make):



              %.foo: %.bar
              cp $< $@

              foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

              test: $(foos)
              echo $(foos)


              $(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.






              share|improve this answer




























                3














                In this case you need to handle wildcards explicitly, with the wildcard function (at least in GNU Make):



                %.foo: %.bar
                cp $< $@

                foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

                test: $(foos)
                echo $(foos)


                $(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.






                share|improve this answer


























                  3












                  3








                  3







                  In this case you need to handle wildcards explicitly, with the wildcard function (at least in GNU Make):



                  %.foo: %.bar
                  cp $< $@

                  foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

                  test: $(foos)
                  echo $(foos)


                  $(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.






                  share|improve this answer













                  In this case you need to handle wildcards explicitly, with the wildcard function (at least in GNU Make):



                  %.foo: %.bar
                  cp $< $@

                  foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))

                  test: $(foos)
                  echo $(foos)


                  $(wildcard *.bar) expands to all the files ending in .bar, the patsubst call replaces .bar with .foo, and all the targets are then processed as you’d expect.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  Stephen KittStephen Kitt

                  175k24400478




                  175k24400478

























                      3














                      There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.



                      You can verify this by running make -d test.



                      You can get the effect you want by generating the list of targets based on list of prerequisites.



                      TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
                      %.foo: %.bar
                      @cp $< $@
                      test: $(TARGETS)
                      @echo $(TARGETS)
                      echo *.foo





                      share|improve this answer




























                        3














                        There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.



                        You can verify this by running make -d test.



                        You can get the effect you want by generating the list of targets based on list of prerequisites.



                        TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
                        %.foo: %.bar
                        @cp $< $@
                        test: $(TARGETS)
                        @echo $(TARGETS)
                        echo *.foo





                        share|improve this answer


























                          3












                          3








                          3







                          There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.



                          You can verify this by running make -d test.



                          You can get the effect you want by generating the list of targets based on list of prerequisites.



                          TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
                          %.foo: %.bar
                          @cp $< $@
                          test: $(TARGETS)
                          @echo $(TARGETS)
                          echo *.foo





                          share|improve this answer













                          There is no *.foo file to begin with. So what make does is look for how to make *.foo literaly and the first rule does this. Make expands $< to the first pre-requisite (*.bar, which happens to be b.bar in this case). Make then runs the shell command cp b.bar *.foo. Since there is no *.foo, shell expands it to cp b.bar *.foo literally. That's how you get a *.foo file.



                          You can verify this by running make -d test.



                          You can get the effect you want by generating the list of targets based on list of prerequisites.



                          TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
                          %.foo: %.bar
                          @cp $< $@
                          test: $(TARGETS)
                          @echo $(TARGETS)
                          echo *.foo






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 3 hours ago









                          Satya MishraSatya Mishra

                          35615




                          35615






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505735%2fmakefile-strange-variable-substitution%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

                              Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

                              Castillo d'Acher Características Menú de navegación