<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  

  <PropertyGroup>
    <CopyBuildOutputToOutputDirectory>False</CopyBuildOutputToOutputDirectory>
    <DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
    <ImplicitlyExpandDesignTimeFacades>False</ImplicitlyExpandDesignTimeFacades>
    <ImplicitlyExpandNETStandardFacades>False</ImplicitlyExpandNETStandardFacades>
    <DesignTimeBuild>True</DesignTimeBuild>
    <ProjectAssetsFile>NULL</ProjectAssetsFile>
    <NoStdLib>true</NoStdLib>
  </PropertyGroup>

  <PropertyGroup>
    <CosmosDir Condition="$(CosmosDir) == ''">$(AppData)\Cosmos User Kit</CosmosDir>
    <BuildToolsDir Condition="$(BuildToolsDir) == ''">$(CosmosDir)\Build\Tools</BuildToolsDir>
    <VSIPDir Condition="$(VSIPDir) == ''">$(CosmosDir)\Build\VSIP</VSIPDir>
    <NasmFile Condition="'$(NasmFile)' == ''">$(BuildToolsDir)\Nasm\nasm.exe</NasmFile>
    <PlatformTarget Condition="'$(PlatformTarget)' == ''">AnyCPU</PlatformTarget>
    <BinFormat Condition="$(BinFormat) == ''">bin</BinFormat>
    <CosmosBuildTaskAssemblyFile Condition="'$(CosmosBuildTaskAssemblyFile)' == ''">$(VSIPDir)\Cosmos.Build.MSBuild.dll</CosmosBuildTaskAssemblyFile>
    <AssemblySearchPaths>$(CosmosDir)\Kernel</AssemblySearchPaths>
    <!--
    <CosmosKernelAssembly>$(OutDir)$(TargetName)$(TargetExt)</CosmosKernelAssembly>
    -->
  </PropertyGroup>

  <ItemGroup Condition="$(KernelPkg) == ''">
    <Reference Include="Cosmos.Core_Asm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.Core_Plugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.Debug.Kernel.Plugs.Asm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.System2_Plugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Remove="System.Core" />
  </ItemGroup>
  <ItemGroup Condition="$(KernelPkg) == 'X86'">
    <Reference Include="Cosmos.CPU.x86, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.CPU_Asm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.CPU_Plugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.Debug.Kernel.Plugs.Asm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.Platform.PC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
    <Reference Include="Cosmos.Plugs.TapRoot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
  </ItemGroup>

  <UsingTask TaskName="TheRingMaster" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="IL2CPU" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="NAsm" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="MakeISO" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="Ld" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="ReadNAsmMapToDebugInfo" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
  <UsingTask TaskName="ExtractMapFromElfFile" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>

  <Target Name="CoreCompile">
    <Error Text="The Release configuration isn't currently supported!" Condition="$(Configuration) == 'Release'" />
    <Error Text="File %(Compile.Identity) is set to compile, but .Cosmos projects don't compile any source themselves!" Condition="$(Compile) != ''"/>
    <CreateProperty Value="true" Condition="$(BinFormat) == 'elf'">
      <Output PropertyName="IsELF" TaskParameter="Value"/>
    </CreateProperty>
    <CreateProperty Value="false" Condition="$(BinFormat) == 'bin'">
      <Output PropertyName="IsELF" TaskParameter="Value"/>
    </CreateProperty>

    <!--
    <CreateProperty Value="%(ReferencePath.Identity)" Condition="%(ReferencePath)">
      <Output PropertyName="CosmosKernelAssembly" TaskParameter="Value"/>
    </CreateProperty>
    -->
    
    <!--
    <TheRingMaster AssemblyPath="$(CosmosKernelAssembly)" WorkingDir="$(TargetDir)" Condition="$(KernelPkg) == 'X86'" />
    -->
    <IL2CPU KernelPkg="$(KernelPkg)" DebugMode="$(DebugMode)" DebugEnabled="$(DebugEnabled)" StackCorruptionDetectionEnabled="$(StackCorruptionDetectionEnabled)" StackCorruptionDetectionLevel="$(StackCorruptionDetectionLevel)" TraceAssemblies="$(TraceAssemblies)" IgnoreDebugStubAttribute="$(IgnoreDebugStubAttribute)" DebugCom="1" References="@(ReferencePath)" AssemblySearchDirs="$(AssemblySearchPaths)" OutputFilename="$(TargetDir)$(MSBuildProjectName).asm" EnableLogging="true" EmitDebugSymbols="$(DebugSymbols)" CosmosBuildDir="$(CosmosDir)\Build" WorkingDir="$(TargetDir)"/>
    <NAsm InputFile="$(TargetDir)$(MSBuildProjectName).asm" OutputFile="$(TargetDir)$(MSBuildProjectName).obj" IsELF="$(IsELF)" ExePath="$(NasmFile)"/>
    <!-- ELF only -->
    <!-- 16 MB 0x1000000 as per hpa (syslinux) is a good spot. For now just put some dummy values. 16 and 32 MB. Later size better. -->
    <Ld CosmosBuildDir="$(CosmosDir)\Build" WorkingDir="$(TargetDir)" Arguments="-Ttext 0x2000000 -Tdata 0x1000000 -e Kernel_Start -o '$(TargetDir)$(MSBuildProjectName).bin' '$(TargetDir)$(MSBuildProjectName).obj'" Condition="$(IsELF) == 'true'"/>
    <ExtractMapFromElfFile InputFile="$(TargetDir)$(MSBuildProjectName).bin" DebugInfoFile="$(TargetDir)$(MSBuildProjectName).cdb" WorkingDir="$(TargetDir)" CosmosBuildDir="$(CosmosDir)\Build" Condition="$(IsELF) == 'true'"/>
    <CreateItem Include="$(TargetDir)$(MSBuildProjectName).bin" Condition="$(IsELF) == 'true'">
      <Output TaskParameter="Include" ItemName="TempFilesToCopy"/>
    </CreateItem>
    <!--End of ELF only-->
    <!--binary only-->
    <ReadNAsmMapToDebugInfo InputBaseDir="$(TargetDir)" DebugInfoFile="$(TargetDir)$(MSBuildProjectName).cdb" Condition="$(IsELF) == 'false'"/>
    <Move SourceFiles="$(TargetDir)$(MSBuildProjectName).obj" DestinationFiles="$(TargetDir)$(MSBuildProjectName).bin" Condition="$(IsELF) == 'false'"/>
    <!--end of binary only-->
    <!-- We dont build ISO in MSBuild any more because not all targets need it and it takes time. But we do delete it, so we dont have out of date outputs. -->
    <!-- <MakeISO InputFile="$(TargetDir)$(MSBuildProjectName).bin" OutputFile="$(TargetDir)$(MSBuildProjectName).iso" CosmosBuildDir="$(CosmosDir)\Build" /> -->
    <Delete Files="$(TargetDir)$(MSBuildProjectName).iso"/>
  </Target>

  <Target Name="CreateManifestResourceNames" />

</Project>
