I have a bunch of applications that are built with the same type of make rule:
apps = foo bar baz
all: $(apps)
foo: foo.o $(objects)
$(link)
bar: bar.o $(objects)
$(link)
baz: baz.o $(objects)
$(link)
If they had an extension (for example .x) I could make a pattern rule like:
%.x: %.o $(objects)
$(link)
and I wouldn't have to write out a new rule for each app.
But they don't have an extension, and I'm pretty sure that:
%: %.o $(objects)
$(link)
won't work (because it specifies that to build any file you can use this rule).
Is there anyway to specify one rule that will cover all the $(apps) build rules?
This looks like a job for a static pattern rule:
$(apps) : % : %.o $(objects)
$(link)
%: %.o $(objects)
$(link)
The above should work.
You can limit the scope of the rule by converting it into a static pattern rule, so that it is only considered for your list of targets:
$(apps) : % : %.o $(objects) # only consider this for $(apps) targets
$(link)
not an answer to what you are looking for , but a reason that might explain why such level of generic code might not yield good results. ....
static patterns rely on the presence of a stem to match and build a dependency chain. pretty much in the same manner as the implicit rules (which are used for targets that dont have any recipie.)
i see what you were trying to achive , making a generic rule that will satisfy all the target checks for object and link in your code.
something like this ::
% : % : $(rule1)
echo / generic code ;
so that it gets invoked for all apps in differnt scenarios
since you dont want to add a extension (this becomes the root of some issues ) the issue with this is that the target will get reflected in the dependency as well since there will be no way of differentiating the dependencies form the targets.
hence if you did try that i think you will get here ...
$ make -nf mk.t
mk.t:18: *** mixed implicit and static pattern rules. Stop.
:) , i will give this a try again tomorrow to see if i can get this working in a real generic way. Nice question though.
来源:https://stackoverflow.com/questions/15718653/makefile-pattern-rule-for-no-extension