You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by peter reilly <pe...@corvil.com> on 2003/03/07 18:07:33 UTC

A couple of usefull tasks

Included is a couple of useful tasks. I am currently moving
a load of makefiles to ant and found that there were a number
of make targets like:

generated.h generated.cpp : mib.mib ../include/common.h
    mibgen -i ../include mib.mib -c generated.cpp
    mibgen -i ../include mib.mib -h generated.h

In other words multiple targets depend on multiple sources.
This is possible to do in ant with uptodate and exec or script, however
it is not nice.

The two tasks I use are outoutdate and shellscript. Shellscript is
a modification of a task submitted to ant-contrib by stephan beal (sgbeal)
patch number 547018 (modified to use a temp file and not a fixed file)
and outofdate is a modification of uptodate which allows multible targets
and contains an embedded do element.

Using these tasks the make extract above can be encoded as (assuming
defines for gen.dir, include.dir and mib.dir):

<outofdate>
    <targetfile name="${gen.dir}/generated.h"/>
    <targetfile name="${gen.dir}/generated.cpp"/>
    <srcfile name="${mib.dir}/mib.mib"/>
    <srcfile name="${include.dir}/common.h"/>
    <do>
        <shellscript shell="bash">
                mibgen -i ../include mib.mib -c generated.cpp
                mibgen -i ../include mib.mib -h generated.h
       </shellscript>
    </do>
</outofdate>

This is a bit more verbose than the make extract, but it is quite
easy to understand.

Peter