Ant vs Makefiles

H

Harris L

Hi,

I am working on a project that is written in Java but it's mainly used
in Unix environments and uses Makefiles to build.

I want to develop on this project in a Windows environment and I want
to:

***Convert the Makefiles into Ant Build files***

Please note that I am not particularly familiar with either (Makefile
or Ant).

If any of you has any suggestions, pointers or references of how to do
this that it would be greatly appreciated.

Regards,
Harris
 
A

Anzime

Harris said:
Hi,

I am working on a project that is written in Java but it's mainly used
in Unix environments and uses Makefiles to build.

I want to develop on this project in a Windows environment and I want
to:

***Convert the Makefiles into Ant Build files***

Please note that I am not particularly familiar with either (Makefile
or Ant).

If any of you has any suggestions, pointers or references of how to do
this that it would be greatly appreciated.

Regards,
Harris

Figure out what the makefile(s) is/are doing, then do the same using
Ant. You'll have to read the ant docs to figure out how to use Ant.

http://ant.apache.org
 
J

Joe

Figure out what the makefile(s) is/are doing, then do the same using
Ant. You'll have to read the ant docs to figure out how to use Ant.


I laughed out loud when I read this.

What Mr Obvious is trying to say is that make and ant take two different
approaches. There isn't an automatic translator between the two (that I
know of).
 
A

Ann

Harris L said:
Hi,

I am working on a project that is written in Java but it's mainly used
in Unix environments and uses Makefiles to build.

I want to develop on this project in a Windows environment and I want
to:

***Convert the Makefiles into Ant Build files***

Please note that I am not particularly familiar with either (Makefile
or Ant).

If any of you has any suggestions, pointers or references of how to do
this that it would be greatly appreciated.

Regards,
Harris

Is there a reason/justification to use Ant? Other than 'cuz' of course.
 
S

Sudsy

Ann said:
"Harris L" <[email protected]> wrote in message


Is there a reason/justification to use Ant? Other than 'cuz' of course.

Make is a superb tool for building applications/executables in the
structured programming, *NIX environment. It properly resolves
dependencies and builds only what is needed.
It doesn't do such a good job with Java, where compilation doesn't
preclude cyclical dependencies. It doesn't incorporate the features
to handle the situation. You can jury-rig something, with bailing
wire and duct tape, but it's going to be fragile.
Ant handles the situation with aplomb, although it is saddled with
the usual criticisms (valid) about slow initial start-up.
So it's not 'just becase'. Use make if your code is C or C++. Use
ant if your code is Java.
Every tool has its place; ever try to loosen a 1/2" nut with a
screwdriver or needle nose pliers? ;-)
 
A

Ann

Sudsy said:
Make is a superb tool for building applications/executables in the
structured programming, *NIX environment. It properly resolves
dependencies and builds only what is needed.
It doesn't do such a good job with Java, where compilation doesn't
preclude cyclical dependencies. It doesn't incorporate the features
to handle the situation. You can jury-rig something, with bailing
wire and duct tape, but it's going to be fragile.
Ant handles the situation with aplomb, although it is saddled with
the usual criticisms (valid) about slow initial start-up.
So it's not 'just becase'. Use make if your code is C or C++. Use
ant if your code is Java.
Every tool has its place; ever try to loosen a 1/2" nut with a
screwdriver or needle nose pliers? ;-)
Great, then maybe you can suggest a solution for me since I am
new to Ant. I have a file that contains mostly constants. When
it changes there are a dozen other files that must be recompiled.
TIA
Ann
 
M

Mike Schilling

Ann said:
Great, then maybe you can suggest a solution for me since I am
new to Ant. I have a file that contains mostly constants. When
it changes there are a dozen other files that must be recompiled.


It's funny, but for all of its reputation as the premier build tool for
Java, Ant doesn't do thorough dependency checking. It assumes that XXX.java
is the only input to XXX.class. The only command-line tool I know of that
does a better job is jikes, which can be used with or without make (see
http://bekaffe.sourceforge.net/documentation/jikes/jikes.html#make).
 
J

Joe

Great, then maybe you can suggest a solution for me since I am
new to Ant. I have a file that contains mostly constants. When
it changes there are a dozen other files that must be recompiled.
TIA
Ann


If your constants are changing, then they aren't really constant are
they?
 
C

Christian Hvid

Anzime said:
...

Figure out what the makefile(s) is/are doing, then do the same using
Ant. You'll have to read the ant docs to figure out how to use Ant.

http://ant.apache.org

Strangely enough. I find subtle wisdom in that answer, eventhough it might
seem a bit obvious.

If you have a Java project that uses make, then it is most likely written
quite some time ago and/or it is written by someone with a C background and
a limited Java understanding. Either case you would want to completely
review your project's build process. Do not translate the make file(s)
line-by-line into a ant file.

As the poster wrote. You need to figure what the makefiles are doing (from a
top-down perspective), and then do (approximately) same thing with ant. But
be very critical of how the source code and built files are organised in the
original make environment, very likely it will be done in a way that is
uncommon and unconstructive in a Java environment.

I have pasted in a build file from one of my own projects. As an example of
some of the things you can very easily using ant. The build file compiles
sources from the src directory into classes using a classpath with all jars
in the lib directory, then packages the classes with ressources from res and
metainformation from etc into a single jar file. There is an additional test
target that runs a test class using the generated classpath.

Also beware many deployment tasks such as servlet container control and file
transfer can be automated using specialised ant tasks.

-- Christian
http://vredungmand.dk

<project name="octopod" default="dist" basedir=".">
<!-- set global properties for this build -->
<property name="project" value="lightweight"/>
<property name="src" value="src"/>
<property name="build" value="classes"/>
<property name="build.compiler" value="jikes"/>
<property name="doc" value="javadoc"/>
<property name="lib" value="lib"/>
<property name="dist" value="."/>
<property name="etc" value="etc"/>
<property name="res" value="res"/>
<property name="project-class-id" refid="project.class.id"/>

<!-- throw everything inside lib in the classpath -->

<path id="project.class.id">
<pathelement path="${classpath}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" nowarn="on">
<classpath refid="project.class.id"/>
</javac>
</target>

<target name="test" depends="dist">
<exec executable="java">
<arg line="-cp ${project}.jar:${project-class-id} test.Main"/>
</exec>
</target>

<target name="dist" depends="compile">
<mkdir dir="${dist}" />
<jar manifest="etc/manifest.mf" jarfile="${project}.jar">
<fileset dir="${build}"/>
<fileset dir="${res}"/>
</jar>
</target>

<target name="clean">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${test}"/>
</target>

<target name="javadoc">
<delete dir="${doc}"/>
<mkdir dir="${doc}"/>
<javadoc packagenames="*.*" sourcepath="${src}"
excludepackagenames="test.*" defaultexcludes="yes"
destdir="${doc}" author="true"
version="true" use="true" windowtitle="Octopod">
<doctitle><![CDATA[<h1>Octopod</h1>]]></doctitle>
<bottom><![CDATA[<i>2004 by Christian Hvid.</i>]]></bottom>
<link
href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
</javadoc>
</target>
</project>
 
A

Ann

Joe said:
If your constants are changing, then they aren't really constant are
they?

Just like Hubble's constant ;-)
(What was originally thought to be a constant actually changes
as the universe expands.)
 
S

Sudsy

Ann wrote:
Great, then maybe you can suggest a solution for me since I am
new to Ant. I have a file that contains mostly constants. When
it changes there are a dozen other files that must be recompiled.

A bit of wading through the documentation provides the answer in the
form of the dependset tag. Suppose file X.java depends on static
variables in Y.java. To force both to be recompiled when Y.java
changes, use the following:

<dependset>
<srcfilelist dir="." files="Y.java" />
<targetfilelist dir="." files="Y.class,X.class" />
</dependset>

Please refer to the javadocs for the specifics.
 
A

Ann

fantastic, tnx,
ann


Sudsy said:
Ann wrote:


A bit of wading through the documentation provides the answer in the
form of the dependset tag. Suppose file X.java depends on static
variables in Y.java. To force both to be recompiled when Y.java
changes, use the following:

<dependset>
<srcfilelist dir="." files="Y.java" />
<targetfilelist dir="." files="Y.class,X.class" />
</dependset>

Please refer to the javadocs for the specifics.
 
J

Juha Laiho

Ann said:
Great, then maybe you can suggest a solution for me since I am
new to Ant. I have a file that contains mostly constants. When
it changes there are a dozen other files that must be recompiled.

Hmm.. that sounds like a combination of a property file and a class
to me. So, if you have constant values, separate them into a property
file that is read when the class is loaded (or an instance created,
whichever suits better to the logic).

Then have a separate class (without the external data), that just
contains the dynamic behaviour you need - and have the dependent
classes call that class to get the information they need. This should
relieve you from recompiling just because a piece of "constant data"
did change - instead just modify the data and repackage/redeploy the
application.
 
A

Ann

Juha Laiho said:
Hmm.. that sounds like a combination of a property file and a class
to me. So, if you have constant values, separate them into a property
file that is read when the class is loaded (or an instance created,
whichever suits better to the logic).

Then have a separate class (without the external data), that just
contains the dynamic behaviour you need - and have the dependent
classes call that class to get the information they need. This should
relieve you from recompiling just because a piece of "constant data"
did change - instead just modify the data and repackage/redeploy the
application.
--
Tnx for the idea. Unfortunately the guy I work with made a huge fuss
about not reading any property (or other)files. And he wants all of the java
files in a single directory. He took the 'package' statements
out of some library files he wanted to use and moved them into the main
directory.
The <dependset> thing works though.
 
M

Mike Schilling

Ann said:
Tnx for the idea. Unfortunately the guy I work with made a huge fuss
about not reading any property (or other)files. And he wants all of the
java
files in a single directory. He took the 'package' statements
out of some library files he wanted to use and moved them into the main
directory.

He did what?

Do this:

First, ask him to post a question about whether this is the proper design to
comp.lang.java.programmer.

Next, buy a dustpan, so you have something to sweep up the ashes with.
 
A

Andrew Thompson

Unfortunately the guy I work with made a huge fuss
about not reading any property (or other)files. And he wants all of the java
files in a single directory. He took the 'package' statements
out of some library files he wanted to use and moved them into the main
directory.

Packaged library classes to 'default' package?
You have to *work* with this guy? Aaaaargh! :-(

Tell him he's a bozo, as a special message from me.
 
A

Ann

Andrew Thompson said:
Packaged library classes to 'default' package?
You have to *work* with this guy? Aaaaargh! :-(

Tell him he's a bozo, as a special message from me.
I'd love to. I continually pester him.
Get this: he has all his files in C:\j2sdk1.4.2\bin
because he couldn't get classpath to work and he
wants to be able to do "javac *.java"
He uses the 'it's my football' technique, so I can walk away.
But it does give me the opportunity to write some swing code.
 
S

Sudsy

Ann said:
"Andrew Thompson" <[email protected]> wrote in message

I'd love to. I continually pester him.
Get this: he has all his files in C:\j2sdk1.4.2\bin
because he couldn't get classpath to work and he
wants to be able to do "javac *.java"
He uses the 'it's my football' technique, so I can walk away.
But it does give me the opportunity to write some swing code.
<snip>

You have to appreciate Andrew's no-nonsense approach. But now it
makes more sense that you're "trying to do the right thing" by
migrating to Ant. Seriously, "javac *.java"?! Ye gods!

ps. Glad I was able to help you with the dependset tag. I didn't
know about it either until I began my excavation, but I
figured that the capability HAD to exist in some shape or
form. [I should charge for my research... ;-) ]
 
A

Ann

Sudsy said:
Ann said:
"Andrew Thompson" <[email protected]> wrote in message

I'd love to. I continually pester him.
Get this: he has all his files in C:\j2sdk1.4.2\bin
because he couldn't get classpath to work and he
wants to be able to do "javac *.java"
He uses the 'it's my football' technique, so I can walk away.
But it does give me the opportunity to write some swing code.
<snip>

You have to appreciate Andrew's no-nonsense approach. But now it
makes more sense that you're "trying to do the right thing" by
migrating to Ant. Seriously, "javac *.java"?! Ye gods!

ps. Glad I was able to help you with the dependset tag. I didn't
know about it either until I began my excavation, but I
figured that the capability HAD to exist in some shape or
form. [I should charge for my research... ;-) ]

I really appreciate your looking it up and testing it out.
Since my 'buddy' is in a different city I feel it safe to put
my version of the source in a reasonable structure and to use ant
which is very convenient.
 
B

bugbear

Mike said:
It's funny, but for all of its reputation as the premier build tool for
Java, Ant doesn't do thorough dependency checking.

It's not funny ; it's very annoying.

Whilst make is built around the concept of file-dependancies,
and has powerful tools for expressing these in general ways
(e.g. pattern dependancies), and is built around
target dependancies. Many of the commands in Ant
implement their own file dependancy functionality
(nice code architecture, I don't think).

There is a desperate kludge within ant in the "dependset"
task, but using it is verbose and ugly.

I like the platform portability of Ant, and the ability
to add (java implemented) extensions, but I'd have strongly
preferred to have retained the elegant dependancy model
of make.

Life might have been so different if Ant's author
had found a decent text editor. One of the prime motivations
seems to have been avoiding the use of tab's in the control
file!

BugBear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top