help-make
[Top][All Lists]
Advanced

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

Dependency chain problem


From: Rick Thompson
Subject: Dependency chain problem
Date: Tue, 17 May 2005 23:06:47 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

I've spent 2 or 3 hours on this, and am getting nowhere, and would
appreciate any pointers. This is basically a more complex version of a
transformation from a Yacc source to a C source; the twist is that the
generator (ANTLR) produces multiple files of different names, some of
which are include files for other C++ sources.

ANTLR reads an input (say, G.g) and produces a number of C++ files as
output (say, X.cpp, Y.cpp, X.hpp, Y.hpp, Z.hpp). The outputs must be
compiled and linked with a test program, say test.cpp, where test.cpp
includes and so depends on X.hpp, Y.hpp, and Z.hpp. A further twist is
that there are actually 3 test programs (test, test1, test2) which must
all be made in this way.

I've given my current version below, and it sort of works, with some
problems:

----
(1) I've explicitly listed all 5 ANTLR outputs in the last rule, so the
ANTLR executable gets run 5 times, instead of once. If I replace this
rule with:

# use a pattern rule with multiple targets (10.5.1) to ensure that
# $(ANTLR) is run only once to produce all 5 output files
X.$pp Y.$pp Z.$pp : $(GRAMMAR)
        $(ANTLR) $<

then everything goes to worms, and nothing works (make complains that
there's no rule to make X.cpp; it doesn't seem to see the new rule).

-----
(2) My rule to make $(TARG_OBJS) seems to have too many dependencies: I
really just want to say that test[12].o is dependent on the
ANTLR-generated include files, but this doesn't work.

Any and all thoughts gratefully received...

Rick

------------------------------------------------------------------
# the grammar file and the outputs produced by $(ANTLR)
GRAMMAR = calc.g
A_CPP   = X.cpp Y.cpp
A_HPP   = X.hpp Y.hpp Z.hpp

# our test programs
TARGETS = test test2 test3

A_OBJS  = $(subst .cpp,.o,$(A_CPP))
TARG_OBJS = $(addsuffix .o, $(TARGETS))

.cpp.o :
        $(CC) $(CFLAGS) $< -o $@

all : $(TARGETS)

# use a static pattern rule (4.12) to match all tests
$(TARGETS) : % : %.o $(A_OBJS)
        $(CC) $< $(A_OBJS) -o $@ $(LIBDIRS) $(LIBS) 2>&1 | c++filt

# all the targets depend on ANTLR's hpp outputs
$(TARG_OBJS) : %.o : %.cpp $(A_CPP) $(A_HPP) $(GRAMMAR)
        $(CC) $(CFLAGS) $< -o $@

X.cpp Y.cpp X.hpp Y.hpp Z.hpp : $(GRAMMAR)
        $(ANTLR) $<

------------------------------------------------------------------






reply via email to

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