ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: How to generate a C header file using ANT?
Date Tue, 21 Oct 2003 22:37:11 GMT
> From: Dan.Crea@milliman.com [mailto:Dan.Crea@milliman.com]
> 
> 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"
         xmlns:ac="antlib:net.sf.antcontrib">

  <target name="generate-headers">
    <ac:outofdate>
      <sourcefiles />
      <targetfiles>
        <pathelement location=".../_undefs.h" />
        <pathelement location=".../_defines.h" />
      </targetfiles>
      <sequential>
        <echo>Generating .../_undefs.h...</echo>
        <echo file=".../_undefs.h">
#ifndef ${lib.name}__undefs_h
#define ${lib.name}__undefs_h
// NOTHING
#endif
</echo>
        <echo>Generating .../_defines.h...</echo>
        <echo file=".../_defines.h">
#ifndef ${lib.name}__defines_h
#define ${lib.name}__defines_h
// NOTHING
#endif
</echo>
      </sequential>
    </ac:outofdate>
  </target>

</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message