remove patterned prefix from list in gnu make









up vote
0
down vote

favorite












If I have a list of files:



files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c


Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c?



I was looking into using patsubst, but I would need two%'s -- one for the first part to be ignored, and one for the last part to be kept.










share|improve this question

























    up vote
    0
    down vote

    favorite












    If I have a list of files:



    files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c


    Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c?



    I was looking into using patsubst, but I would need two%'s -- one for the first part to be ignored, and one for the last part to be kept.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      If I have a list of files:



      files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c


      Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c?



      I was looking into using patsubst, but I would need two%'s -- one for the first part to be ignored, and one for the last part to be kept.










      share|improve this question













      If I have a list of files:



      files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c


      Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c?



      I was looking into using patsubst, but I would need two%'s -- one for the first part to be ignored, and one for the last part to be kept.







      makefile gnu-make






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 20:03









      HardcoreHenry

      1,208318




      1,208318






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          It can be done but it's a little gross. You want something like this:



          final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))


          This says, for each element in files we convert the _ to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.



          ETA
          ReAl points out below that this can be simplified using lastword:



          final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))





          share|improve this answer






















          • a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
            – HardcoreHenry
            Nov 9 at 22:13






          • 2




            or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
            – ReAl
            Nov 9 at 22:13










          • Oh yeah... hah!! Forgot about lastword :p :)
            – MadScientist
            Nov 9 at 22:19

















          up vote
          2
          down vote













          As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /: file name functions.



          So your example should simply boil down to



          $(notdir $(subst _,/,$(files))





          share|improve this answer



























            up vote
            0
            down vote













            Use the external program — sed — and enjoy all its power



            files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
            f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`

            all:
            echo $(f)





            share|improve this answer




















            • Nah. Always prefer make mechanisms over the shell.
              – bobbogo
              Nov 12 at 10:17










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53232595%2fremove-patterned-prefix-from-list-in-gnu-make%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            It can be done but it's a little gross. You want something like this:



            final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))


            This says, for each element in files we convert the _ to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.



            ETA
            ReAl points out below that this can be simplified using lastword:



            final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))





            share|improve this answer






















            • a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
              – HardcoreHenry
              Nov 9 at 22:13






            • 2




              or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
              – ReAl
              Nov 9 at 22:13










            • Oh yeah... hah!! Forgot about lastword :p :)
              – MadScientist
              Nov 9 at 22:19














            up vote
            2
            down vote



            accepted










            It can be done but it's a little gross. You want something like this:



            final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))


            This says, for each element in files we convert the _ to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.



            ETA
            ReAl points out below that this can be simplified using lastword:



            final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))





            share|improve this answer






















            • a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
              – HardcoreHenry
              Nov 9 at 22:13






            • 2




              or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
              – ReAl
              Nov 9 at 22:13










            • Oh yeah... hah!! Forgot about lastword :p :)
              – MadScientist
              Nov 9 at 22:19












            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            It can be done but it's a little gross. You want something like this:



            final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))


            This says, for each element in files we convert the _ to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.



            ETA
            ReAl points out below that this can be simplified using lastword:



            final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))





            share|improve this answer














            It can be done but it's a little gross. You want something like this:



            final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))


            This says, for each element in files we convert the _ to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.



            ETA
            ReAl points out below that this can be simplified using lastword:



            final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 17:27

























            answered Nov 9 at 22:06









            MadScientist

            44.7k44764




            44.7k44764











            • a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
              – HardcoreHenry
              Nov 9 at 22:13






            • 2




              or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
              – ReAl
              Nov 9 at 22:13










            • Oh yeah... hah!! Forgot about lastword :p :)
              – MadScientist
              Nov 9 at 22:19
















            • a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
              – HardcoreHenry
              Nov 9 at 22:13






            • 2




              or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
              – ReAl
              Nov 9 at 22:13










            • Oh yeah... hah!! Forgot about lastword :p :)
              – MadScientist
              Nov 9 at 22:19















            a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
            – HardcoreHenry
            Nov 9 at 22:13




            a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
            – HardcoreHenry
            Nov 9 at 22:13




            2




            2




            or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
            – ReAl
            Nov 9 at 22:13




            or even final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
            – ReAl
            Nov 9 at 22:13












            Oh yeah... hah!! Forgot about lastword :p :)
            – MadScientist
            Nov 9 at 22:19




            Oh yeah... hah!! Forgot about lastword :p :)
            – MadScientist
            Nov 9 at 22:19












            up vote
            2
            down vote













            As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /: file name functions.



            So your example should simply boil down to



            $(notdir $(subst _,/,$(files))





            share|improve this answer
























              up vote
              2
              down vote













              As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /: file name functions.



              So your example should simply boil down to



              $(notdir $(subst _,/,$(files))





              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /: file name functions.



                So your example should simply boil down to



                $(notdir $(subst _,/,$(files))





                share|improve this answer












                As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /: file name functions.



                So your example should simply boil down to



                $(notdir $(subst _,/,$(files))






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 22:23









                Vroomfondel

                1,104719




                1,104719




















                    up vote
                    0
                    down vote













                    Use the external program — sed — and enjoy all its power



                    files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
                    f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`

                    all:
                    echo $(f)





                    share|improve this answer




















                    • Nah. Always prefer make mechanisms over the shell.
                      – bobbogo
                      Nov 12 at 10:17














                    up vote
                    0
                    down vote













                    Use the external program — sed — and enjoy all its power



                    files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
                    f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`

                    all:
                    echo $(f)





                    share|improve this answer




















                    • Nah. Always prefer make mechanisms over the shell.
                      – bobbogo
                      Nov 12 at 10:17












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Use the external program — sed — and enjoy all its power



                    files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
                    f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`

                    all:
                    echo $(f)





                    share|improve this answer












                    Use the external program — sed — and enjoy all its power



                    files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
                    f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`

                    all:
                    echo $(f)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 9 at 21:51









                    ReAl

                    548215




                    548215











                    • Nah. Always prefer make mechanisms over the shell.
                      – bobbogo
                      Nov 12 at 10:17
















                    • Nah. Always prefer make mechanisms over the shell.
                      – bobbogo
                      Nov 12 at 10:17















                    Nah. Always prefer make mechanisms over the shell.
                    – bobbogo
                    Nov 12 at 10:17




                    Nah. Always prefer make mechanisms over the shell.
                    – bobbogo
                    Nov 12 at 10:17

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232595%2fremove-patterned-prefix-from-list-in-gnu-make%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

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo