%% Laird Nelson <[EMAIL PROTECTED]> writes:
ln> I want to do this:
ln> $(CONTENTS_FILES) : %.jar.contents : %/GNUmakefile
^^^^^^^^^^^^^
I assume you mean something like $(dir %)GNUmakefile here.
ln> ...where $(CONTENTS_FILES) is something like this:
ln> package1/blah.jar.contents \
ln> package2/foobar.jar.contents
ln> ...but I can't, because % can't be used on the right side of a static
ln> pattern rule except to add to it (?!?!?!). What a very odd distinction
ln> to make.
Not odd at all, once you understand the reason. See the section (in the
newer GNU make manuals) about when variable/function expansion is
performed. Make proceeds in two distinct phases: first it reads all the
makefiles, constructing a internal representation of the dependency
graph, dictionary of rules, etc. Second, it uses that graph and
dictionary to examine and possibly try to build the targets it's been
asked about.
In the manual you'll find that expansion happens _as the makefile is
read in_ for variables and functions that appear in a target or
prerequisite list (including suffix, pattern, and static pattern rules).
However, matching and expansion of the "%" in pattern rules happens when
make invokes the rule, during runtime.
So, when make reads the makefile and sees:
% : $(dir %)/foo
it expands the function in the first phase, and runs the "dir" function
on the literal string "%", because the "%" isn't matched and expanded
until the second phase.
ln> So how come I can add with reckless abandon to % but I can't work on it
ln> with functions? This seems just wrong to me.
Because "%.GNUmakefile" doesn't have any expansion issues; there are no
variables or functions here. When make expands the "%" later it can
easily append the ".GNUmakefile" to give the result you expect.
ln> So what I'm trying to do in one command is say, hey, for all
ln> contents files in the list, each one depends on a GNUmakefile in
ln> its own directory. Any suggestions?
If you have a relatively well-known set of package directories, you can
do something like this:
$(filter package1/%,$(CONTENTS_FILES)) : package1/GNUmakefile
$(filter package2/%,$(CONTENTS_FILES)) : package2/GNUmakefile
Etc.
If you want this to be dynamic, you'll need to have a rule that
auto-creates a makefile that contains these lines based on the list of
directories in CONTENTS_FILES (you can get that easily enough), then
include that file. Then, GNU make's automatic recreation of included
files can take care of keeping it up-to-date.
If you have no idea what I'm talking about here, let me know :).
--
-------------------------------------------------------------------------------
Paul D. Smith <[EMAIL PROTECTED]> 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