ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "W. Sean Hennessy" <shenne...@goldenhourdata.com>
Subject RE: How to generate a C header file using ANT?
Date Tue, 21 Oct 2003 23:06:25 GMT
That's pretty cool..
Another common method providing a finer granularity of versioning at the file.o level
 is available using a combination of CVS keyword substitution and
 your file search utility du jour which targets a known string like 'SCMReleaseTag:'

This allows one to aggregate considerable file level version information inorder to leverage
build manifests for build
verification and validation.

Example filename.c
/* ============================
 * keyword substitution is used to brand each file.c with release info.
 * Name keyword is label assigned on checkout
 * Id keyword contains filename, version, author, etc.
 * ============================ */
#include version.h

static const char *mc_CSCI_Filename = "SCMReleaseTag:$Name$ $Id$";

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com] 
Sent: Tuesday, October 21, 2003 3:37 PM
To: 'Ant Users List'
Subject: RE: How to generate a C header file using ANT?


> 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



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


Mime
View raw message