1<project name="%projectName%" basedir="." default="postcompile"> 2 <!-- include the environment --> 3 <property environment="env"/> 4 <!-- output directory for temporary object files --> 5 <property name="buildDir" value="%buildDir%" /> 6 <!-- output directory for the shared library --> 7 <property name="libsDir" value="%libsDir%" /> 8 <!-- the name of the shared library --> 9 <property name="libName" value="%libName%"/> 10 <!-- the jni header jniPlatform to use --> 11 <property name="jniPlatform" value="%jniPlatform%"/> 12 <!-- the compilerPrefix for the C & C++ compilers --> 13 <property name="compilerPrefix" value="%compilerPrefix%"/> 14 <!-- the compilerSuffix for the C & C++ compilers --> 15 <property name="compilerSuffix" value="" /> 16 17 <!-- define gcc compiler, options and files to compile --> 18 <property name="gcc" value="${compilerPrefix}gcc${compilerSuffix}"/> 19 <property name="gcc-opts" value="%cFlags%"/> 20 <fileset id="gcc-files" dir="./"> 21 <exclude name="target/"/> 22 %cIncludes% 23 %cExcludes% 24 </fileset> 25 26 <!-- define g++ compiler, options and files to compile --> 27 <property name="g++" value="${compilerPrefix}g++${compilerSuffix}"/> 28 <property name="g++-opts" value="%cppFlags%"/> 29 <fileset id="g++-files" dir="./"> 30 <exclude name="target/"/> 31 %cppIncludes% 32 %cppExcludes% 33 </fileset> 34 35 <!-- define linker and options --> 36 <property name="linker" value="${compilerPrefix}g++${compilerSuffix}"/> 37 <property name="linker-opts" value="%linkerFlags%"/> 38 <property name="libraries" value="%libraries%"/> 39 40 <!-- cleans the build directory, removes all object files and shared libs --> 41 <target name="clean"> 42 <delete includeemptydirs="true" quiet="true"> 43 <fileset dir="${buildDir}"/> 44 <fileset dir="${libsDir}" includes="**/*" excludes="**/.svn"/> 45 </delete> 46 </target> 47 48 <target name="precompile"> 49 <condition property="compiler-found"> 50 <and> 51 <or> 52 <!-- Include both b/c Windows might be either --> 53 <available file="${g++}" filepath="${env.PATH}"/> 54 <available file="${g++}" filepath="${env.Path}"/> 55 </or> 56 <or> 57 <!-- Include both b/c Windows might be either --> 58 <available file="${gcc}" filepath="${env.PATH}"/> 59 <available file="${gcc}" filepath="${env.Path}"/> 60 </or> 61 </and> 62 </condition> 63 <condition property="has-compiler"> 64 <equals arg1="${compiler-found}" arg2="true"/> 65 </condition> 66 %precompile% 67 </target> 68 69 <target name="create-build-dir" depends="precompile" if="has-compiler"> 70 <!-- FIXME this is pretty nasty :/ --> 71 <copy todir="${buildDir}"> 72 <fileset refid="g++-files"/> 73 <fileset refid="gcc-files"/> 74 </copy> 75 <delete> 76 <fileset dir="${buildDir}"> 77 <include name="*"/> 78 <exclude name="*.o"/> 79 </fileset> 80 </delete> 81 </target> 82 83 <!-- compiles all C and C++ files to object files in the build directory --> 84 <target name="compile" depends="create-build-dir" if="has-compiler"> 85 <mkdir dir="${buildDir}"/> 86 <apply failonerror="true" executable="${g++}" dest="${buildDir}" verbose="true"> 87 <arg line="${g++-opts}"/> 88 <arg value="-Ijni-headers"/> 89 <arg value="-Ijni-headers/${jniPlatform}"/> 90 <arg value="-I."/> 91 %headerDirs% 92 <srcfile/> 93 <arg value="-o"/> 94 <targetfile/> 95 <fileset refid="g++-files"/> 96 <compositemapper> 97 <mapper type="glob" from="*.cpp" to="*.o"/> 98 <mapper type="glob" from="*.mm" to="*.o"/> 99 </compositemapper> 100 </apply> 101 <apply failonerror="true" executable="${gcc}" dest="${buildDir}" verbose="true"> 102 <arg line="${gcc-opts}"/> 103 <arg value="-Ijni-headers"/> 104 <arg value="-Ijni-headers/${jniPlatform}"/> 105 <arg value="-I."/> 106 %headerDirs% 107 <srcfile/> 108 <arg value="-o"/> 109 <targetfile/> 110 <fileset refid="gcc-files"/> 111 <compositemapper> 112 <mapper type="glob" from="*.c" to="*.o"/> 113 <mapper type="glob" from="*.m" to="*.o"/> 114 </compositemapper> 115 </apply> 116 </target> 117 118 <!-- links the shared library based on the previously compiled object files --> 119 <target name="link" depends="compile" if="has-compiler"> 120 <fileset dir="${buildDir}" id="objFileSet"> 121 <patternset> 122 <include name="**/*.o" /> 123 </patternset> 124 </fileset> 125 <pathconvert pathsep=" " property="objFiles" refid="objFileSet" /> 126 <mkdir dir="${libsDir}" /> 127 <exec executable="${linker}" failonerror="true" dir="${buildDir}"> 128 <arg line="${linker-opts}" /> 129 <arg value="-o" /> 130 <arg path="${libsDir}/${libName}" /> 131 <arg line="${objFiles}"/> 132 <arg line="${libraries}" /> 133 </exec> 134 </target> 135 136 <target name="postcompile" depends="link"> 137 %postcompile% 138 </target> 139</project> 140