help-make
[Top][All Lists]
Advanced

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

Using circular dependencies in GNU make


From: Paul Hilfinger
Subject: Using circular dependencies in GNU make
Date: Fri, 18 Mar 2005 19:57:07 -0800

Folks,

GNU make considers circular dependency chains to be errors, and breaks
them at essentially arbitrary points.  It has occurred to me, however,
that there are applications in which such chains are expected and
there is a sensible way that make might handle them.  I was wondering
whether anyone else would care to comment.

In Java, when one compiles A.java, and the source contains a reference
to class B, the compiler will consult B.class, and will build it if
missing and (sometimes) rebuild it if needed.  That would seem to
introduce dependencies of .class files on other .class files.  But of
course, such dependencies are very often circular in the case of
Java (they would be in the case of C, too, if C compilers consulted .o
files rather than source files).

In general, one gets a dependency graph in which there are cliques of 
.class files.  It is actually clear what to do in such a case: 
when confronted with a clique, perform a single compilation containing
(at least) all sources corresponding to the members of the clique.

This suggests an extension to GNU make along the following lines:

    Introduce a new kind of rule that countenances circular
    dependencies. For the sake of concreteness, let's write

       TARGETS :* DEPENDENCIES

    (but I have no syntactic prejudices here).  

Now I might write:

       %.class :* %.java
           javac $(^:%.class=%.java)

which, together with a bunch of dependencies:

       a.class : b.class c.class d.class
       b.class : c.class a.class
       
seems to capture what I'm after.

Of course, the need for dependency management in Java is well known
(see JavaMake, e.g.), but it would be nice to think that GNU make 
could handle it.  

I'd appreciate anyone's comments.

Paul Hilfinger




reply via email to

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