Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javac vs Makefile problem ...

Reply
Thread Tools

javac vs Makefile problem ...

 
 
for.fun@laposte.net
Guest
Posts: n/a
 
      11-30-2005
Hi everybody,


I actually have the following problem :

I have a Java/JNI application which mixes ".h", ".cpp", ".java" (native
and regular files)
In order to compile everything easily, I did a Makefile.

I know that "javac" resolves the dependencies but because I have to
generate ".h" files from ".class", I had to include the Java
compilation in my Makefile.

To be clearer, here is my compilation chain :

javac javah CC
X.java => X.class => X.h => X.o
X.cpp


All this chain is achieved thanks to my Makefile.
It works but not as well as I expect it to.


My problem is :

1/ Consider that "Y.java" depends on "X.java"

2/ If "Y.java" is compiled later, it involves "X.java" to be compiled
again.

3/ Consequently, the modify time of "X.java" is changed so all the long
job starting from "X.class" is done again and my Makefile takes a while
....


Is there a way to disable the "javac" automatic dependency resolution
in order to completely manage it in a Makefile ?
Do you have another issue which could help me ?


Thanks in advance.

 
Reply With Quote
 
 
 
 
Adam Maass
Guest
Posts: n/a
 
      11-30-2005

<(E-Mail Removed)> wrote:
> Hi everybody,
>
>
> I actually have the following problem :
>
> I have a Java/JNI application which mixes ".h", ".cpp", ".java" (native
> and regular files)
> In order to compile everything easily, I did a Makefile.
>
> I know that "javac" resolves the dependencies but because I have to
> generate ".h" files from ".class", I had to include the Java
> compilation in my Makefile.
>
> To be clearer, here is my compilation chain :
>
> javac javah CC
> X.java => X.class => X.h => X.o
> X.cpp
>
>
> All this chain is achieved thanks to my Makefile.
> It works but not as well as I expect it to.
>
>
> My problem is :
>
> 1/ Consider that "Y.java" depends on "X.java"
>
> 2/ If "Y.java" is compiled later, it involves "X.java" to be compiled
> again.
>
> 3/ Consequently, the modify time of "X.java" is changed so all the long
> job starting from "X.class" is done again and my Makefile takes a while
> ...
>
>
> Is there a way to disable the "javac" automatic dependency resolution
> in order to completely manage it in a Makefile ?
> Do you have another issue which could help me ?
>


There is no way to disable the javac automatic dependency resolution.

However, there is a way to fix your build script so that it ends up doing
what you want:

You don't want 1 execution of javac for each .java file in your project;
instead, what you want to do is invoke javac once on *all* .java files in
your project -- all at one go. Do this first, then do the javah and
subsequent steps.

If all of your .java files live in one directory (or are contained in
subdirectories of one directory), your life is much simplified. Examine
the -sourcepath option to javac.


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-30-2005
On 30 Nov 2005 10:32:12 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote, quoted or
indirectly quoted someone who said :

>Is there a way to disable the "javac" automatic dependency resolution
>in order to completely manage it in a Makefile ?
>Do you have another issue which could help me ?


Almost no one use a makefile anymore. They use ANT to handle this,
which solves the problem in a platform-independent way.

You periodically do a clean compile (recompile the universe). Other
than than that, A depending on B won't recompile B. If B has changed
then A might get recompiled, but there are situations where A should
be recompiled, but is not. I don't know of any situation where you
get spurious recompiles.

The more common problem is failing to rebuild all jars that contain A
when A changes.

see http://mindprod.com/jgloss/ant.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-30-2005
On Wed, 30 Nov 2005 13:39:47 -0800, "Adam Maass"
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>You don't want 1 execution of javac for each .java file in your project;
>instead, what you want to do is invoke javac once on *all* .java files in
>your project -- all at one go. Do this first, then do the javah and
>subsequent steps.


ANT is clever enough to invoke JavaC only once no matter how
complicated your build script. It is at least a order of magnitude
faster than invoking Javac for each *.java file.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Jeffrey Schwab
Guest
Posts: n/a
 
      11-30-2005
Adam Maass wrote:
> <(E-Mail Removed)> wrote:
>
>>Hi everybody,
>>
>>
>>I actually have the following problem :
>>
>>I have a Java/JNI application which mixes ".h", ".cpp", ".java" (native
>>and regular files)
>>In order to compile everything easily, I did a Makefile.
>>
>>I know that "javac" resolves the dependencies but because I have to
>>generate ".h" files from ".class", I had to include the Java
>>compilation in my Makefile.
>>
>>To be clearer, here is my compilation chain :
>>
>> javac javah CC
>>X.java => X.class => X.h => X.o
>> X.cpp
>>
>>
>>All this chain is achieved thanks to my Makefile.
>>It works but not as well as I expect it to.
>>
>>
>>My problem is :
>>
>>1/ Consider that "Y.java" depends on "X.java"
>>
>>2/ If "Y.java" is compiled later, it involves "X.java" to be compiled
>>again.
>>
>>3/ Consequently, the modify time of "X.java" is changed so all the long
>>job starting from "X.class" is done again and my Makefile takes a while
>>...
>>
>>
>>Is there a way to disable the "javac" automatic dependency resolution
>>in order to completely manage it in a Makefile ?
>>Do you have another issue which could help me ?
>>

>
>
> There is no way to disable the javac automatic dependency resolution.
>
> However, there is a way to fix your build script so that it ends up doing
> what you want:
>
> You don't want 1 execution of javac for each .java file in your project;
> instead, what you want to do is invoke javac once on *all* .java files in
> your project -- all at one go. Do this first, then do the javah and
> subsequent steps.
>
> If all of your .java files live in one directory (or are contained in
> subdirectories of one directory), your life is much simplified. Examine
> the -sourcepath option to javac.


OP: Of course Adam's solution is probably optimal. Just out of
curiousity, why is the modification time of X.java changing? Compiling
a source file should not change the source's modification time.
 
Reply With Quote
 
for.fun@laposte.net
Guest
Posts: n/a
 
      12-01-2005

Jeffrey Schwab a écrit :

> >>3/ Consequently, the modify time of "X.java" is changed so all the long
> >>job starting from "X.class" is done again and my Makefile takes a while


> OP: Of course Adam's solution is probably optimal. Just out of
> curiousity, why is the modification time of X.java changing? Compiling
> a source file should not change the source's modification time.


Of course, you are right : the source Java modify time will not change.
I did a write mistake.
In facts, I meant this : 'the modify time of "X.class" is changed' and
so on ...

I had a quick look to ANT.
I understand your point of view but I am not going to use it because I
think that the Unix shell commands are powerfull and I can not work
without them.
Moreover, it is no problem installing Win32 ports of the Unix shell
commands (direct port or using Cygwin) on any system so you can run
make everywhere.
I just did it did and it works fine on Solaris and Windows XP.

The Adam Maass will work but I will not gain any performance : each
time I will touch a Java source file, everything is recompiled. I work
on a very big project and recompiling anything each time will take
hours ...

 
Reply With Quote
 
for.fun@laposte.net
Guest
Posts: n/a
 
      12-01-2005
Today, I spent some time looking for some other Java tools and I
discovered the Jikes Java compiler which is said to be compatible with
the JVM.
Moreover, Jikes allows to manually manage dependencies by generating
dependencies Makefile.

I am going to try this ...


Adam Maass a écrit :

> <(E-Mail Removed)> wrote:
> > Hi everybody,
> >
> >
> > I actually have the following problem :
> >
> > I have a Java/JNI application which mixes ".h", ".cpp", ".java" (native
> > and regular files)
> > In order to compile everything easily, I did a Makefile.
> >
> > I know that "javac" resolves the dependencies but because I have to
> > generate ".h" files from ".class", I had to include the Java
> > compilation in my Makefile.
> >
> > To be clearer, here is my compilation chain :
> >
> > javac javah CC
> > X.java => X.class => X.h => X.o
> > X.cpp
> >
> >
> > All this chain is achieved thanks to my Makefile.
> > It works but not as well as I expect it to.
> >
> >
> > My problem is :
> >
> > 1/ Consider that "Y.java" depends on "X.java"
> >
> > 2/ If "Y.java" is compiled later, it involves "X.java" to be compiled
> > again.
> >
> > 3/ Consequently, the modify time of "X.java" is changed so all the long
> > job starting from "X.class" is done again and my Makefile takes a while
> > ...
> >
> >
> > Is there a way to disable the "javac" automatic dependency resolution
> > in order to completely manage it in a Makefile ?
> > Do you have another issue which could help me ?
> >

>
> There is no way to disable the javac automatic dependency resolution.
>
> However, there is a way to fix your build script so that it ends up doing
> what you want:
>
> You don't want 1 execution of javac for each .java file in your project;
> instead, what you want to do is invoke javac once on *all* .java files in
> your project -- all at one go. Do this first, then do the javah and
> subsequent steps.
>
> If all of your .java files live in one directory (or are contained in
> subdirectories of one directory), your life is much simplified. Examine
> the -sourcepath option to javac.


 
Reply With Quote
 
Adam Maass
Guest
Posts: n/a
 
      12-02-2005

"Roedy Green" <(E-Mail Removed) > wrote:
>
> Almost no one use a makefile anymore. They use ANT [instead].
>


Not true. My current project is a combination of Ant and make; Ant exec's
make for the native portions of the project. There's good reason for
makefiles if there's no portion of the project that's Java.

If the project is pure Java (or nearly so), then I can see using Ant as
*the* build executible. Otherwise, makefiles have a lot going for them.



-- Adam Maass




 
Reply With Quote
 
Adam Maass
Guest
Posts: n/a
 
      12-02-2005

<(E-Mail Removed)> wrote:

> To be clearer, here is my compilation chain :


> javac javah CC
> X.java => X.class => X.h => X.o
> X.cpp



I suggested compiling all of the .java files to .class files at one go,
using the -sourcepath argument to javac.


> The Adam Maass will work but I will not gain any performance : each
> time I will touch a Java source file, everything is recompiled. I work
> on a very big project and recompiling anything each time will take
> hours ...



OP: try setting the dependency your X.h and X.cpp files not on X.class, but
X.java instead. That should alleviate the "recompile the world when anything
changes" problem.

-- Adam Maass


 
Reply With Quote
 
for.fun@laposte.net
Guest
Posts: n/a
 
      12-02-2005

Adam Maass a écrit :

> OP: try setting the dependency your X.h and X.cpp files not on X.class, but
> X.java instead. That should alleviate the "recompile the world when anything
> changes" problem.



Good idea. I am going to try it.
Thx Adam.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javac -encoding problem and/or glaring bug ? java Java 6 08-19-2007 11:22 AM
"com.sun.tools.javac.Main is not on the classpath" problem still there. drunken_wizard Java 1 03-23-2006 01:33 AM
Javac compilation error, problem with packages... Salil P Java 2 01-22-2005 06:18 AM
Problem with ant javac task not finding interface dependence Collin VanDyck Java 2 11-18-2004 04:13 PM
Re: Problem with ant's javac task z3 Java 0 07-23-2003 06:39 PM



Advertisments