help-make
[Top][All Lists]
Advanced

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

Re: using $(patsubst) and $(shell) together


From: Paul D. Smith
Subject: Re: using $(patsubst) and $(shell) together
Date: Sat, 23 Nov 2002 17:13:06 -0500

%% Nehal Mistry <address@hidden> writes:

  nm> i have a variable:
   
  nm>     OBJ = src/ai/ai_magic.o src/ai/ai_plan.o

  nm> and so on... i want to convert it so that there is an '/obj'
  nm> between the basename and dirname... so it would be:

  nm>     OBJ_2 = src/ai/obj/ai_magic.o src/ai/obj/ai_plan.o

  nm> so i tried doing this, but it did not work:

  nm>     OBJ_2 = $(patsubst %, $(shell dirname %)/obj/$(shell basename %), 
$(OBJ))

Ouch.  First, using $(shell ...) like this is very inefficient; it
starts a new subshell for each invocation.

Second, you can't do this because make expands from the inside out: that
is, the arguments are expanded _first_, _then_ the pattern substitution
is performed on the results.

That means that the pattern in $(shell dirname %) is not replaced until
_after_ the function is run, not before.

  nm> i think dirname and basename are not converting % correctly.
  nm> can someone help me out please

How about this:

  OBJ_2 = $(join $(addsuffix obj/,$(dir $(OBJ))),$(notdir $(OBJ)))

?

-- 
-------------------------------------------------------------------------------
 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]