<!--
  build.xml
  This file is part of the HandBrake source code.
  Homepage: <http://handbrake.fr>.
  It may be used under the terms of the GNU General Public License
  
  HandBrake Build Script for usage with Jenkins.
  Usage: 
    msbuild build.xml /t:Nightly
    msbuild build.xml /t:Release
  Example with code signing:
    msbuild build.xml /t:Release /p:SignThumbprint=XYZ /p:SignTimestampServer=http://time.certum.pl/
    
  Requires: libhb.dll to be in the release folder.
  
-->
<Project DefaultTargets="Nightly" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Setup -->
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform Condition="'$(Platform)'==''">x64</Platform>
  </PropertyGroup>

  <!-- Build all the main cproj files.-->
  <ItemGroup>
    <ProjectsToBuild Include="HandBrake.Interop\*proj" Exclude="$(MSBuildProjectFile)"/>
    <ProjectsToBuild Include="HandBrakeWPF\HandBrakeWPF.*proj" Exclude="$(MSBuildProjectFile)"/>
  </ItemGroup>

  <!-- Dependencies -->
  <PropertyGroup>
    <NightlyDependsOn>BuildRelease;NightlyPostBuild</NightlyDependsOn>
    <InstallDependsOn>BuildRelease;ReleasePostBuild</InstallDependsOn>
  </PropertyGroup>

  <!-- Builds /t: -->
  <Target Name="Nightly" DependsOnTargets="$(NightlyDependsOn)"/>
  <Target Name="Release" DependsOnTargets="$(InstallDependsOn)"/>

  <!-- Build All Components (WPF, Interop, Interop) -->
  <Target Name="BuildRelease">
    <MSBuild Projects ="@(ProjectsToBuild)"
             ContinueOnError ="false"
             Properties="Configuration=$(Configuration)" >
      <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>
    </MSBuild>
  </Target>

  <!-- Code Signing Configuration -->
  <PropertyGroup Condition="'$(SignToolLocation)'==''">
    <SignToolLocation>C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64\SignTool.exe</SignToolLocation>
  </PropertyGroup>

  <PropertyGroup Condition="'$(SignThumbprint)'!=''">
    <SignTimestamp  Condition="'$(SignTimestampServer)'!=''" >/t</SignTimestamp>
  </PropertyGroup>

  <!-- Post Build Events -->
  <Target Name="NightlyPostBuild">
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\Installer\MakeNightly64.nsi $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\Installer\InstallerBackground.bmp $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\handbrakepineapple.ico $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="xcopy $(MSBuildProjectDirectory)\doc $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release\doc /I /Y" />
    <Exec Command="makensis $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release\MakeNightly64.nsi" />
    <Exec Command="&quot;$(SignToolLocation)&quot; sign /sha1 $(SignThumbprint) $(SignTimestamp) $(SignTimestampServer) /v &quot;$(MSBuildProjectDirectory)\HandBrakeWPF\bin\$(Platform)\Release\*Win_GUI.exe&quot;"  Condition="'$(SignThumbprint)' != ''" />
  </Target>

  <Target Name="ReleasePostBuild">
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\Installer\Installer64.nsi $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\Installer\InstallerBackground.bmp $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="copy $(MSBuildProjectDirectory)\HandBrakeWPF\handbrakepineapple.ico $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release /Y" />
    <Exec Command="xcopy $(MSBuildProjectDirectory)\doc $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release\doc /I /Y" />
    <Exec Command="makensis $(MSBuildProjectDirectory)\HandBrakeWPF\bin\x64\Release\Installer64.nsi" />
    <Exec Command="&quot;$(SignToolLocation)&quot; sign /sha1 $(SignThumbprint) $(SignTimestamp) $(SignTimestampServer) /v &quot;$(MSBuildProjectDirectory)\HandBrakeWPF\bin\$(Platform)\Release\*Win_GUI.exe&quot;"  Condition="'$(SignThumbprint)' != ''" />
  </Target>

</Project>
