1

I am attempting to use an Ant build script to build a project that already has nmake (Visual Studio) build scripts. Rather than redo the entire build script, I would like to have Ant reuse the existing scripts.

So, I have something like this which works for Windows Mobile 6 ARMV4I builds:

<project ...>
  <target name="-BUILD.XML-COMPILE" depends="-init, -pre-compile">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg line='"${g.path.project}\build-wm6-armv4i.bat"'/>
    </exec>
    <antcall target="-post-compile" inheritall="true" inheritrefs="true" />
  </target>
</project>

But I would also like it to work for other platforms like Win32 x86 and Windows CE6 x86.

How can I have the Ant script discriminate which batch file it should execute to perform the build?

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
PaulH
  • 7,759
  • 8
  • 66
  • 143
  • Do you want the build to detect the environment it's running on and pick the nmake build script according to that, or do you just want to pass in the nmake file name as a parameter ? – gareth_bowles Sep 07 '12 at 18:53
  • I want to call a different batch file if a different target is specified. – PaulH Sep 07 '12 at 19:02

1 Answers1

1

The <os> condition may be used to set properties based on the operating system and the hardware architecture. Targets may be conditionally executed using the if and unless attributes.

<?xml version="1.0" encoding="UTF-8"?>
<project name="build" basedir="." default="BUILD.XML-COMPILE">

  <condition property="Win32-x86">
    <and>
      <os family="windows" />
      <or>
        <os arch="i386" />
        <os arch="x86" />
      </or>
    </and>
  </condition>

  <condition property="Win-ARMv4">
    <os family="windows" arch="armv4" />
  </condition>


  <target name="-BUILD.XML-COMPILE_Win-ARMv4" if="Win-ARMv4" 
      depends="-init, -pre-compile">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg line='"${g.path.project}\build-wm6-armv4i.bat"'/>
    </exec>
    <antcall target="-post-compile" inheritall="true" inheritrefs="true" />
  </target>

  <target name="-BUILD.XML-COMPILE_Win32-x86" if="Win32-x86"
      depends="-init, -pre-compile">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg line='"${g.path.project}\build-win32-x86.bat"'/>
    </exec>
    <antcall target="-post-compile" inheritall="true" inheritrefs="true" />
  </target>

  <!-- Execute the correct target automatically based on current platform. -->
  <target name="BUILD.XML-COMPILE"
      depends="-BUILD.XML-COMPILE_Win-ARMv4,
               -BUILD.XML-COMPILE_Win32-x86" />
</project>

The paths to the batch files are both single and double quoted so that file paths with spaces will not break the script. I have not tested this script on Windows Mobile 6 ARMV4I, so you will want to use the Ant target below to verify the name.

<target name="echo-os-name-arch-version">
  <echo message="OS Name is:         ${os.name}" />
  <echo message="OS Architecture is: ${os.arch}" />
  <echo message="OS Version is:      ${os.version}" />
</target> 

Related stack overflow questions:

Community
  • 1
  • 1
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117