help-make
[Top][All Lists]
Advanced

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

RE: Expanding variables as part of function arguments


From: Anthony Penniston
Subject: RE: Expanding variables as part of function arguments
Date: Wed, 9 Jun 2010 04:29:01 -0400

I see; similar to the limitations preventing function calls like "$($(func) 
$(args))" (although it would be a nice feature to have). Indeed, most suffixes 
will be .o, though I have a few others and the goal was to be able to add 
sources/objects with minimal updating of the makefile, i.e.:

SRCEXT := .c .p .def .java
OBJEXT := .o .o .dll .class

>From this, the dependency list for the main target could be updated easily 
>from files that match OBJEXT (i.e. "foo.o bar.o baz.dll fred.class").

The only way I can think to achieve this now is to define OBJ as:
OBJ = $(patsubst 
$(1),$(2),$(wildcard $(addprefix $(SRC)/*,$(SRCEXT))))
Then join the list as before, but using subst to split on commas and pass 
$(firstword, $(lastword as arguments $(1) and $(2) to $(call.
But this seems overly obtuse, and I can't help but feel I'm forcing an 
unnatural solution. Basically, I have certain source files in /src that I want 
to pull into the build with minimal editing of the makefile. These mostly 
depend on extension type and most have generic rules for building. Is there a 
better way to go about this than the above approach?


----------------------------------------
> Subject: Re: Expanding variables as part of function arguments
> From: address@hidden
> To: address@hidden
> CC: address@hidden
> Date: Wed, 9 Jun 2010 02:30:29 -0400
>
> On Wed, 2010-06-09 at 00:05 -0400, Anthony Penniston wrote:
>> Hello,
>> I need to expand a variable as an argument to patsubst, as in the following 
>> code snippet:
>>
>> SRC := src
>> SRCEXT := .c .cpp
>> OBJEXT := .o .o
>> comma := ,
>> SUB = $(join $(addsuffix $(comma),$(addprefix %%,$(SRCEXT))),$(addprefix 
>> %%,$(OBJEXT)))
>> OBJ = $(patsubst $(SUB),$(wildcard $(addprefix $(SRC)/*,$(SRCEXT))))
>
> Commas have to be "top-level" tokens. The arguments to a function are
> parsed BEFORE they are expanded, so the comma separating an argument
> cannot appear inside a variable.
>
> Assuming the suffix is always the same (.o), why not just use:
>
> SRCFILES := foo.c bar.c baz.cpp
> OBJFILES := $(addsuffix .o,$(basename $(SRCFILES))
>
> --
> -------------------------------------------------------------------------------
> Paul D. Smith  Find some GNU make tips at:
> http://www.gnu.org http://make.mad-scientist.net
> "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
>
                                          
_________________________________________________________________
Turn down-time into play-time with Messenger games
http://go.microsoft.com/?linkid=9734385


reply via email to

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