help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exception to Paul's Second Rule?


From: Robert Mecklenburg
Subject: Re: exception to Paul's Second Rule?
Date: Thu, 16 Oct 2003 14:56:02 -0600

> From: "Paul D. Smith" <address@hidden>
>
>   rm> .PRECIOUS: %.mkdir
>   rm> %.mkdir:
>   rm>         @mkdir -p $(dir $@)
>   rm>         @touch $@
>
> In this case you can just use $*.

I don't understand.  If % expands to, say out/foo (because of
%.o: %.c %.mkdir) then

   @mkdir -p $*  => @mkdir -p out/foo
   @touch $*     => @touch out/foo

This isn't what you meant.


> I don't see how this is that useful.  I prefer the very straightforward:
>
>   OBJDIR = ../../foo/bar
>   $(shell [ -d $(OBJDIR) ] || mkdir -p $(OBJDIR))
>
> The downside is directories are created which you might not need, but
> it's quite a bit simpler and more reliable.

I basically agree with you, Paul.  I've been using this approach for quite a
while (after reading your post about it).  However, if you have many source
files across many directories this can be troublesome:

# Find the source.
sources := $(shell find . -name '*.c')

# Gather the directories to create.
dirs := $(sort $(dir $(sources)))

# Create them
$(shell for d in $(dirs); do [ -d $$d ] || mkdir -p $$d; done)
# or
$(foreach d,$(dirs),$(shell [ -d $$d ] || mkdir -p $$d))
# of
$(foreach d,$(dirs),$(if $(wildcard $d),,$(shell mkdir -p $$d)))

Again, untested ;-)

Cheers,
Robert





reply via email to

[Prev in Thread] Current Thread [Next in Thread]