<project name="ANX.Framework Build" default="build" basedir="./">
  <property name="build.platform" value="Any CPU" />
  <property name="build.dir" value="../../bin" />
  <property name="build.dir.tools" value="../bin" />
  <property name="build.solution_dir" value="../" />  

  <property name="project.anx.path" value="../ANX.Framework" />
  <property name="project.anx.name" value="ANX.Framework" />

  <property name="project.anx.extended" value="false" unless="${property::exists('project.anx.extended')}" />
  <property name="project.anx.directives" value="" unless="${property::exists('project.anx.directives')}" />

  <property name="project.anxcontent.path" value="../ANX.Framework.ContentPipeline" />
  <property name="project.anxcontent.name" value="ANX.Framework.ContentPipeline" />

  <!-- dont change the following flags... set 'em by calling the appropriate target -->
  <property name="build.configuration" value="Release" />
  <property name="project.anx.build_env" value="VS2010" />
  <property name="project.anx.platform" value="Windows" />
  <property name="project.anx.windows" value="true" />
  <property name="project.anx.linux" value="false" />
  <property name="project.anx.psvita" value="false" />
  <property name="project.anx.metro" value="false" />
  
  <target name="clean" description="Cleans all targets.">
    <delete>
      <fileset>
        <include name="../bin/**" />
        <include name="${build.dir}/${build.configuration}/installer/**" />
        <include name="${project.anx.path}/obj/**" />
        <include name="${project.anx.path.inputsystem.standard}/obj/**" />
        <include name="${project.anx.path.inputsystem.recording}/obj/**" />
        <include name="${project.anx.path.inputdevices.xinput}/obj/**" />
        <include name="${project.anx.path.inputdevices.kinect}/obj/**" />
        <include name="${project.anx.path.inputdevices.opentk}/obj/**" />
        <include name="${project.anx.path.soundsystem.xaudio}/obj/**" />
        <include name="${project.anx.path.soundsystem.openal}/obj/**" />
        <include name="${project.anx.path.rendersystem.dx10}/obj/**" />
        <include name="${project.anx.path.rendersystem.dx11}/obj/**" />
        <include name="${project.anx.path.rendersystem.gl3}/obj/**" />
        <include name="${project.anx.path.rendersystem.metro}/obj/**" />
        <include name="${project.anxcontent.path}/obj/**" />
      </fileset>
    </delete>
  </target>

  <target name="VS2010">
    <property name="project.anx.build_env" value="VS2010" />
  </target>

  <target name="VS2011">
    <property name="project.anx.build_env" value="VS2011" />
  </target>

  <target name="windows">
    <property name="project.anx.windows" value="true" />
    <property name="project.anx.platform" value="Windows" />
  </target>

  <target name="linux">
    <property name="project.anx.linux" value="true" />
    <property name="project.anx.platform" value="Linux" />

    <call target="generate_project_files" />
  </target>

  <target name="psvita">
    <property name="project.anx.psvita" value="true" />
    <property name="project.anx.platform" value="PS Vita" />

    <call target="generate_project_files" />
  </target>

  <target name="metro">
    <property name="project.anx.metro" value="true" />
    <property name="project.anx.platform" value="Windows 8 / Metro" />
    <property name="build.platform" value="x86" />

    <property name="project.anx.directives" value="${project.anx.directives} WINDOWSMETRO" />
    
    <call target="generate_project_files" />
  </target>
  
  <target name="build">
    <echo message="===================================================" />
    <echo message="ANX.Framework build script" />
    <echo message="===================================================" />
    <echo message="" />
    <echo message="Build environment  : ${project.anx.build_env}" />
    <echo message="Build configuration: ${build.configuration}" />
    <echo message="Target platform    : ${project.anx.platform}" />
    <echo message="" />

    <if test="${project.anx.extended}">
      <property name="project.anx.directives" value="${project.anx.directives} XNAEXT" />
    </if>

    <echo message="Compiler directives: ${project.anx.directives}" />

    <call target="tools" />
    
    <call target="generate_stock_shaders" />
    
    <call target="anx" />
    <call target="content_pipeline" />

    <call target="inputsystem" />
    <call target="soundsystem" />
    <call target="rendersystem" />
    <call target="platformsystem" />

    <call target="samples" />
  </target>

  <target name="anx" description="Build ANX.Framework core">
    <echo message="building: ANX.Framework" />

    <exec program="msbuild.exe" >
      <arg value="/t:Build"/>
      <arg value="/p:Configuration=${build.configuration}"/>
      <arg value='/p:Platform="${build.platform}"'/>
      <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
      <arg value="/p:AllowUnsafeBlocks=true" />
      <arg value="/p:SolutionDir=${build.solution_dir}" />
      <arg value='/p:DefineConstants="${project.anx.directives}"' />
      <arg value="/clp:ErrorsOnly" />
      <arg value="/nologo" />
      <arg value="${project.anx.path}/${project.anx.name}.csproj" />
    </exec>
  </target>

  <target name="support" description="ANX.Framework supporting libraries" unless="${target::has-executed('support')}">
    <fileset id="support_files" basedir="../Support/">
      <include name="**/*.csproj" />
      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*Linux*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="support_files" basedir="../Support/">
        <include name="**/*_Linux.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="support_files" basedir="../Support/">
        <include name="**/*.PSVITA*_PSVITA.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="support_files" basedir="../Support/">
        <include name="**/*.Metro*_WindowsMetro.csproj" />
      </fileset>
    </if>
    
    <foreach item="File" property="projectFile">
      <in>
        <items refid="support_files" />
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>
  
  <target name="rendersystem" description="Build ANX.Framework InputSystems">
    <!-- default windows fileset -->
    <fileset id="rendersystem_files" basedir="../RenderSystems/">
      <include name="**/*.csproj" />
      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*Linux*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="rendersystem_files" basedir="../RenderSystems/">
        <include name="**/*GL*_Linux.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="rendersystem_files" basedir="../RenderSystems/">
        <include name="**/*.PSVITA*_PSVITA.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="rendersystem_files" basedir="../RenderSystems/">
        <include name="**/*.Metro*_WindowsMetro.csproj" />
      </fileset>
    </if>
    
    <foreach item="File" property="projectFile">
      <in>
        <items refid="rendersystem_files" />
      </in>
      <do>
        <property name="additional_directives" value="${path::get-file-name-without-extension(projectFile)}" />
        <property name="additional_directives" value="${string::replace(additional_directives, 'ANX.RenderSystem.', '')}" />
        <property name="additional_directives" value="${string::replace(additional_directives, 'Windows.', '')}" />

        <echo message="building: ${path::get-file-name-without-extension(projectFile)} (directives: ${additional_directives})" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives} ${additional_directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>

  <target name="inputsystem" description="Build ANX.Framework InputSystems">
    <!-- default windows fileset -->
    <fileset id="inputsystem_files" basedir="../InputSystems/">
      <include name="**/*.csproj" />
      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*ModernUI*.csproj" />
      <exclude name="**/*Kinect*.csproj" />
      <exclude name="**/*_Linux.csproj" />
      <exclude name="**/ANX.InputDevices.Test*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="inputsystem_files" basedir="../InputSystems/">
        <include name="**/*_Linux.csproj" />
        <exclude name="**/*Metro*.csproj" />
        <exclude name="**/*ModernUI*.csproj" />
        <exclude name="**/*Kinect*.csproj" />
        <exclude name="**/*PSVITA*.csproj" />
        <exclude name="**/*Windows*.csproj" />
        <exclude name="**/ANX.InputDevices.Test*.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="inputsystem_files" basedir="../InputSystems/">
        <include name="**/*_PSVITA.csproj" />
        <exclude name="**/*Metro*.csproj" />
        <exclude name="**/*ModernUI*.csproj" />
        <exclude name="**/*Kinect*.csproj" />
        <exclude name="**/*Windows*.csproj" />
        <exclude name="**/*Linux*.csproj" />
        <exclude name="**/*OpenTK*.csproj" />
        <exclude name="**/ANX.InputDevices.Test*.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="inputsystem_files" basedir="../InputSystems/">
        <include name="**/*ModernUI*_WindowsMetro.csproj" />
        <exclude name="**/*PsVita*.csproj" />
        <exclude name="**/*Kinect*.csproj" />
        <exclude name="**/*Linux*.csproj" />
        <exclude name="**/*OpenTK*.csproj" />
        <exclude name="**/ANX.InputDevices.Test*.csproj" />
      </fileset>
    </if>
    
    <foreach item="File" property="projectFile">
      <in>
        <items refid="inputsystem_files" />
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>
 
  <target name="soundsystem" description="Build ANX.Framework SoundSystems" depends="support">
    <!-- default windows fileset -->
    <fileset id="soundsystem_files" basedir="../SoundSystems/">
      <include name="**/*.csproj" />
      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*Linux*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="soundsystem_files" basedir="../SoundSystems/">
        <include name="**/*_Linux.csproj" />
        <exclude name="**/*Metro*.csproj" />
        <exclude name="**/*PSVITA*.csproj" />
        <exclude name="**/*Windows*.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="soundsystem_files" basedir="../SoundSystems/">
        <include name="**/*_PsVita.csproj" />
        <exclude name="**/*Metro*.csproj" />
        <exclude name="**/*Linux*.csproj" />
        <exclude name="**/*OpenAL*.csproj" />
        <exclude name="**/*Windows*.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="soundsystem_files" basedir="../SoundSystems/">
        <include name="**/*_WindowsMetro.csproj" />
        <exclude name="**/*PSVita*.csproj" />
        <exclude name="**/*Linux*.csproj" />
        <exclude name="**/*OpenAL*.csproj" />
      </fileset>
    </if>

    <foreach item="File" property="projectFile">
      <in>
        <items refid="soundsystem_files" />
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>

  <target name="platformsystem" description="Build ANX.Framework PlatformSystems">
    <!-- default windows fileset -->
    <fileset id="platformsystem_files" basedir="../PlatformSystems/">
      <include name="**/*.csproj" />
      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*Linux*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="platformsystem_files" basedir="../PlatformSystems/">
        <include name="**/*Linux*_Linux.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="platformsystem_files" basedir="../PlatformSystems/">
        <include name="**/*PsVita*_PsVita.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="platformsystem_files" basedir="../PlatformSystems/">
        <include name="**/*Metro*_WindowsMetro.csproj" />
      </fileset>
    </if>

    <foreach item="File" property="projectFile">
      <in>
        <items refid="platformsystem_files" />
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>
  
  <target name="generate_stock_shaders" description="Generate code for stock shaders" depends="tools">
    <foreach item="File" property="buildFile">
      <in>
        <items basedir="../shader/">
          <include name="**/build.xml" />
          <exclude name="**/*Metro*/build.xml" unless="${project.anx.metro}" />
        </items>
      </in>
      <do>
        <echo message="generating: ${path::get-file-name(path::get-directory-name(buildFile))}" />
        
        <exec program="../bin/${build.configuration}/sscg.exe" >
          <arg value="${buildFile}" />
          <arg value="/silent" />
        </exec>
      </do>
    </foreach>    
  </target>

  <target name="samples" description="Build ANX.Framework samples">
    <!-- default windows fileset -->
    <fileset id="sample_files" basedir="../Samples/">
      <include name="**/*.csproj" />

      <exclude name="**/*Kinect*.csproj" />

      <exclude name="**/*PSVita*.csproj" />
      <exclude name="**/*Metro*.csproj" />
      <exclude name="**/*Linux*.csproj" />
    </fileset>

    <if test="${project.anx.linux}">
      <fileset id="sample_files" basedir="../Samples/">
        <include name="**/*_Linux.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.psvita}">
      <fileset id="sample_files" basedir="../Samples/">
        <include name="**/*_PsVita.csproj" />
      </fileset>
    </if>

    <if test="${project.anx.metro}">
      <fileset id="sample_files" basedir="../Samples/">
        <include name="**/*_WindowsMetro.csproj" />
      </fileset>
    </if>

    <foreach item="File" property="projectFile">
      <in>
        <items refid="sample_files" />
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/samples/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>

  </target>

  <target name="build_tools" description="Tools supporting the build process of ANX.Framework" unless="${target::has-executed('build_tools')}">
    <foreach item="File" property="projectFile">
      <in>
        <items basedir="../Tools/">
          <include name="**/ProjectConverter.csproj" />
        </items>
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>
  </target>
  
  <!--
    TODO: "depends rendersystem" in the tools target leads to three compilations of all the rendersystems. Currently this is necessary because we have
    kind of ring dependency. To build a rendersystem we need the StockShaderCodeGenerator. This is used to embed the stock shaders into the 
    rendersystem. To compile a stock shader the rendersystem is needed because the compile methods are embedded into the rendersytem.
    
    A possible solution is:
    
    - compile render system
    - compile stock shader code generator
    - generate stock shaders
    - compile stock shader assembly
    - merge render system and stock shader assembly to one file
    
    Another possible solution is:
    
    - don't use sscg or remove rendersystem dependency from sscg
  -->
  <target name="tools" description="Build ANX.Framework tools" depends="support, rendersystem" unless="${target::has-executed('tools')}">
    <foreach item="File" property="projectFile">
      <in>
        <items basedir="../Tools/">
          <include name="**/*.csproj" />
          <exclude name="**/HLSLParser*.csproj" />
          <exclude name="**/DX11MetroShaderGenerator.csproj" />
          <exclude name="**/ProjectConverter.csproj" />

          <exclude name="**/*ANX.ContentCompiler.GUI*.csproj" if="${project.anx.metro}" />
          <exclude name="**/*ContentBuilder*.csproj" if="${project.anx.metro}" />
          <exclude name="**/*ANXStatusComparer*.csproj" if="${project.anx.metro}" />
          <exclude name="**/*StockShaderCodeGenerator*.csproj" if="${project.anx.metro}" />
          <exclude name="**/*XNBInspector*.csproj" if="${project.anx.metro}" />
        </items>
      </in>
      <do>
        <echo message="building: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="msbuild.exe" >
          <arg value="/t:Build"/>
          <arg value="/p:Configuration=${build.configuration}"/>
          <arg value='/p:Platform="${build.platform}"'/>
          <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
          <arg value="/p:AllowUnsafeBlocks=true" />
          <arg value="/p:SolutionDir=${build.solution_dir}" />
          <arg value='/p:DefineConstants="${project.anx.directives}"' />
          <arg value="/clp:ErrorsOnly" />
          <arg value="/nologo" />
          <arg value="${projectFile}" />
        </exec>
      </do>
    </foreach>

  </target>

  <target name="content_pipeline" description="Build ANX.Framework ContentPipeline extensions" depends="support">
    <echo message="building: Content.Pipeline.Extensions" />
<!--
    <exec program="msbuild.exe" >
      <arg value="/t:Build"/>
      <arg value="/p:Configuration=${build.configuration}"/>
      <arg value='/p:Platform="${build.platform}"'/>
      <arg value="/p:OutputPath=${build.dir}/${build.configuration}" />
      <arg value="/p:SolutionDir=${build.solution_dir}" />
      <arg value='/p:DefineConstants="${project.anx.directives}"' />
      <arg value="/p:AllowUnsafeBlocks=true" />
      <arg value="/clp:ErrorsOnly" />
      <arg value="/nologo" />
      <arg value="${project.anxcontent.path}/${project.anxcontent.name}.csproj" />
    </exec>
-->    
  </target>

  <target name="create_packages" description="generates all type of packages">
    <call target="create_zip_packages" />
    <call target="create_msi_packages" />
  </target>
  
  <target name="create_zip_packages" description="Generate zip package containing binaries" depends="build">
    <loadfile file="${project.anx.path}/Properties/AssemblyInfo.cs" property="assembly_version_file" />
    <regex pattern="AssemblyVersion\(.(?'assembly_version'\d+\.\d+.\d+)" input="${assembly_version_file}" />
    <property name="build.output.release_package" value="../package/${project.anx.name}-${build.configuration}-${assembly_version}.zip"/>
    
    <zip ziplevel="9" zipfile="${build.output.release_package}">
      <fileset basedir="${build.dir}/${build.configuration}/">
        <include name="*.dll" />
        <include name="*.config" />
        <include name="../../doc/license.txt" />
      </fileset>
    </zip>

  </target>

  <target name="create_msi_packages" description="Create the installer package" depends="build">
    <loadfile file="${project.anx.path}/Properties/AssemblyInfo.cs" property="assembly_version_file" />
    <regex pattern="AssemblyVersion\(.(?'assembly_version'\d+\.\d+.\d+)" input="${assembly_version_file}" />
    <property name="build.output.installer_package" value="../package/${project.anx.name}-${build.configuration}-${assembly_version}.msi"/>

    <property name="wix.dir" value="${path::combine(environment::get-variable('WIX'), 'bin')}" readonly="true" />
    <loadtasks assembly="${wix.dir}\Microsoft.Tools.WindowsInstallerXml.NAntTasks.dll" />

    <candle out="${build.dir}/${build.configuration}/installer/" exedir="${wix.dir}" extensions="WixUIExtension;WiXUtilExtension">
      <sources>
        <include name="../Installer/anx.wxs" />
      </sources>
      <defines>
        <define name="PRODUCTVERSION" value="${assembly_version}" />
      </defines>
    </candle>

    <light
      exedir="${wix.dir}"
      out="${build.output.installer_package}"
      warningsaserrors="true"
      suppressices="ICE57"
      cultures="en-us"
      extensions="WixUIExtension;WiXUtilExtension"
      rebuild="true"
      suppresspdb="true">
      <!-- Specify additional options -->
      <arg line="-fv" />
      <sources basedir="${build.dir}/${build.configuration}/installer/">
        <include name="*.wixobj" />
      </sources>
    </light>

  </target>

  <target name="generate_project_files" depends="build_tools">
    <fileset id="project_files" basedir="../">
      <include name="**/${project.anx.name}/*.csproj" />
      <include name="RenderSystems/**/*.csproj" />
      <include name="InputSystems/**/*.csproj" />
      <include name="PlatformSystems/**/*.csproj" />
      <include name="SoundSystems/**/*.csproj" />
      <include name="Samples/**/*.csproj" />
      <exclude name="**/*_Linux.csproj" />
      <exclude name="**/*_PSVita.csproj" />
      <exclude name="**/*_WindowsMetro.csproj" />

<!--
    <exclude name="Samples/**/*.csproj" if="${project.anx.metro}" />
-->
  </fileset>

    <foreach item="File" property="projectFile">
      <in>
        <items refid="project_files" />
      </in>
      <do>
        <echo message="create project file: ${path::get-file-name-without-extension(projectFile)}" />

        <exec program="${build.dir.tools}/${build.configuration}/ProjectConverter.exe" >
          <arg value="&quot;${projectFile}&quot;" />
          <arg value="/linux" if="${project.anx.linux}" />
          <arg value="/psvita" if="${project.anx.psvita}" />
          <arg value="/windowsmetro" if="${project.anx.metro}" />
        </exec>
      </do>
    </foreach>
  </target>
</project>