help-make
[Top][All Lists]
Advanced

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

Re: pattern-specific variables in target names?


From: John Graham-Cumming
Subject: Re: pattern-specific variables in target names?
Date: Mon, 31 Jan 2005 17:27:37 -0500

On Mon, 2005-01-31 at 15:39, Rahul Jain wrote:
> I want to tweak target lists and locations for the build of two 
> different libraries in my project. I don't want to replicate all of the 
> contents of the makefile for each one. Pattern-specific variables seemed 
> like a good way to achieve this, but it seems that target names can't 
> have any dependency on pattern-specific variables. What is the best way 
> to achieve this goal?
>
> I want to have something like (of course, with far more rules, but I 
> should be able to generalize from something that works for this):
> 
> OBJDIR = bin
> 
> TARGET1 = $(OBJDIR)/foo/target.tx
> TARGET2 = $(OBJDIR)/bar/target.tx
> 
> TARGET1: PROJ = foo
> TARGET2: PROJ = bar
> 
> SRCDIR = ../src/$(PROJ)
> SRCS: $(wildcard $(SRCDIR)/*.x)
> OBJS: $($(subst $(SRCDIR),$(OBJDIR),$(SRCS)):%.x=%.o)
> 
> all: $(TARGET1) $(TARGET2)
> 
> %.tx: $(OBJS)
>     commands ...

Well, that wont work because you have a few errors in your Makefile. 
For example, when you do TARGET1: PROJ = foo you really mean $(TARGET1)
: PROJ = foo.  The other problem is that you are setting PROJ as a
variable local to $(TARGET1) but using it later in the rule for $(SRCS)
(which I think is actually a definition of a variable not a rule, did
you mean = instead of :).  Because $(SRCS): $(wildcard $(SRCDIR)/*.x) is
going to be handled at Makefile parse time (and not when the rules for
$(TARGET1) and prereqs is run, PROJ is undefined and hence SRCDIR is
../src/.

Perhaps you can just rearrange your Makefile so that all the emphasis is
on which PROJ you are building, rather than the target.

John.
-- 
John Graham-Cumming

Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/






reply via email to

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