﻿<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="DownloadLAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - DownloadLAME" />
        <WebDownload
            Condition="!Exists('$(MSBuildProjectDirectory)\_archives\$(LAME_SRC_TAR_GZ)')"
            FileUri="$(LAME_URL)/$(LAME_SRC_TAR_GZ)/download"
            FileName="$(MSBuildProjectDirectory)\_archives\$(LAME_SRC_TAR_GZ)"
            UseDefaultCredentials="True" />    
    </Target>
    <Target Name="ExtractLAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - ExtractLAME" />
        <ExtractWith7za
            Condition="!Exists('$(MSBuildProjectDirectory)\$(LAME_DIR)')"
            FileToExtract="$(MSBuildProjectDirectory)\_archives\$(LAME_SRC_TAR_GZ)" />
    </Target>
    <Target Name="PatchLAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - PatchLAME" />
        <Exec
            Condition="!Exists('$(MSBuildProjectDirectory)\$(LAME_DIR)\lame_patched')"
            Command="&quot;$(PATCH_EXE)&quot; -p1 -i &quot;$(MSBuildProjectDirectory)\patches\$(LAME_PATCH_FILE)&quot;"
            WorkingDirectory="$(MSBuildProjectDirectory)\$(LAME_DIR)" />
        <Touch
            AlwaysCreate='true'
            Files="$(MSBuildProjectDirectory)\$(LAME_DIR)\lame_patched" />
    </Target>
    <Target Name="BuildLAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - BuildLAME" />
        <Message
            Text="# Building lame.sln - Release|Win32 #" />
        <Message
            Text="-------------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame.sln"
            Properties="Configuration=Release;Platform=Win32;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame_clients.sln - Release|Win32 #" />
        <Message
            Text="---------------------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame_clients.sln"
            Properties="Configuration=Release;Platform=Win32;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame.sln - Release|x64 #" />
        <Message
            Text="-----------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame.sln"
            Properties="Configuration=Release;Platform=x64;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame_clients.sln - Release|x64 #" />
        <Message
            Text="-------------------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame_clients.sln"
            Properties="Configuration=Release;Platform=x64;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame.sln - Debug|Win32 #" />
        <Message
            Text="-----------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame.sln"
            Properties="Configuration=Debug;Platform=Win32;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame_clients.sln - Debug|Win32 #" />
        <Message
            Text="-------------------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame_clients.sln"
            Properties="Configuration=Debug;Platform=Win32;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame.sln - Debug|x64 #" />
        <Message
            Text="---------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame.sln"
            Properties="Configuration=Debug;Platform=x64;VcpkgEnabled=false"/>

        <Message
            Text="# Building lame_clients.sln - Debug|x64 #" />
        <Message
            Text="-----------------------------------------" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(LAME_DIR)\vc_solution\lame_clients.sln"
            Properties="Configuration=Debug;Platform=x64;VcpkgEnabled=false"/>
    </Target>
    <Target Name="CopyLAME">
        <ItemGroup>
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame.exe" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame.pdb" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame_acm.xml" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame_enc.dll" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lameACM.acm" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\LameACM.inf" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lameACM.pdb" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmp3lame.dll" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\mp3rtp.exe" />
            <LAME_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\mp3rtp.pdb" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame.exe" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame.pdb" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame_acm.xml" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame_enc.dll" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lameACM.acm" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\LameACM.inf" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lameACM.pdb" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmp3lame.dll" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\mp3rtp.exe" />
            <LAME_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\mp3rtp.pdb" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame.exe" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame.pdb" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame_acm.xml" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame_enc.dll" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lameACM.acm" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\LameACM.inf" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lameACM.pdb" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmp3lame.dll" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\mp3rtp.exe" />
            <LAME_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\mp3rtp.pdb" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame.exe" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame.pdb" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame_acm.xml" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame_enc.dll" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lameACM.acm" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\LameACM.inf" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lameACM.pdb" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmp3lame.dll" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\mp3rtp.exe" />
            <LAME_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\mp3rtp.pdb" />
            <LAME_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\doc\html\*.html" />
            <LAME_INCLUDE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\include\lame.h" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame_enc.lib" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\lame_enc.pdb" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmp3lame-static.lib" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmp3lame-static.pdb" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmp3lame.lib" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmp3lame.pdb" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmpghip-static.lib" />
            <LAME_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Debug\libmpghip-static.pdb" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame_enc.lib" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\lame_enc.pdb" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmp3lame-static.lib" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmp3lame-static.pdb" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmp3lame.lib" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmp3lame.pdb" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmpghip-static.lib" />
            <LAME_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x64\Release\libmpghip-static.pdb" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame_enc.lib" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\lame_enc.pdb" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmp3lame-static.lib" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmp3lame-static.pdb" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmp3lame.lib" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmp3lame.pdb" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmpghip-static.lib" />
            <LAME_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Debug\libmpghip-static.pdb" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame_enc.lib" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\lame_enc.pdb" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmp3lame-static.lib" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmp3lame-static.pdb" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmp3lame.lib" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmp3lame.pdb" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmpghip-static.lib" />
            <LAME_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\$(LAME_DIR)\build\out\x86\Release\libmpghip-static.pdb" />
        </ItemGroup>
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - CopyLAME" />
        <MakeDir
            Condition="!Exists('$(COMMON_SDKS)\docs\lame')"
            Directories="$(COMMON_SDKS)\docs\lame" />
        <MakeDir
            Condition="!Exists('$(COMMON_SDKS)\include\lame')"
            Directories="$(COMMON_SDKS)\include\lame" />
        <Copy
            SourceFiles="@(LAME_BIN_X64_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x64\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_BIN_X64_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x64\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_BIN_X86_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x86\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_BIN_X86_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x86\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_DOCS_FILES)"
            DestinationFolder="$(COMMON_SDKS)\docs\lame"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_INCLUDE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\include\lame"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_LIB_X64_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x64\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_LIB_X64_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x64\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_LIB_X86_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x86\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(LAME_LIB_X86_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x86\Release"
            SkipUnchangedFiles="true" />
    </Target>
    <Target Name="CleanLAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - CleanLAME" />
        <RemoveDir
            Condition="Exists('$(MSBuildProjectDirectory)\$(LAME_DIR)')"
            Directories="$(MSBuildProjectDirectory)\$(LAME_DIR)" />
    </Target>
    <Target Name="LAME">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - LAME" />
        <CallTarget
            Condition="!Exists('$(MSBuildProjectDirectory)\build_state\LAME_build_successful')"
            Targets="DownloadLAME;ExtractLAME;PatchLAME;BuildLAME;CopyLAME" />
        <Touch
            AlwaysCreate='true'
            Files="$(MSBuildProjectDirectory)\build_state\LAME_build_successful" />
    </Target>
</Project>
