tags:

views:

336

answers:

8

While i'm developing in C/C++ and Java, i simply make a compile.bat script that does everything, that's fine for me. Why should i use make and why should i use ant?

+22  A: 

Suppose you have 1000 source files and change just one of them. With your .bat script you will have to recompile the lot, with make you recompile just the one that changed. This can save quite a bit (read hours on a big project) of time.

Even better, if you change one of your header files, make will re-compile only the source files that use that header.

These are the two main features that have meant make and its offspring are used for all serious software development with compiled languages.

anon
Heck, even on a one man project it's not hard to get to multiple minute clean builds on a fast machine.
dmckee
There's also the ability to support building multiple versions (debug, release, platform-specific), automate testing, installation, etc. Yes, you can do all that by rolling your own scripts, but why invent the wheel again some more?
John Bode
And if your makefile dependencies are accurate, you can do a parallel build just by typing `make -j N` where `N` is the number of jobs you want run at a time -- great speedup on a multi-core CPU.
Dan
Make recompiling only sources using a header file that changes is not completely correct: this will only work if the dependencies are resolved properly. These are usually created by a rule in the Makefile too, with something like running `gcc -E` on all source files first, writing the output to some file and including it in the Makefile. Make can handle rebuilding includes for its own Makefiles which makes this process transparent.
bluebrother
+1  A: 

For one thing, make and ant both keep track of which files have already been compiled, so it does not redo work if it isn't needed.

Christoffer Hammarström
+4  A: 

With a build file, you can automate more than just compiling your code; you can run unit tests, gather metrics, package build artifacts for deployment, and more.

An advantage, of sorts, of Ant is that it inspired tools for other platforms - NAnt for .NET, Phing for PHP. They do the same things, and work in the same way.

Grant Palin
+2  A: 

As long as you develop for yourself under Windows: suit yourself.

But if you start to develop with others Ant and Make are a standard to describe how your App is built.

Leonidas
+1: a .bat file will work *only* on Windows, a `.sh` file will work *only* on Unix (yes, I know ...). An Ant `build.xml` file will work everywhere where you can run Ant.
Joachim Sauer
+2  A: 

There may be several reasons: - because you are not the only one in the project - because somebody will have to care about the build script when you left - because a compile.bat script is not platform independent - because the policy of the project defines the build technology, e.g. for the entire enterprise

I recently read a funny article about build tools. For you only the first part may be of any interest (before the maven bashing starts)

bertolami
A: 

You gain some platform-neutrality (how can I run your batch-script on my linux-box). But more important: build-tools have support for dependency-resolution. Scripts lack this and have to build it on their own.

Say you have targets A, B and C. B and C both depend on A. In an script they call the subroutine A. If you now create a new target D, that depends on B and C, than you will execute A twice. Build-tools recognize this and execute A only once.

Because this situation is typical for task involving compiling, building a distribution, testing, building documentation etc. build-tools are useful for software-development.

Mnementh
A: 

It would be possible to use a .bat file -- or bash or another flavor of shell script -- to do everything Ant can do, I believe. But it's far easier to do many things in Ant...

  • create/move/delete files and directories
  • apply filter tokens
  • run unit tests
  • package a jar, zip, or war properly

Many projects need to do these things, in addition to compiling, when they build.

Also Ant is platform-independent, so you can collaborate with those who use other operating systems.

But why stop at Ant? Apache Maven offers even more compelling features.

Drew Wills
A: 

Make and Ant really come into their own when used with automated build systems or continuous integration.

The requirements for production builds, test builds and development builds are often different, and on a multi-person team, different developers set up their development environments in different ways.

Having a definitive build process solves the "Works on My Machine" (WOMM) problems that arise whenever the application needs to be built on a different machine from the one that it was developed on. It is the ultimate arbiter when one developer checks in code that doesn't work on another developer's machine. If the build process doesn't produce working software, then the first developer's check-in was broken. If it does produce working software then the second developer's development environment is broken - unless proven otherwise.

richj