Dear Sir/Madam,

Let me specify what I did with the windows 32 version of gnu make utility.

I want to use make to compile some inter-related java codes.  You know, java
name space is based on directory.  So I have some files under one directory,
some files under another.  The output class files will be under other different
directories.  This is the root cause for the whole problem here.

What I did is essentially as following:

1.  I have created a HelloWorld.java file under d:\sub1.
2.  I want to compile the HelloWorld.java into d:\sub2\HelloWorld.class with the
following command:
    javac -d d:\sub2 d:\sub1\HelloWorld.java
3.  I created a Makefile to accomplish step 2.  Here is the content of Makefile.

    VPATH=d:\sub1;d:\sub2
    %.class:%.java
        javac -d d:\sub2 $<

    HelloWorld.class:HelloWorld.java

This Makefile file resides at d:\sub1.  When I executed make from d:\sub1,
everything works fine.  If there is no HelloWorld.class at d:\sub2, the output
from make is:

    javac -d d:\sub2 HelloWorld.java

which means that make is executing the "    javac -d d:\sub2 $<" command.

If there is a HelloWorld.class file at d:\sub2, the output from make is:

    make: `d:\sub2/HelloWorld.class' is up to date.

which means that the target is up to date.  But if you look at the output, the
problem I want to talk about already appeared.  You have
"d:\sub2/HelloWorld.class", which is not a valid path for either unix or
windows.  This problem posed a fatal threat when I tried to do the following
thing:  I want to execute make from d:\ instead of d:\sub1.  Basically I execute
the make with parameters:

    make -f d:\sub1\Makefile

Here is the output from the execution (I have removed the HelloWorld.class file
from d:\sub2 if it exists):

    javac -d d:\sub2 d:\sub1/HelloWorld.java
    d:\sub1/HelloWorld.java:1: Public class HelloWorld must be defined in a file
called "HelloWorld.java".
    public class HelloWorld{
                 ^
    1 error
    make: *** [HelloWorld.class] Error 1

Basically, make is passing an invalid path "d:\sub1/HelloWorld.java" to the
javac compiler.  As I said before, it is impossible to put all java files under
one directory.  Thus I can not avoid the above scenario.

I think the problem lies in the return of the make's search-path algorithm.  I
specified VPATH=d:\sub1;d:\sub2 in the Makefile.  The make utility will first
look for a HelloWorld.java under current directory, which is d:\ under the above
scenario.  If make can not find the file, it looks at all the directories in the
VPATH.  Bingo.  It found the file at d:\sub1.  It needs to append the file name
to the path to form the "$<" parameter to the "javac -d d:\sub2 $<" command. 
Something was not correct with that functionality.  Instead of forming a
"d:\sub1\HelloWorld.java", it formed a "d:\sub1/HelloWorld.java", which is not
acceptable to javac compiler.

I hope that will help your pinpoint of the problem code!  Let me know if you
have any questions!


Thanks!
Tianmiao Hu

Reply via email to