Sayed, Irfan (Irfan) wrote:
 hi,

I went to that site but I found only main steps to use external task
such as cc.

As I am very new to Ant I don't know how to use it

so can anybody please give  me any sample build file which compiles the
c / c++ files
regards
irfan.


here you go. comes with no support options, use at own risk, etc, etc.

-steve
<?xml version="1.0" ?>
<project name="jni" default="test">

  <property environment="env"/>
  <property name ="build.dir" location="build/" />
  <property name ="generated.dir" 
      location="${build.dir}/generated" />
  <property name ="classes.dir" 
      location="${build.dir}/classes" />
  <property name ="obj.dir" 
      location="${build.dir}/obj" />
  <property name ="dist.dir" 
      location="dist" />
  <property name ="libname" 
          value="CpuInfo" />

          
  <property name ="deploy.dir"
      location="${env.JAVA_HOME}/bin" />
  <property name="headers.dir" value="src/cpp/include"/>
  <property name="build.debug" value="true"/>

  <path id="cc.classpath">
    <pathelement location="lib/cpptasks.jar"/>
  </path>
  
  <taskdef resource="cpptasks.tasks"
    classpathref="cc.classpath" 
    loaderRef="cctasks"/>
  <typedef resource="cpptasks.types"
    classpathref="cc.classpath" 
    loaderRef="cctasks"/> 
<!-- 
  <taskdef name="cc" 
    classname="net.sf.antcontrib.cpptasks.CCTask" 
    classpathref="cc.classpath" />
  <typedef name="defineset" 
    classname="net.sf.antcontrib.cpptasks.types.DefineSet" 
    classpathref="cc.classpath" />
  <typedef name="libset" 
    classname="net.sf.antcontrib.cpptasks.types.LibrarySet" 
    classpathref="cc.classpath" />
  <typedef name="linker" 
    classname="net.sf.antcontrib.cpptasks.LinkerDef"
    classpathref="cc.classpath" />
  <typedef name="compiler" 
    classname="net.sf.antcontrib.cpptasks.CompilerDef"
    classpathref="cc.classpath" />  
 -->

    

  <target name="init">
    <mkdir dir="${classes.dir}"/>
    <mkdir dir="${generated.dir}"/>
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${obj.dir}"/>
    <echo message="java.home is set to ${java.home}"/>    
    <echo message="env.JAVA_HOME is set to ${env.JAVA_HOME}"/>
    <echo message="env.INCLUDE is set to ${env.INCLUDE}"/>
    <echo>
      os.name=${os.name}
      os.arch=${os.arch}
    </echo>
    <condition property="suffix" value="dll">
      <os family="windows"/>
    </condition>
    <condition property="suffix" value="so">
      <os family="unix" />
    </condition>
    <condition property="is-unix">
      <os family="unix"/>
    </condition>
    <condition property="is-linux">
      <os family="unix"  />
    </condition>
    <echo message="is-linux is set to ${is-linux}"/>
    <condition property="is-linux2">
      <os name="linux"  />
    </condition>     
    <echo message="is-linux2 is set to ${is-linux2}"/>
    <condition property="is-windows">
      <os family="windows"/>
    </condition>
    <echo message="is-windows is set to ${is-windows}"/>
    <fail unless="suffix" 
      message="unsupported platform"/>
    <property name ="dist.filename.nosuffix" 
        location="${dist.dir}/${libname}" />
    <property name ="dist.filename" 
        location="${dist.dir}/${libname}.${suffix}" />
    <condition property="build.debug.istrue">
      <istrue value="${build.debug}" />
    </condition>
    <defineset id="build.defines">
      <define name="DEBUG" if="build.debug.istrue" />
      <define name="RELEASE" unless="build.debug.istrue" />
    </defineset>    
    <defineset id="platform.defines">
      <define name="WINDOWS" if="is-windows" />
      <define name="LINUX" if="is-linux" />
    </defineset>
  </target>
  
  <target name="compile" depends="init" >
    <javac srcdir="src" includes="**/*.java"
      destdir="${classes.dir}"/>
  </target>
  
  
  <target name="headers" depends="compile">
    <javah destdir="${generated.dir}"
      force="yes"
      classpath="${classes.dir}">
    <class name="org.example.antbook.cpu.CpuInfo"/>
    </javah>
  </target>
  
  <!-- do an MSDEV /? to get the args -->
  <target name="msdev" depends="headers">
    <exec
      executable="msdev.exe"
      failonerror="true" >
      <arg file="CpuInfo.dsw" />
      <arg value="/MAKE"/>
      <arg value="&quot;CpuInfo - Release&quot;"/>
   </exec>   
  </target>
  
  <target name="devenv" depends="headers">
    <exec
      executable="devenv.exe"
      failonerror="true" >
      <arg file="CpuInfo.sln" />
      <arg value="/build"/>
      <arg value="Release"/>
     </exec>   
  </target>
  
  <!-- nmake a generated makefile -->
  <target name="nmake" depends="headers">
    <exec
      executable="nmake.exe"
      failonerror="true" >
      <arg value="/F"/>
      <arg file="CpuInfo.mak" />
      <arg value="CFG=&quot;CpuInfo - Win32 Release&quot;"/>
     </exec>   
  </target>
  
  <!-- get the class onto the path -->
  <target name="deploy" depends="cc">
    <copy
      file="${dist.dir}/${libname}"
      todir="${deploy.dir}" />
    <echo message="deployed to ${deploy.dir}" />
  </target>
  
  <!-- run tests past the library -->
  <target name="test-old" depends="deploy">
    <junit printsummary="withOutAndErr" 
      failureproperty="tests.failed"
      fork="yes">
      <classpath>
        <pathelement location="${classes.dir}" />
        <pathelement path="${dist.dir}" />
        <pathelement path="${java.class.path}" />
      </classpath>
      <formatter type="plain" usefile="false"/>
      <test name="org.example.antbook.cpu.CpuInfoTest" />
    </junit>
    <fail if="tests.failed">Tests failed</fail>
  </target>

  <target name="test" depends="cc">
    <junit printsummary="withOutAndErr" 
      failureproperty="tests.failed"
      fork="yes">
      <sysproperty key="java.library.path" 
        value="${dist.dir}"/>
      <classpath>
        <pathelement location="${classes.dir}" />
        <pathelement path="${dist.dir}" />
        <pathelement path="${java.class.path}" />
      </classpath>
      <formatter type="plain" usefile="false"/>
      <test name="org.example.antbook.cpu.CpuInfoTest" />
    </junit>
    <fail if="tests.failed">Tests failed</fail>
  </target>  

  <!-- clean up after us -->
  <target name="clean">
    <delete file="${deploy.dir}/${libname}"/>
    <delete dir="${build.dir}"/>
    <delete dir="${dist.dir}"/>
  </target>




  <target name="declare-compilers" depends="init">
    <compiler id="studio" name="msvc">
      <compilerarg value="/G6"/>
      <compilerarg value="/W3"/>
      <compilerarg value="/Ze"/>
      <compilerarg value="/Zc:forScope" 
        if="msvc.version.is.devenv"/>
      <defineset>
        <define name="_CRTDBG_MAP_ALLOC" 
          if="build.debug.istrue"/>
      </defineset>    
    </compiler> 
    <compiler id="studio2" extends="studio">
      <compilerarg value="/Gm"/>
    </compiler>
    <linker id="nt4linker" name="msvc" 
        base="168427520">
      <linkerarg value="/version:4.0" />
    </linker>
  </target>
  
  <target name="cc" depends="cc-windows,cc-linux"/>


  <target name="cc-windows" depends="headers,declare-compilers" 
      if="is-windows" >
    <cc debug="${build.debug}"
        link="shared" 
        outfile="${dist.filename.nosuffix}" 
        objdir="${obj.dir}" 
        multithreaded="true"
        exceptions="true" >
        <compiler refid="studio2" />
        <fileset dir="src/cpp/windows" 
          includes="*.cpp"/>
        <defineset refid="build.defines"/>
        <defineset refid="platform.defines"/>
        <includepath location="${generated.dir}" />
        <sysincludepath location="${env.JAVA_HOME}/include" />       
        <sysincludepath location="${env.JAVA_HOME}/include/win32" /> 
        <linker refid="nt4linker" />
        <syslibset libs="kernel32,user32"/>
    </cc>
  </target>


  <!-- Build the .so library -->
  <target name="cc-linux" depends="headers" if="is-linux">
    <cc debug="${build.debug}"
        link="shared" 
        outfile="${dist.filename.nosuffix}" 
        objdir="${obj.dir}" 
        multithreaded="true"
        exceptions="true" >
        <compiler name="gcc"/>
        <fileset dir="src/cpp/linux"/>
        <defineset refid="build.defines"/>
        <defineset refid="platform.defines"/>
        <includepath location="${generated.dir}" />
        <sysincludepath location="${env.JAVA_HOME}/include" />       
        <sysincludepath location="${env.JAVA_HOME}/include/linux"/> 
        <linker name="gcc" />
    </cc>
  </target>
  
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to