List Info

Thread: trouble cleaning the right files ..




trouble cleaning the right files ..
country flaguser name
United States
2007-06-18 03:43:43
** sorry for such a long post, but I dont know how else to
explain this **

I am having trouble cleaning up the right set of files.
Basically the make 
is divided into a
a top make file which includes module level makes. Top make
has a target 
called clean_all
which has module level clean targets as prereqs as follows
:
clean_all : $(clean)

Each module make appends its clean target to clean variable
as :
clean     += clean_dir1 .. so eventually clean_all looks
like
clean_all : clean_dir1 clean_dir2

clean_dir1 (for example) rule is :

clean_dir1 :
        rm $(local_objs)

Each module make has the following common lines at the
beginning ..
local_dir  := dir1
local_src  := $(addprefix $(local_dir)/,print1dir1.c)
local_src  += $(addprefix $(local_dir)/,print2dir1.c)
local_objs := $(subst .c,.o,$(local_src))

When I try cleaning with clean_all target, make throws out
the following :

Reading makefile `SmallPrjMain.mk'...
Reading makefile `dir1/dir1.mk' (search path) (no ~
expansion)...
Reading makefile `dir2/dir2.mk' (search path) (no ~
expansion)...
Updating goal targets....
Considering target file `clean_all'.
File `clean_all' does not exist.
  Considering target file `clean_dir1'.
   File `clean_dir1' does not exist.
   Finished prerequisites of target file `clean_dir1'.
  Must remake target `clean_dir1'.
rm dir2/print1dir2.o dir2/print2dir2.o
rm: cannot lstat `dir2/print1dir2.o': No such file or
directory
rm: cannot lstat `dir2/print2dir2.o': No such file or
directory
make: *** [clean_dir1] Error 1

I expect that clean_all should lead to clean_dir1 and
clean_dir2.
This should result in rm dir1/print1dir1.o dir1/print2dir1
and
                            rm dir2/print1dir2.o
dir2/print2dir2

But clean_all always leads to dir2/print1dir2.o
dir2/print2dir2.o

I can see that make has the right rule and has proper
prereqs.
But it seems defered variable substitution for local_objs in
the
command is causing this issue. I know that this is how make
is expected to work, but given a problem of my kind, what
is the way out.

I can think of appending all objects to a variable and use
it,
but if I want to clean objects relating to a particular
target alone
then I am stuck ..

I am pasting all the 3 make file I am using

top make file

programs :=
sources  :=
clean    :=
objects  :=

dependencies  = $(subst .c,.d,$(sources));

include_dirs := lib include

CPPFLAGS     += $(addprefix -I,$(include_dirs))

programs     += main.c

vpath %.h $(include_dirs)
VPATH = dir1:dir2

MV  := mv -f
RM  := rm -f
SED := sed

all:
include dir1/dir1.mk
include dir2/dir2.mk

objects  := $(subst .c,.o,$(sources))

.PHONY : all

all :  main

main : main.o $(objects)

.PHONY : clean_all

clean_all : $(clean)
        echo clean

dir1.mk

local_dir  := dir1
local_src  := $(addprefix $(local_dir)/,print1dir1.c)
local_src  += $(addprefix $(local_dir)/,print2dir1.c)
local_objs := $(subst .c,.o,$(local_src))

libraries += $(local_lib)
sources   += $(local_src)

programs  += dir1
clean     += clean_dir1

dir1 : $(local_objs)

.PHONY : clean_dir1
clean_dir1 :
        rm $(local_objs)
~
dir2.mk

local_dir  := dir2
local_src  := $(addprefix $(local_dir)/,print1dir2.c)
local_src  += $(addprefix $(local_dir)/,print2dir2.c)
local_objs := $(subst .c,.o,$(local_src))

libraries += $(local_lib)
sources   += $(local_src)

programs  += dir2
clean     += clean_dir2

dir2 : $(local_objs)

.PHONY : clean_dir2
clean_dir2 :
        rm $(local_objs)


Shell command

make -f SmallPrjMain.mk clean_all --debug=verbose

____________________________________________________________
_____
Catch all the cricketing action right here. Live score,
match reports, 
photos et al. 
http://content.msn.co.in/Sports/Cricket/Default.aspx



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

Re: trouble cleaning the right files ..
user name
2007-06-18 05:22:47
On 6/18/07, sharan basappa <sharanbrhotmail.com> wrote:
...
> Each module make appends its clean target to clean
variable as :
> clean     += clean_dir1 .. so eventually clean_all
looks like
> clean_all : clean_dir1 clean_dir2
>
> clean_dir1 (for example) rule is :
>
> clean_dir1 :
>         rm $(local_objs)

The expansion of variables in command rules is always
deferred until
the command is run.  That doesn't take place until the
makefiles have
been completely parsed.  Ergo, unless you use a
target-specific
variable assignment, the above will use the value of
local_objs that
was last set during the parsing.  That's what's causing your
problem.

There are two solutions:
1) use target-specific variables.  Check out the info pages
for the details
    (just search for "target-specific"), but the
quick-n-dirty kludge would
   be to add something like:
        clean_dir1: local_objs := $(local_objs)
   near where the clean_dir1 target is defined and similar
with other
such targets.

2) instead of using the same variable for all the
directories, use a different
    name for each:
        local_objs_dir1 := $(subst .c,.o,$(local_src))
        dir1: $(local_objs_dir1)
        clean_dir1:
                $(RM) $(local_objs_dir1)

   That can be mostly automated using computed names:
        local_objs_$(local_dir) := $(subst
.c,.o,$(local_src))
        dir1: $(local_objs_$(local_dir))
        clean_dir1:
                $(RM) $(local_objs_$(subst clean_,,$))

   ...but that's probably only worthwhile if you factor out
that code
into a file
   that each submakefile then included.


Philip Guenther


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

Re: trouble cleaning the right files ..
country flaguser name
France
2007-06-18 06:30:13
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sharan basappa wrote:
> Each module make appends its clean target to clean
variable as :
> clean     += clean_dir1 .. so eventually clean_all
looks like
> clean_all : clean_dir1 clean_dir2
> 
> clean_dir1 (for example) rule is :
> 
> clean_dir1 :
>        rm $(local_objs)

Here's how I'd handle that:

1. I'd drop the 'clean' variable completely.

2. When I'm defining clean_dir1 I'd add

    clean: clean_dir1

So that whenever the clean target is requested clean_dir1 is
run.

3. To handle grabbing of local_objs you can either do a
target-specific
variable as Phillip has suggested, or you could grab the
state of
local_objs using a := and save it:

    clean_dir1_local_objs := $(local_objs)
    clean_dir1: ; rm $(clean_dir1_local_objs)

4. You can dispense with the clean_dir1 targets completely
by using a ::
rule for clean.  Each Makefile could just have the following
that grabs
the local_objs variable and adds commands to the clean
target.

    clean_dir1_local_objs := $(local_objs)
    clean:: ; rm $(clean_dir1_local_objs)

John.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


iD8DBQFGdmzELphrp73n/hARAtgdAJ40QmXPjaGns7aT6zDs3XM8Z3XrpwCg
2kMd
FKbsK8ItoUuvedBxuqrCs2I=
=sM17
-----END PGP SIGNATURE-----


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

[1-3]

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