Makefile strange variable substitution [duplicate]












5
















This question already has an answer here:




  • Is there a way to tell make to apply a rule to every file that matches a pattern?

    1 answer




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













marked as duplicate by ilkkachu, Mr Shunz, roaima, Michael Homer, elbarna Mar 17 at 20:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    5
















    This question already has an answer here:




    • Is there a way to tell make to apply a rule to every file that matches a pattern?

      1 answer




    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













    marked as duplicate by ilkkachu, Mr Shunz, roaima, Michael Homer, elbarna Mar 17 at 20:28


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      5












      5








      5









      This question already has an answer here:




      • Is there a way to tell make to apply a rule to every file that matches a pattern?

        1 answer




      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















      This question already has an answer here:




      • Is there a way to tell make to apply a rule to every file that matches a pattern?

        1 answer




      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?





      This question already has an answer here:




      • Is there a way to tell make to apply a rule to every file that matches a pattern?

        1 answer








      make






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 11 at 21:49









      Martin ŽdilaMartin Ždila

      170115




      170115




      marked as duplicate by ilkkachu, Mr Shunz, roaima, Michael Homer, elbarna Mar 17 at 20:28


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by ilkkachu, Mr Shunz, roaima, Michael Homer, elbarna Mar 17 at 20:28


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          2 Answers
          2






          active

          oldest

          votes


















          7














          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































            6














            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






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7














              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




























                7














                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


























                  7












                  7








                  7







                  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 Mar 11 at 21:59









                  Stephen KittStephen Kitt

                  177k24402479




                  177k24402479

























                      6














                      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




























                        6














                        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


























                          6












                          6








                          6







                          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 Mar 11 at 22:13









                          Satya MishraSatya Mishra

                          38615




                          38615















                              Popular posts from this blog

                              How to send String Array data to Server using php in android

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Is anime1.com a legal site for watching anime?