List Info

Thread: clean recursively into sub-directories




clean recursively into sub-directories
country flaguser name
Netherlands
2008-04-29 07:49:12
Hello all,

I have three sub-directories (gen, ora, util) under the
top-level directory and I want to run Makefiles recursively
into these sub-directories.

My Makefile at top-level directory is

============================================
SRC = gen ora util

SUBDIRS = gen ora util

.PHONY: all $(SUBDIRS)

all: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $ -f Makefile.hvr_gcc

util: ora

ora: gen

.PHONY: clean $(SRC)

clean: $(SRC)

$(SRC): 
	$(MAKE) -C $ -f Makefile.hvr_gcc clean

==============================================

It just follows the example code from the offical manual of
GNU Make. But since I would like this Makefile to run
"make clean" also recureively into
sub-directories, I add the "clean" target and it
stops working.

However, when I run "make" or "make
clean" under the top-level directory, the result is:

==============================================
jigsawguam> gmake -f Makefile
Makefile:54: warning: overriding commands for target `gen'
Makefile:41: warning: ignoring old commands for target
`gen'
Makefile:54: warning: overriding commands for target `ora'
Makefile:41: warning: ignoring old commands for target
`ora'
Makefile:54: warning: overriding commands for target `util'
Makefile:41: warning: ignoring old commands for target
`util'
gmake -C gen -f Makefile.hvr_gcc clean
gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/gen'
rm -f libzizzy.a
rm -f *.o
gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/gen'
gmake -C ora -f Makefile.hvr_gcc clean
gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/ora'
rm -f libzizora.a
rm -f *.o
rm -f ../gen/*.o
gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/ora'
gmake -C util -f Makefile.hvr_gcc clean
gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/util'
rm -f zizzy
rm -f *.o
gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/util'
================================================

Could anybody help me out? Thanks in advance!
____________________________________________________________
_____
News, entertainment and everything you care about at
Live.com. Get it now!
http://www.live.c
om/getstarted.aspx


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: clean recursively into sub-directories
country flaguser name
United States
2008-04-29 09:57:27
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hongliang,

You have multiple conflicting rules for "all" and
"clean". Here's the
right way to do this (untested):

============================================

SUBDIRS = gen ora util

.PHONY: all clean

all clean:
        for dir in $(SUBDIRS); do 
	  $(MAKE) -C $$dir -f Makefile.hvr_gcc $; 
        done

============================================

Cleaner and simpler. Note that the inter-directory
dependencies are now
maintained by the order of the SUBDIRS list, not by make
itself.

John

Hongliang Wang wrote:
> Hello all,
> 
> I have three sub-directories (gen, ora, util) under the
top-level directory and I want to run Makefiles recursively
into these sub-directories.
> 
> My Makefile at top-level directory is
> 
> ============================================
> SRC = gen ora util
> 
> SUBDIRS = gen ora util
> 
> .PHONY: all $(SUBDIRS)
> 
> all: $(SUBDIRS)
> 
> $(SUBDIRS):
> 	$(MAKE) -C $ -f Makefile.hvr_gcc
> 
> util: ora
> 
> ora: gen
> 
> .PHONY: clean $(SRC)
> 
> clean: $(SRC)
> 
> $(SRC): 
> 	$(MAKE) -C $ -f Makefile.hvr_gcc clean
> 
> ==============================================
> 
> It just follows the example code from the offical
manual of GNU Make. But since I would like this Makefile to
run "make clean" also recureively into
sub-directories, I add the "clean" target and it
stops working.
> 
> However, when I run "make" or "make
clean" under the top-level directory, the result is:
> 
> ==============================================
> jigsawguam> gmake -f Makefile
> Makefile:54: warning: overriding commands for target
`gen'
> Makefile:41: warning: ignoring old commands for target
`gen'
> Makefile:54: warning: overriding commands for target
`ora'
> Makefile:41: warning: ignoring old commands for target
`ora'
> Makefile:54: warning: overriding commands for target
`util'
> Makefile:41: warning: ignoring old commands for target
`util'
> gmake -C gen -f Makefile.hvr_gcc clean
> gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/gen'
> rm -f libzizzy.a
> rm -f *.o
> gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/gen'
> gmake -C ora -f Makefile.hvr_gcc clean
> gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/ora'
> rm -f libzizora.a
> rm -f *.o
> rm -f ../gen/*.o
> gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/ora'
> gmake -C util -f Makefile.hvr_gcc clean
> gmake[1]: Entering directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/util'
> rm -f zizzy
> rm -f *.o
> gmake[1]: Leaving directory
`/export/guam/jigsaw/dev/jhwgu/src/jz/util'
> ================================================
> 
> Could anybody help me out? Thanks in advance!
>
____________________________________________________________
_____
> News, entertainment and everything you care about at
Live.com. Get it now!
> http://www.live.c
om/getstarted.aspx
> 
> 
> _______________________________________________
> Help-make mailing list
> Help-makegnu.org
> http:
//lists.gnu.org/mailman/listinfo/help-make
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org


iD8DBQFIFzdXdcgqmRY/OH8RApWiAJ992MAbkhVSe5rGUPhDhNtdjxyx+QCf
b+fA
VD8zJuZ/s5bCJMQrDDpj7lg=
=84VL
-----END PGP SIGNATURE-----


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: clean recursively into sub-directories
user name
2008-04-29 10:14:30
On Tue, 2008-04-29 at 08:57 -0600, John Calcote wrote:

> You have multiple conflicting rules for "all"
and "clean".

This is true.  You may only have one recipe defined for a
given target.
Else, how can make know which one you want to run?

> Here's the right way to do this (untested):

But this is not correct.  See the GNU make manual for a
number of
reasons why this model (using a for-loop in a single rule)
is a bad way
to handle subdirectory makes.

Hongliang's method of handling "all" is correct
and appropriate.

However, to have a different set of rules that also are run
in
subdirectories, you have to create different targets. 
Something like:

        SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
        
        .PHONY: clean $(SUBCLEAN)
        clean: $(SUBCLEAN)
        
        $(SUBCLEAN): %.clean:
        	$(MAKE) -C $* -f Makefile.hvr_gcc clean

(untested).  There are a lot of ways to do this but you need
to do
something like it.

> all clean:
>         for dir in $(SUBDIRS); do 
> 	  $(MAKE) -C $$dir -f Makefile.hvr_gcc $; 
>         done

> Cleaner and simpler.

But, not correct .  For
example, what happens if one of the submakes
fails?  That's not even mentioning the problems this brings
if you want
to run parallel builds.

-- 
------------------------------------------------------------
-----------------
 Paul D. Smith <psmithgnu.org>                
http://make.mad-scientis
t.us
 "Please remain calm--I may be mad, but I am a
professional."--Mad Scientist




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: clean recursively into sub-directories
country flaguser name
United States
2008-04-29 10:26:05
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul,

Hmmm, I guess Automake's been doing it wrong all these
years...

BTW, I see your points, and I agree. I'm just wondering why,
if this
method that you (and the manual) mention is more correct,
Automake has
not been retrofitted years ago to handle this syntax. Could
it have
something to do with the fact that some of the syntax you
use is GNU
make specific?

John

Paul Smith wrote:
> On Tue, 2008-04-29 at 08:57 -0600, John Calcote wrote:
> 
>> You have multiple conflicting rules for
"all" and "clean".
> 
> This is true.  You may only have one recipe defined for
a given target.
> Else, how can make know which one you want to run?
> 
>> Here's the right way to do this (untested):
> 
> But this is not correct.  See the GNU make manual for a
number of
> reasons why this model (using a for-loop in a single
rule) is a bad way
> to handle subdirectory makes.
> 
> Hongliang's method of handling "all" is
correct and appropriate.
> 
> However, to have a different set of rules that also are
run in
> subdirectories, you have to create different targets. 
Something like:
> 
>         SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
>         
>         .PHONY: clean $(SUBCLEAN)
>         clean: $(SUBCLEAN)
>         
>         $(SUBCLEAN): %.clean:
>         	$(MAKE) -C $* -f Makefile.hvr_gcc clean
> 
> (untested).  There are a lot of ways to do this but you
need to do
> something like it.
> 
>> all clean:
>>         for dir in $(SUBDIRS); do 
>> 	  $(MAKE) -C $$dir -f Makefile.hvr_gcc $; 
>>         done
> 
>> Cleaner and simpler.
> 
> But, not correct .  For
example, what happens if one of the submakes
> fails?  That's not even mentioning the problems this
brings if you want
> to run parallel builds.
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org


iD8DBQFIFz4NdcgqmRY/OH8RAj2SAKCDfU5LDF7UVaDh0Lk0qMpxkfyg8ACe
J6GI
/67V8867gzjHO2XKnJ4UMF8=
=VYtD
-----END PGP SIGNATURE-----


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: clean recursively into sub-directories
user name
2008-04-29 10:41:10
On Tue, 2008-04-29 at 09:26 -0600, John Calcote wrote:
> Could it have something to do with the fact that some
of the syntax
> you use is GNU make specific?

This is exactly it, I think.  Also, make versions other than
GNU make
don't do parallelism anyway.  And, you can see that automake
recipes go
to a LOT of effort to handle the errors that are generated
by
subdirectories properly: they even test the make flags and
don't throw
an error if the user specified -k.

If you're able to rely on GNU make, it's a lot simpler to
use one of the
methods described in the GNU make manual.

-- 
------------------------------------------------------------
-----------------
 Paul D. Smith <psmithgnu.org>                
http://make.mad-scientis
t.us
 "Please remain calm--I may be mad, but I am a
professional."--Mad Scientist




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: clean recursively into sub-directories
user name
2008-04-29 12:52:25
>>>>> "John" == John Calcote
<john.calcotegmail.com> writes:

John> Hmmm, I guess Automake's been doing it wrong all
these years...

Automake's output is runnable on pretty restricted versions
of make --
not just GNU make.  Sometimes that entails sacrifices like
this.
Also, in this particular case, Automake's SUBDIRS feature
has been
documented for years as running the subdir builds in order.

In general I would say, avoid subdirs if you can, even with
Automake.

And, if you can't, and you don't mind a GNU make dependency,
then use
that instead.

Tom


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )