[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Trying to get rid of one redundand rule
From: |
Alexander.Farber |
Subject: |
Trying to get rid of one redundand rule |
Date: |
Tue, 14 Jun 2005 10:18:42 +0200 |
Hi,
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 )
CXX = g++296
YACC = bison
LEX = flex
BLDDIR = ../build
SRCDIR = ../src
INCDIR = ../inc
SOURCE = main.cpp \
array.cpp astring.cpp ccodes.cpp ctable.cpp \
datatype.cpp errorhan.cpp fileacc.cpp fileline.cpp \
indextab.cpp linklist.cpp mem.cpp \
nameidma.cpp numval.cpp rcbinstr.cpp \
rcostrm.cpp \
rcscan.cpp rcstack.cpp resource.cpp \
stack.cpp stringar.cpp structst.cpp \
unicode_compressor.cpp \
localise.cpp
GENSRC = rcompl.cpp rcomp.cpp
OBJECT = $(addprefix $(BLDDIR)/, $(notdir $(SOURCE:.cpp=.o) \
$(GENSRC:.cpp=.o)))
TARGET = $(addprefix $(BLDDIR)/, rcomp )
vpath %.cpp $(SRCDIR) $(BLDDIR)
all: $(TARGET)
$(TARGET): $(OBJECT)
$(CXX) $^ -o $@
strip $@
$(OBJECT): $(BLDDIR)/stamp $(BLDDIR)/rcomp.hpp
$(BLDDIR)/stamp:
mkdir -p $(dir $@)
touch $@
$(BLDDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -D __LINUX__ -I $(INCDIR) -I $(BLDDIR) -c $< -o $@
# HERE: is it possible to get rid of the following rule for $(GENSRC) files?
%.o: %.cpp
$(CXX) $(CXXFLAGS) -D __LINUX__ -I $(INCDIR) -I $(BLDDIR) -c $< -o $@
$(BLDDIR)/rcompl.cpp: $(SRCDIR)/rcomp.l
$(LEX) -t $< > $@
$(BLDDIR)/rcomp.cpp $(BLDDIR)/rcomp.hpp: $(SRCDIR)/rcomp.y
$(YACC) -d $< -o $(BLDDIR)/rcomp.cpp
clean:
rm -f $(GENSRC) $(OBJECT) $(TARGET) $(BLDDIR)/stamp
rm -f $(addprefix $(BLDDIR)/, $(GENSRC)) $(BLDDIR)/rcomp.hpp
-rmdir $(BLDDIR)
.PHONY: all clean
Regards
Alex
PS: Here is the output when I remove the %.o: %.cpp rule:
bolinux72:/home/afarber/src/rcomp-SymbianOS-9.2/group> gmake
mkdir -p ../build/
touch ../build/stamp
bison -d ../src/rcomp.y -o ../build/rcomp.cpp
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/main.cpp -o ../build/main.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/array.cpp -o
../build/array.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/astring.cpp -o
../build/astring.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/ccodes.cpp -o
../build/ccodes.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/ctable.cpp -o
../build/ctable.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/datatype.cpp -o
../build/datatype.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/errorhan.cpp -o
../build/errorhan.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/fileacc.cpp -o
../build/fileacc.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/fileline.cpp -o
../build/fileline.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/indextab.cpp -o
../build/indextab.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/linklist.cpp -o
../build/linklist.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/mem.cpp -o ../build/mem.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/nameidma.cpp -o
../build/nameidma.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/numval.cpp -o
../build/numval.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/rcbinstr.cpp -o
../build/rcbinstr.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/rcostrm.cpp -o
../build/rcostrm.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/rcscan.cpp -o
../build/rcscan.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/rcstack.cpp -o
../build/rcstack.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/resource.cpp -o
../build/resource.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/stack.cpp -o
../build/stack.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/stringar.cpp -o
../build/stringar.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/structst.cpp -o
../build/structst.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/unicode_compressor.cpp -o
../build/unicode_compressor.o
g++296 -D __LINUX__ -I ../inc -I ../build -c ../src/localise.cpp -o
../build/localise.o
flex -t ../src/rcomp.l > ../build/rcompl.cpp
g++296 -c -o ../build/rcompl.o ../build/rcompl.cpp
../src/rcomp.l:11:18: main.h: No such file or directory
../src/rcomp.l:12:22: structst.h: No such file or directory
../src/rcomp.l:13:20: Parser.h: No such file or directory
../src/rcomp.l:14:22: localise.h: No such file or directory
../src/rcomp.l:22:22: fileline.h: No such file or directory
../src/rcomp.l:60:22: errorhan.h: No such file or directory
gmake: *** [../build/rcompl.o] Error 1