[Top][All Lists]

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

Re: make doesn't honor -n switch plus wrong target selection

From: Paul Smith
Subject: Re: make doesn't honor -n switch plus wrong target selection
Date: Mon, 10 Sep 2007 10:09:12 -0400

Please always CC the mailing list.

On Mon, 2007-09-10 at 19:13 +0530, Jeenu V wrote:
>         Your problem is here:
>                 DIRS = $(shell ls)
> Thanks for this too. Actually I tried to get the list of directories
> with this command: 
> $(shell for i in $(ls -d */); do echo $i | sed 's#/$$##'; done)
> but was failing and had to resort to what was there in the Makefile.
> I could work it around by
> COMMAND := ls -d */ | sed s#/$$# 
> $(shell $(COMMAND))

All of these are too complicated.  All you have to do is something like

        DIRS = $(patsubst %/.,%,$(wildcard */.))

Not only is this significantly simpler BUT it's a LOT more efficient
than forking a new shell, plus a bunch of other programs like ls, sed,

However, IMO you should not do this.  A common thing people want to do
when they first start using make is to have it intuit everything about
their build environment, by using $(wildcard ...) etc. to have make find
all the things it needs to build.  In my opinion this is usually a
mistake.  It's too easy to get something wrong; someone makes a
temporary file or directory that you didn't expect and all of a sudden
your build is failing, maybe for reasons that aren't immediately

I understand the attraction of not having to change your makefile but
(again IMO) it's not worth it.  Source files should be explicitly stated
in the makefile, and if you create new ones you want to build you should
modify the makefile to add them.

In this case (subdirectories) it's a bit less clear-cut (I've created
build systems where it would automatically try to build in each
subdirectory without being explicitly told to do so, and it does work),
but still probably a useful rule to follow.

> I'm wondering why it executed the commands even with "make -n".

As I said, check out the section of the GNU make manual "How Makefiles
are Remade" in the chapter "Writing Makefiles".  That happens even if
you specify -n, because otherwise how can make know if the makefile is
correct?  If you don't understand it, let us know.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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