i recommend to create a copy of the entire source tree then modify the files in the copy directory without renaming them. that way you don't need to modify the makefile. and as bonus you can have an overview of the changes just by comparing the directories.
instead of this
project
fun1.c
fun1_mod.c
fun2.c
fun2_mod.c
Makefile
Makefile_mod
you have this
project
fun1.c
fun2.c
Makefile
project_mod
fun1.c
fun2.c
Makefile
elaboration
if the makefile is super simple like in your example you might get away with using sed to modify the filenames in the makefile. but makefiles are arcane beasts. with a plethora of implicit rules and multiple levels of variable expansions.
mangling filenames is a common occurence even in simple makefiles. even your makefile has some filename mangling (OBJ= $(SRC:.c=.o)
). this can get unexpected results if changing something using sed.
common wildcards like *.c
can easily end up collecting more files than expected. and trying to write wildcards to exclude or include the suffix would be like herding cats.
if original and modified source files are in the same directory you can never be sure if not one of the originals was inadvertently compiled by the modified makefile or vice versa.
also, i forebode, you will not have just one modification. you will have many. so not just fun1_mod.c
and fun2_mod.c
but _mod1
_mod2
_mod3
_mod3butpartmod1
and so forth.
you will forever have headache figuring out what binary was compiled from which modset.
so create a copy of the entire source tree for each modification. modify the source in each directory. keep the filenames the same. keep the makefile the same.
that way you go in one directory and compile. go to other directory and compile. always the same makefile. and always know for sure which files will be compiled. (unless the makefile picks up source files from parent and sibling directories but that is not common practice and is frowned upon in the makefile community.)
bonus:
you can easily see what is different from one modset to another using a directory compare tool of your liking.
you can keep the modifications in source control like git. one branch for each mod. you can do changes in the main branch and propagate it to the other branches. you can cherry pick changes around. you can push and pull to colleagues.
make
, is it a requirement to use tools suchsed
/perl
/awk
?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).fun2.o: fun1.o
...this looks strange. I think that the rule.c --> .o
is the default makefile rule. What is your makefile really doing?