help-make
[Top][All Lists]
Advanced

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

Re: make 3.81rc2: automatic variables strip leading "./"


From: Paul D. Smith
Subject: Re: make 3.81rc2: automatic variables strip leading "./"
Date: Thu, 30 Mar 2006 15:25:14 -0500

%% "Angel Tsankov" <address@hidden> writes:

  >> Well, I guess I don't understand what you're asking.  You'll need to be
  >> more clear or, preferably, provide a specific example.

  at> OK, here it is. Consider the following makefile:

  at> DEPENDENCIES_FROM_SOURCES = $(patsubst 
$(SOURCE_PATH)/%$(SOURCE_FILE_EXT),$(DEPENDENCY_PATH)/%$(DEPENDENCY_FILE_EXT),$(1))

  at> $(INTERMEDIATE_PATH)/%$(OBJECT_FILE_EXT): \
  at> $(SOURCE_PATH)/%$(SOURCE_FILE_EXT)   \
  at> $(DEPENDENCY_PATH)/%$(DEPENDENCY_FILE_EXT)
  at>  @$(eval DEPENDENCY_FILE := $(call DEPENDENCIES_FROM_SOURCES,$<))

  at> # On the last line "$<" is canonical. Now conisder the case when 
SOURCE_PATH is "." - DEPENDENCIES_FROM_SOURCES does not perform any 
  at> substitution, which is a problem.
  at> # In order to work around it, I consider cononizing the argument to 
DEPENDENCIES_FROM_SOURCE, e.g. like this:

Thanks.  Although for future reference, completely self-contained,
runnable examples are easier to work with.


You have a few options here, depending on your situation.  Note, none of
these are tested.

One option would be to change your DEPENDENCIES_FROM_SOURCES macro to
look like this:

  DEPENDENCIES_FROM_SOURCES = $(patsubst $(if $(filter-out 
.,$(SOURCE_PATH)),$(SOURCE_PATH)/)%$(SOURCE_FILE_EXT),$(DEPENDENCY_PATH)/%$(DEPENDENCY_FILE_EXT),$(1))

This uses $(SOURCE_PATH)/% if SOURCE_PATH is not ".", and just % if it
is.  The problem here is that in the second case it will match anything
ending in $(SOURCE_FILE_EXT) which you might not want.


Or, you could do something like this:

 DEPENDENCIES_FROM_SOURCES = $(patsubst 
$(SOURCE_PATH)/%$(SOURCE_FILE_EXT),$(DEPENDENCY_PATH)/%$(DEPENDENCY_FILE_EXT),$(patsubst
 $*$(SOURCE_FILE_EXT),$(SOURCE_PATH)/$*$(SOURCE_FILE_EXT),$(1)))

This adds back in the $(SOURCE_FILE_PATH)/ prefix if it doesn't exist,
before the "outer" patsubst gets involved.  Of course you can rearrange
this in various ways.  The problem with this is it's tied to $* which
means this macro will now only work inside a rule.

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