[opensuse-programming] Redefining GNU make's implicit RM variable
GNU 'make' uses implicit variables to perform some tasks. For example CC to define the compiler, and RM to remove a file: http://www.gnu.org/s/hello/manual/make/Implicit-Variables.html On openSUSE 11.2, I can redefine CC as expected. Whatever I define there gets used to do the compile. If I am compiling a binary from multiple sources, my CC gets used for each object file: myBinary: a.o b.o c.o myBinary is correctly created. Since the make rule led to making the three object files, it will also automatically delete them when done. Which it does. But it will not use the RM variable to do this. It seems to use some other definition. At least if I redefine RM (in the same place I defined CC), my definition is never used. All I am really trying to accomplish is to not have the make process echo the rm command when it removes objects it make to satisfy some rule. So, I want to define it as: RM = @rm -f I guess the built-in rule uses 'rm' instead of $(RM). At least it is acting that way. Another odd thing is that the Gnu docs say the default RM command is 'rm -f'. But I see 'rm' being used. Am I looking in the wrong place to redefine RM? Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Wed, 2011-08-03 at 13:37 +0200, Roger Oberholtzer wrote:
All I am really trying to accomplish is to not have the make process echo the rm command when it removes objects it make to satisfy some rule. So, I want to define it as:
RM = @rm -f
I guess the built-in rule uses 'rm' instead of $(RM). At least it is acting that way. Another odd thing is that the Gnu docs say the default RM command is 'rm -f'. But I see 'rm' being used.
Am I looking in the wrong place to redefine RM?
No. You can redefine RM as an environmental variable and make will use what it finds. Check the makefile, especially if you did not write it by hand. Does it use ${RM} to remove files? If not then changing RM will have no effect. Makefiles created by configure scripts usually don’t use ${RM}. -- JDL -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Thu, 2011-08-04 at 07:34 +0100, John D Lamb wrote:
On Wed, 2011-08-03 at 13:37 +0200, Roger Oberholtzer wrote:
All I am really trying to accomplish is to not have the make process echo the rm command when it removes objects it make to satisfy some rule. So, I want to define it as:
RM = @rm -f
I guess the built-in rule uses 'rm' instead of $(RM). At least it is acting that way. Another odd thing is that the Gnu docs say the default RM command is 'rm -f'. But I see 'rm' being used.
Am I looking in the wrong place to redefine RM?
No. You can redefine RM as an environmental variable and make will use what it finds.
Check the makefile, especially if you did not write it by hand. Does it use ${RM} to remove files? If not then changing RM will have no effect. Makefiles created by configure scripts usually don’t use ${RM}.
It is a hand-made Makefile that I have made. My Makefile does not call the RM. It is not supposed to. make has a built-in rule to convert a bunch of .c files in to an executable. It uses variables like CC, CFLAGS, LD, etc as part of this rule. You can re-define CC if you would like, and make will use this as part of the built-in procedure. It seems, however, that even though Gnu define RM as the variable to remove files, RM is not in fact used by this built-in series of steps to convert the .c files into an executable. Is this as intended? How can I list these internal rules? Perhaps I need to redefine it slightly so it does not use 'rm' direct, buy instead uses the variable RM? As a minimum, there should be a way to tell make not to echo these built-in commands. That was what I was trying be defining RM to be a command that started with '@'. To no avail. Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Thu, 2011-08-04 at 09:27 +0200, Roger Oberholtzer wrote:
It is a hand-made Makefile that I have made.
My Makefile does not call the RM. It is not supposed to. make has a built-in rule to convert a bunch of .c files in to an executable. It uses variables like CC, CFLAGS, LD, etc as part of this rule. You can re-define CC if you would like, and make will use this as part of the built-in procedure. It seems, however, that even though Gnu define RM as the variable to remove files, RM is not in fact used by this built-in series of steps to convert the .c files into an executable.
I should have thought of that. Look at pattern rules for make. I think you’ll need to redefine the pattern rule in the make file. For example the implicit rule for compiling C files is %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ If you write a suitable pattern rule for your needs (with $(RM) instead of rm) and put it in the makefile then Make should use the environment variable for RM. -- JDL -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Thu, 2011-08-04 at 14:08 +0100, John D Lamb wrote:
On Thu, 2011-08-04 at 09:27 +0200, Roger Oberholtzer wrote:
It is a hand-made Makefile that I have made.
My Makefile does not call the RM. It is not supposed to. make has a built-in rule to convert a bunch of .c files in to an executable. It uses variables like CC, CFLAGS, LD, etc as part of this rule. You can re-define CC if you would like, and make will use this as part of the built-in procedure. It seems, however, that even though Gnu define RM as the variable to remove files, RM is not in fact used by this built-in series of steps to convert the .c files into an executable.
I should have thought of that. Look at pattern rules for make. I think you’ll need to redefine the pattern rule in the make file. For example the implicit rule for compiling C files is
%.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
If you write a suitable pattern rule for your needs (with $(RM) instead of rm) and put it in the makefile then Make should use the environment variable for RM.
OK. I listed the rules with -p. I see 'rm' in these places: # default RM = rm -f %.out: % # commands to execute (built-in): @rm -f $@ cp $< $@ As well as this: # This program built for i686-pc-linux-gnu rm a.o c.o c.o This final one is the first thing make -p lists. I have no such rule. Mysterious. I think there is a rule not shown with the -p option.
-- JDL
Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
participants (2)
-
John D Lamb
-
Roger Oberholtzer