Have recently just started using Ant, with the goal to using it as the default 
build tool across an entire project. While most of the project will be java 
based, there are a few parts that won't be and I'm trying to make ant work as 
effectively as possible for these sections.

One of them just happens to be a kernel module. While there will be a makefile 
called by the Ant target in the end, I'm trying to set Ant up as the entry 
point so that developers moving between different parts of the project will get 
the same interface and the same targets to be called. It also simplifies the 
work around a continuous build tool, in that it doesn't have to run differently 
for the different components.


For the kernel module build, I'm trying to allow for more than 1 kernel version 
and different kernel variants. In most cases the kernel version will be 
2.6.18-194.el5 (RHEL5 Update 5 kernel) and the variant will be the default. 
However at times developers will want to build against multiple kernel versions 
and/or variants when developing/debugging issues.

Examples:
Default Properties
kernel.versions = 2.6.18-194.el5
kernel.variants = ""

Additionally "kernel.${kernel.version}.variants = xxx" can be used to specify 
the variants for a particular version, rather than using the default set. I use 
"" to represent the default variant simply because that is the method that 
works best when building kmod-* rpm packages as I'm using a spec template 
similar to what fedora uses.

Properties set by a Developer
kernel.versions = 2.6.18-194.el5 2.6.33-k.org
kernel.variants = ""
kernel.2.6.18-194.el5.variants = xen



Coming from a make background I was previously used to expanding targets 
dynamically based on values set in properties in the makefile in order to 
reference multiple kernel versions and variants and then using pattern based 
rules to build the necessary target. Right now I've got something partially 
working in Ant using the foreach/for tasks from ant-contrib, but I'm not sure 
that this is the best way to accomplish this. I'm also using if/the/else to 
work around the use of "" which Ant doesn't really like when it comes to 
specifying an empty value for a property.

I know I have a bug in the xml below, in that the for loop I attempt to change 
properties which by default Ant won't overwrite after setting them initially. 
Like I mentioned before I'm very much used to make and I've yet to fully get to 
grips with Ant.


Any suggestions on other Ant tasks that could simplify this would be very 
welcome:


  <target name="compile" if="isLinux"
          description="Compile the source against all requested kernel versions 
and variants">
    <!-- determine the default kernel version, only set if not already set -->
    <exec executable="uname" outputproperty="kernel.versions">
      <arg value="-r" />
    </exec>
    <foreach target="compile-module" list="${kernel.versions}" delimiter=" " 
param="kernel.version" />
  </target>


  <!-- default compile task, restrict to running on linux also try to avoid 
rebuilding if
      it has already been compiled and the sources have not be modified.

      TODO:
        Handle if different kernel version or variants used
        Handle building for multiple variants
        Handle building for multiple kernel versions

        Compile the source against the specified kernel version and variant
  -->
  <target name="compile-module" depends="init" if="isLinux" >


    <!-- Will set the variants to the default value only if not already set 
(i.e. doesn't override) -->
    <property name="kernel.${kernel.version}.variants" 
value="${kernel.variants}" />
    <propertycopy property="kernel.currver.variants" override="true" 
from="kernel.${kernel.version}.variants" />

    <for list="${kernel.currver.variants}" param="kernel.variant" delimiter=" " 
trim="true">
      <sequential>
        <if>
          <equals arg1="@{kernel.variant}" arg2='""' />
          <then>
            <property name="dir.kernel.build" 
location="/lib/modules/${kernel.version}/build" />
            <property name="dir.module.build" 
location="${dir.build}/output/${kernel.version}" />
          </then>
          <else>
            <property name="dir.kernel.build" 
location="/lib/modules/${kernel.versi...@{kernel.variant}/build" />
            <property name="dir.module.build" 
location="${dir.build}/output/${kernel.versi...@{kernel.variant}" />
          </else>
        </if>
        <!--<property name="kernel.arch" />-->
        <echoproperties prefix="name."/>
        <echoproperties prefix="dir."/>
        <echoproperties prefix="kernel."/>
        <echo message="kernel.variant='@{kernel.variant}'" />
        <!-- Copy the src to a directory under the build directory, excluding 
hidden files -->
        <copy todir="${dir.module.build}">
          <fileset dir="${dir.src}">
            <exclude name="**/.*" />
          </fileset>
        </copy>

        <!-- execute the require make command, specifying the kernel directory 
to use -->
        <exec executable="make">
          <arg value="-C" />
          <arg value="${dir.kernel.build}" />
          <arg value="M=${dir.module.build}" />
          <arg value="modules" />
        </exec>
      </sequential>
    </for>
  </target>



--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, 
Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's 
Quay Dublin 2
Registered Number: 361933 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to