bug-make
[Top][All Lists]
Advanced

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

Re: Make ends up deleting source files


From: Paul D. Smith
Subject: Re: Make ends up deleting source files
Date: Mon, 18 Feb 2002 08:50:06 -0500

%% Krishnakumar B <address@hidden> writes:

  kb> Specifically is there any way in GNU Make to specify that if a
  kb> pattern substitute fails to replace anything, return null.

Not using variable substitution references.

  kb> If I understand what Make does now, it tries to match the longest
  kb> entry for % and ends up matching the whole name but still doesn't
  kb> find .cc and hence doesn't perform the replace. But the problem
  kb> arises because Make returns the whole % at this point even if no
  kb> match requested was found.

Certainly.  The semantics of pattern variable substitutions are that
they substitute for words that the pattern matches, and don't touch
words that the pattern does not match.

  kb> If it's not possible to change the semantics (legacy reasons et
  kb> al, though I don't know if anybody will really want this
  kb> behaviour), will it be possible to issue a warning option if a
  kb> variable pattern substitution results in a value which is the same
  kb> as the original variable ? Even something that detects such a
  kb> thing in only this specified syntactic usage is also very welcome.

No, I'm sorry, but that is not possible.  We cannot issue warnings for
behavior which is well-defined, useful, behaves exactly as described in
the manual, and is used that way on purpose.  Consider something like:

  foo: $(OBJS) $(LIBS)
        $(CC) ... $(^:lib%.a=-l%)

Here LIBS could be empty, or it could have all the libraries already in
the form -lbar.  I'm not exactly sure what you mean by "only on this
specified syntactic usage", but I'm not thrilled about adding special
cases to the code which say things like "if we're patsubst'ing for .cc
or .cpp or .c (or whatever) then give a warning".


To get exactly what you're asking for, try this:

  OBJS = $(patsubst %.cc,%.o,$(filter %.cc,$(SRC)))

But, you probably want this instead:

  OBJS = $(addsuffix .o,$(basename $(SRC)))

HTH.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "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]