[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trying to get rid of one redundand rule
From: |
John Graham-Cumming |
Subject: |
Re: Trying to get rid of one redundand rule |
Date: |
Tue, 14 Jun 2005 11:54:35 -0400 |
On Tue, 2005-06-14 at 10:18 +0200, address@hidden wrote:
> I have most of my .cpp files in $(SRCDIR), but there are
> also 2 files being generated by yacc/lex into $(BLDDIR).
>
> My problem: even though I list both $(SRCDIR) and $(BLDDIR) in the VPATH,
> I still have to list a separate rule to compile those 2 files:
>
> $(BLDDIR)/%.o: %.cpp
> $(CXX) $(CXXFLAGS) -D __LINUX__ -I $(INCDIR) -I $(BLDDIR) -c $< -o $@
>
> %.o: %.cpp
> $(CXX) $(CXXFLAGS) -D __LINUX__ -I $(INCDIR) -I $(BLDDIR) -c $< -o $@
>
> If I remove the 2nd rule above, then the generated files ../build/rcompl.cpp
> and ../build/rcomp.cpp won't compile because the implicit rule is missing
> the "-I"s. (Please see the output at very bottom demonstrating that)
>
> Does anybody please have an idea, how to better organize my Makefile?
>
> I've also tried without the VPATH ( prefixed the $(SOURCE) and $(GENSRC)
> files with $(SRCDIR) and $(BLDDIR) but that didn't help - I still needed
> the %.o:%.cpp rule )
Here's a simplified Makefile to work from:
all: obj/foo.z
vpath %.y obj
obj/%.z: %.y
@echo Making $@ from $<
obj/foo.y: src/foo.x
@echo Making $@ from $<
It builds an intermediate file obj/foo.y from something in the src
directory (src/foo.x) and then uses a pattern rule to build obj/foo.z
from obj/foo.y. And here's the output:
Making obj/foo.y from src/foo.x
Making obj/foo.z from obj/foo.y
This simulates your situation of the lex rule and it seems to work fine.
I believe the problem you are seeing is that the %.o : %.cpp rule that
is defined automatically by GNU Make is taking precedence. Try doing
one of the following:
1. Run GNU Make with -r
2. Or add as the first line of your Makefile
%.o : %.cpp
John.
--
John Graham-Cumming
Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/