Modify filenames in MakefileCreating a MakefileGNU Makefile surpriseIntercept GNU/Linux system callsUsing...

Why do we need a bootloader separate from our application program in microcontrollers?

How to deal with a Murder Hobo Paladin?

How to play a D major chord lower than the open E major chord on guitar?

What is this arch-and-tower near a road?

Will Jimmy fall off his platform?

What is the fundamental difference between catching whales and hunting other animals?

What causes a fastener to lock?

Should I warn my boss I might take sick leave?

Speeding up thousands of string parses

Why does mean tend be more stable in different samples than median?

Why no parachutes in the Orion AA2 abort test?

How do I check that users don't write down their passwords?

Why weren't Gemini capsules given names?

n-level Ouroboros Quine

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

How did Einstein know the speed of light was constant?

Bypass with wrong cvv of debit card and getting OTP

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

soda water first stored in refrigerator and then outside

What's the difference between a type and a kind?

What's the big deal about the Nazgûl losing their horses?

Park the computer

How do I iterate equal values with the standard library?

Is conquering your neighbors to fight a greater enemy a valid strategy?



Modify filenames in Makefile


Creating a MakefileGNU Makefile surpriseIntercept GNU/Linux system callsUsing eval in make fileWhy 'Makefile' demands dependency?Reference function in Makefile?Automated way to periodically move files of a specific file-extension to cloud folder (mounted as local directory)Hello World MakefileMakefile strange variable substitutionUsing sed within a makefile






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with files called



fun1.c fun2.c


and end up with files



fun1_a.c fun2_a.c


I want the Makefile to be adapted automatically, too. A bare-bones version of the Makefile is



SRC=    fun1.c fun2.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2.o: fun1.o


How can I best process the file so each entry in the definition of the source files and the dependencies is changed as needed, but the pattern rules are left untouched? In other words, what I need is:



SRC=    fun1_a.c fun2_a.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2_a.o: fun1_a.o


I assume this is trivial, but my scripting abilities, especially in sed and perl are limited.



EDIT: Please note that in practice, not all the files will be called funx.c where x is an integer, so I'm looking for a solution that will work with any filename.










share|improve this question
















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

    – Kira
    Nov 17 '15 at 15:38











  • Yes, I would prefer to have two separate copies of the Makefile.

    – user1362373
    Nov 17 '15 at 15:45











  • And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

    – Kira
    Nov 17 '15 at 15:47













  • Yes, you are right. I've edited my question accordingly.

    – user1362373
    Nov 17 '15 at 16:02











  • fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

    – JJoao
    Nov 18 '15 at 0:01


















3















For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with files called



fun1.c fun2.c


and end up with files



fun1_a.c fun2_a.c


I want the Makefile to be adapted automatically, too. A bare-bones version of the Makefile is



SRC=    fun1.c fun2.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2.o: fun1.o


How can I best process the file so each entry in the definition of the source files and the dependencies is changed as needed, but the pattern rules are left untouched? In other words, what I need is:



SRC=    fun1_a.c fun2_a.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2_a.o: fun1_a.o


I assume this is trivial, but my scripting abilities, especially in sed and perl are limited.



EDIT: Please note that in practice, not all the files will be called funx.c where x is an integer, so I'm looking for a solution that will work with any filename.










share|improve this question
















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

    – Kira
    Nov 17 '15 at 15:38











  • Yes, I would prefer to have two separate copies of the Makefile.

    – user1362373
    Nov 17 '15 at 15:45











  • And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

    – Kira
    Nov 17 '15 at 15:47













  • Yes, you are right. I've edited my question accordingly.

    – user1362373
    Nov 17 '15 at 16:02











  • fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

    – JJoao
    Nov 18 '15 at 0:01














3












3








3


2






For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with files called



fun1.c fun2.c


and end up with files



fun1_a.c fun2_a.c


I want the Makefile to be adapted automatically, too. A bare-bones version of the Makefile is



SRC=    fun1.c fun2.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2.o: fun1.o


How can I best process the file so each entry in the definition of the source files and the dependencies is changed as needed, but the pattern rules are left untouched? In other words, what I need is:



SRC=    fun1_a.c fun2_a.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2_a.o: fun1_a.o


I assume this is trivial, but my scripting abilities, especially in sed and perl are limited.



EDIT: Please note that in practice, not all the files will be called funx.c where x is an integer, so I'm looking for a solution that will work with any filename.










share|improve this question
















For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with files called



fun1.c fun2.c


and end up with files



fun1_a.c fun2_a.c


I want the Makefile to be adapted automatically, too. A bare-bones version of the Makefile is



SRC=    fun1.c fun2.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2.o: fun1.o


How can I best process the file so each entry in the definition of the source files and the dependencies is changed as needed, but the pattern rules are left untouched? In other words, what I need is:



SRC=    fun1_a.c fun2_a.c

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

fun2_a.o: fun1_a.o


I assume this is trivial, but my scripting abilities, especially in sed and perl are limited.



EDIT: Please note that in practice, not all the files will be called funx.c where x is an integer, so I'm looking for a solution that will work with any filename.







shell-script text-processing sed perl make






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '15 at 23:32









Gilles

562k134 gold badges1158 silver badges1667 bronze badges




562k134 gold badges1158 silver badges1667 bronze badges










asked Nov 17 '15 at 15:26









user1362373user1362373

1163 bronze badges




1163 bronze badges





bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

    – Kira
    Nov 17 '15 at 15:38











  • Yes, I would prefer to have two separate copies of the Makefile.

    – user1362373
    Nov 17 '15 at 15:45











  • And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

    – Kira
    Nov 17 '15 at 15:47













  • Yes, you are right. I've edited my question accordingly.

    – user1362373
    Nov 17 '15 at 16:02











  • fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

    – JJoao
    Nov 18 '15 at 0:01














  • 1





    It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

    – Kira
    Nov 17 '15 at 15:38











  • Yes, I would prefer to have two separate copies of the Makefile.

    – user1362373
    Nov 17 '15 at 15:45











  • And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

    – Kira
    Nov 17 '15 at 15:47













  • Yes, you are right. I've edited my question accordingly.

    – user1362373
    Nov 17 '15 at 16:02











  • fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

    – JJoao
    Nov 18 '15 at 0:01








1




1





It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

– Kira
Nov 17 '15 at 15:38





It would be possible to solve your problem entirely with make, is it a requirement to use tools such sed/perl/awk?

– Kira
Nov 17 '15 at 15:38













Yes, I would prefer to have two separate copies of the Makefile.

– user1362373
Nov 17 '15 at 15:45





Yes, I would prefer to have two separate copies of the Makefile.

– user1362373
Nov 17 '15 at 15:45













And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

– Kira
Nov 17 '15 at 15:47







And isn't it relevant to better explain how your files are renamed? Otherwise something like sed 's/(fun[0-9]+)/1_a/' makefile would do the trick (I've not tested this, I'm trying to gather more information yet).

– Kira
Nov 17 '15 at 15:47















Yes, you are right. I've edited my question accordingly.

– user1362373
Nov 17 '15 at 16:02





Yes, you are right. I've edited my question accordingly.

– user1362373
Nov 17 '15 at 16:02













fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

– JJoao
Nov 18 '15 at 0:01





fun2.o: fun1.o ...this looks strange. I think that the rule .c --> .ois the default makefile rule. What is your makefile really doing?

– JJoao
Nov 18 '15 at 0:01










1 Answer
1






active

oldest

votes


















0














Assuming that the original file names are static, and only the result of the rename operation is unpredictable. When you rename files, generate an additional file which would contain the mapping of the original file names to the new names, e.g.:



fun1.c=fun1_a.c
fun2.c=fun2_a.c


Assuming that this generated mapping file is called rename.mk, one can modify the Makefile in the following fashion:



include rename.mk
SRC= $(fun1.c) $(fun2.c)

%.o: $.c
$(CC) $(CFLAGS) -c $< -o $@

OBJ= $(SRC:.c=.o)

$(fun2.c:.c=.o): $(fun1.c:.c=.o)


The file names have become the variable names, and are used to access the new names via the mapping specified in the rename.mk.






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%2f243630%2fmodify-filenames-in-makefile%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Assuming that the original file names are static, and only the result of the rename operation is unpredictable. When you rename files, generate an additional file which would contain the mapping of the original file names to the new names, e.g.:



    fun1.c=fun1_a.c
    fun2.c=fun2_a.c


    Assuming that this generated mapping file is called rename.mk, one can modify the Makefile in the following fashion:



    include rename.mk
    SRC= $(fun1.c) $(fun2.c)

    %.o: $.c
    $(CC) $(CFLAGS) -c $< -o $@

    OBJ= $(SRC:.c=.o)

    $(fun2.c:.c=.o): $(fun1.c:.c=.o)


    The file names have become the variable names, and are used to access the new names via the mapping specified in the rename.mk.






    share|improve this answer




























      0














      Assuming that the original file names are static, and only the result of the rename operation is unpredictable. When you rename files, generate an additional file which would contain the mapping of the original file names to the new names, e.g.:



      fun1.c=fun1_a.c
      fun2.c=fun2_a.c


      Assuming that this generated mapping file is called rename.mk, one can modify the Makefile in the following fashion:



      include rename.mk
      SRC= $(fun1.c) $(fun2.c)

      %.o: $.c
      $(CC) $(CFLAGS) -c $< -o $@

      OBJ= $(SRC:.c=.o)

      $(fun2.c:.c=.o): $(fun1.c:.c=.o)


      The file names have become the variable names, and are used to access the new names via the mapping specified in the rename.mk.






      share|improve this answer


























        0












        0








        0







        Assuming that the original file names are static, and only the result of the rename operation is unpredictable. When you rename files, generate an additional file which would contain the mapping of the original file names to the new names, e.g.:



        fun1.c=fun1_a.c
        fun2.c=fun2_a.c


        Assuming that this generated mapping file is called rename.mk, one can modify the Makefile in the following fashion:



        include rename.mk
        SRC= $(fun1.c) $(fun2.c)

        %.o: $.c
        $(CC) $(CFLAGS) -c $< -o $@

        OBJ= $(SRC:.c=.o)

        $(fun2.c:.c=.o): $(fun1.c:.c=.o)


        The file names have become the variable names, and are used to access the new names via the mapping specified in the rename.mk.






        share|improve this answer













        Assuming that the original file names are static, and only the result of the rename operation is unpredictable. When you rename files, generate an additional file which would contain the mapping of the original file names to the new names, e.g.:



        fun1.c=fun1_a.c
        fun2.c=fun2_a.c


        Assuming that this generated mapping file is called rename.mk, one can modify the Makefile in the following fashion:



        include rename.mk
        SRC= $(fun1.c) $(fun2.c)

        %.o: $.c
        $(CC) $(CFLAGS) -c $< -o $@

        OBJ= $(SRC:.c=.o)

        $(fun2.c:.c=.o): $(fun1.c:.c=.o)


        The file names have become the variable names, and are used to access the new names via the mapping specified in the rename.mk.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 16 '15 at 20:41









        Dummy00001Dummy00001

        1664 bronze badges




        1664 bronze badges






























            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%2f243630%2fmodify-filenames-in-makefile%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

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...