ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: How to generate a C header file using ANT?
Date Tue, 21 Oct 2003 22:37:11 GMT
> From: []
> Hello:
> I am trying to integrate versioning into our build process and I am
> looking for a way to have ANT generate a C header file as one of its
> targets.  Is there any built-in functionality I can use to do this?
> I was looking at the XSTL but I am not familiar with this enough to know
> if it will work.  What I would like to do is create some #define
> statements in a C header file using ANT properties.
> Can this be done or would I need to create a task for this?

There are many ways to do something like that. As you wrote yourself, XSL is
one way. But it sounds like a simple textual solution could work for you.
Below is an example that uses Ant-Contrib's <outofdate> with Ant 1.6 to
generate some header files (for many different libraries) by simply doing an
<echo>. It's simple, and still gives you access to Ant property expansion.

My use case though never wants to update the generated file, just create
them if missing. You might remove them and regenerate them all the time, but
that would force unnecessary compiles of any C/C++ file including that
header (assuming you have perfect dependency management by using CppTasks
like me ;-)

You could also using <replaceregex> to 'edit' your build file with a new
version number. Again, beware of the effect to having to recompile
everything that includes the generated headers. It might actually be better
to generate an impl file (C or C++) that returns the version number, rather
than a header!

I hope this gets you started. --DD

<project xmlns="ant:core"

  <target name="generate-headers">
      <sourcefiles />
        <pathelement location=".../_undefs.h" />
        <pathelement location=".../_defines.h" />
        <echo>Generating .../_undefs.h...</echo>
        <echo file=".../_undefs.h">
#ifndef ${}__undefs_h
#define ${}__undefs_h
        <echo>Generating .../_defines.h...</echo>
        <echo file=".../_defines.h">
#ifndef ${}__defines_h
#define ${}__defines_h


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message