<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{5391A8B1-9C70-4DC4-92AD-D3E34C6B803F}</ProjectGuid>
    <RootNamespace>luajit</RootNamespace>
  </PropertyGroup>

  <!-- Aegisub project configuration -->
  <PropertyGroup Label="AegisubConfiguration">
    <AegisubProjectType>lib</AegisubProjectType>
    <SrcDir>..\..\vendor\luajit\</SrcDir>
  </PropertyGroup>
  <ImportGroup Label="PropertySheets">
    <Import Project="$(MSBuildThisFileDirectory)..\aegisub.props" />
  </ImportGroup>

  <!-- Project specific configuration -->
  <ItemDefinitionGroup>
    <ClCompile>
      <PreprocessorDefinitions>
        _CRT_SECURE_NO_WARNINGS;
        LUAJIT_ENABLE_LUA52COMPAT;
        %(PreprocessorDefinitions)
      </PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(AegisubObjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <InstallHeader>
      <HeaderRoot>$(SrcDir)include</HeaderRoot>
    </InstallHeader>
  </ItemDefinitionGroup>

  <!-- BuildVM stuff -->
  <PropertyGroup>
    <BuildVMCommand>$(AegisubBinaryDir)luajit-buildvm$(AegisubPlatformSuffix)</BuildVMCommand>
    <BuildCompileTargets>
      BuildVM;
      ComputeLibDefNames;
      BuildLibDefs;
      $(BuildCompileTargets)
    </BuildCompileTargets>
  </PropertyGroup>
  <Target
    Name="BuildVM"
    Inputs="$(SrcDir)src\host\buildvm.c;$(SrcDir)src\lj_opt_fold.c"
    Outputs="$(AegisubObjectDir)lj_vm.obj;$(AegisubObjectDir)lj_folddef.h"
    >
    <Message Text="luajit-buildvm peobj" Importance="High" />
    <Exec Command="$(BuildVMCommand) -m peobj -o lj_vm.obj" WorkingDirectory="$(AegisubObjectDir)" />
    <Message Text="luajit-buildvm folddef" Importance="High" />
    <Exec Command="$(BuildVMCommand) -m folddef -o $(AegisubObjectDir)lj_folddef.h lj_opt_fold.c" WorkingDirectory="$(SrcDir)src" />
    <ItemGroup>
      <Lib Include="$(AegisubObjectDir)lj_vm.obj" />
    </ItemGroup>
  </Target>
  <Target Name="ComputeLibDefNames">
    <!-- To avoid having any top-level itemgroups not naming real files -->
    <ItemGroup>
      <LuajitLibDefname Include="bcdef;ffdef;libdef;recdef" />
    </ItemGroup>
  </Target>
  <Target
    Name="BuildLibDefs"
    Inputs="@(LuajitLibSource)"
    Outputs="@(LuajitLibDefname -> '$(AegisubObjectDir)lj_%(Identity).h')"
    >
    <Message Text="luajit-buildvm %(LuajitLibDefname.Identity)" Importance="High" Condition="'%(LuajitLibDefname.Identity)' != ''" />
    <Exec
      Command="$(BuildVMCommand) -m %(LuajitLibDefname.Identity) -o $(AegisubObjectDir)lj_%(LuajitLibDefname.Identity).h @(LuajitLibSource->'%(filename)%(extension)',' ')"
      WorkingDirectory="$(SrcDir)src\"
      Condition="'%(LuajitLibDefname.Identity)' != ''"
      />
  </Target>

  <!-- Source files -->
  <ItemGroup>
    <LuajitLibSource Include="$(SrcDir)src\lib_base.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_math.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_bit.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_string.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_table.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_io.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_os.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_package.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_debug.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_jit.c" />
    <LuajitLibSource Include="$(SrcDir)src\lib_ffi.c" />
  </ItemGroup>

  <ItemGroup>
    <ClCompile Include="$(SrcDir)src\ljamalg.c" />
  </ItemGroup>
  
  <ItemGroup>
    <LuajitVMSource Include="$(SrcDir)src\lj_alloc.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_api.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_asm.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_bc.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_bcread.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_bcwrite.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_carith.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_ccall.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_ccallback.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_cconv.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_cdata.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_char.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_clib.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_cparse.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_crecord.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_ctype.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_debug.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_dispatch.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_err.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_ffrecord.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_func.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_gc.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_gdbjit.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_ir.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_lex.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_lib.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_load.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_mcode.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_meta.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_obj.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_dce.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_fold.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_loop.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_mem.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_narrow.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_sink.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_opt_split.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_parse.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_record.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_snap.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_state.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_str.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_strscan.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_tab.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_trace.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_udata.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_vmevent.c" />
    <LuajitVMSource Include="$(SrcDir)src\lj_vmmath.c" />
  </ItemGroup>

  <ItemGroup>
    <InstallHeader Include="$(SrcDir)include\lauxlib.h" />
    <InstallHeader Include="$(SrcDir)include\lua.h" />
    <InstallHeader Include="$(SrcDir)include\lua.hpp" />
    <InstallHeader Include="$(SrcDir)include\luaconf.h" />
    <InstallHeader Include="$(SrcDir)include\luajit.h" />
    <InstallHeader Include="$(SrcDir)include\lualib.h" />
  </ItemGroup>

  <ItemGroup>
    <ClInclude Include="$(SrcDir)src\lj_alloc.h" />
    <ClInclude Include="$(SrcDir)src\lj_arch.h" />
    <ClInclude Include="$(SrcDir)src\lj_asm.h" />
    <ClInclude Include="$(SrcDir)src\lj_asm_arm.h" />
    <ClInclude Include="$(SrcDir)src\lj_asm_mips.h" />
    <ClInclude Include="$(SrcDir)src\lj_asm_ppc.h" />
    <ClInclude Include="$(SrcDir)src\lj_asm_x86.h" />
    <ClInclude Include="$(SrcDir)src\lj_bc.h" />
    <ClInclude Include="$(SrcDir)src\lj_bcdump.h" />
    <ClInclude Include="$(SrcDir)src\lj_carith.h" />
    <ClInclude Include="$(SrcDir)src\lj_ccall.h" />
    <ClInclude Include="$(SrcDir)src\lj_ccallback.h" />
    <ClInclude Include="$(SrcDir)src\lj_cconv.h" />
    <ClInclude Include="$(SrcDir)src\lj_cdata.h" />
    <ClInclude Include="$(SrcDir)src\lj_char.h" />
    <ClInclude Include="$(SrcDir)src\lj_clib.h" />
    <ClInclude Include="$(SrcDir)src\lj_cparse.h" />
    <ClInclude Include="$(SrcDir)src\lj_crecord.h" />
    <ClInclude Include="$(SrcDir)src\lj_ctype.h" />
    <ClInclude Include="$(SrcDir)src\lj_debug.h" />
    <ClInclude Include="$(SrcDir)src\lj_def.h" />
    <ClInclude Include="$(SrcDir)src\lj_dispatch.h" />
    <ClInclude Include="$(SrcDir)src\lj_emit_arm.h" />
    <ClInclude Include="$(SrcDir)src\lj_emit_mips.h" />
    <ClInclude Include="$(SrcDir)src\lj_emit_ppc.h" />
    <ClInclude Include="$(SrcDir)src\lj_emit_x86.h" />
    <ClInclude Include="$(SrcDir)src\lj_err.h" />
    <ClInclude Include="$(SrcDir)src\lj_errmsg.h" />
    <ClInclude Include="$(SrcDir)src\lj_ff.h" />
    <ClInclude Include="$(SrcDir)src\lj_ffrecord.h" />
    <ClInclude Include="$(SrcDir)src\lj_frame.h" />
    <ClInclude Include="$(SrcDir)src\lj_func.h" />
    <ClInclude Include="$(SrcDir)src\lj_gc.h" />
    <ClInclude Include="$(SrcDir)src\lj_gdbjit.h" />
    <ClInclude Include="$(SrcDir)src\lj_ir.h" />
    <ClInclude Include="$(SrcDir)src\lj_ircall.h" />
    <ClInclude Include="$(SrcDir)src\lj_iropt.h" />
    <ClInclude Include="$(SrcDir)src\lj_jit.h" />
    <ClInclude Include="$(SrcDir)src\lj_lex.h" />
    <ClInclude Include="$(SrcDir)src\lj_lib.h" />
    <ClInclude Include="$(SrcDir)src\lj_mcode.h" />
    <ClInclude Include="$(SrcDir)src\lj_meta.h" />
    <ClInclude Include="$(SrcDir)src\lj_obj.h" />
    <ClInclude Include="$(SrcDir)src\lj_parse.h" />
    <ClInclude Include="$(SrcDir)src\lj_record.h" />
    <ClInclude Include="$(SrcDir)src\lj_snap.h" />
    <ClInclude Include="$(SrcDir)src\lj_state.h" />
    <ClInclude Include="$(SrcDir)src\lj_str.h" />
    <ClInclude Include="$(SrcDir)src\lj_strscan.h" />
    <ClInclude Include="$(SrcDir)src\lj_tab.h" />
    <ClInclude Include="$(SrcDir)src\lj_target.h" />
    <ClInclude Include="$(SrcDir)src\lj_target_arm.h" />
    <ClInclude Include="$(SrcDir)src\lj_target_mips.h" />
    <ClInclude Include="$(SrcDir)src\lj_target_ppc.h" />
    <ClInclude Include="$(SrcDir)src\lj_target_x86.h" />
    <ClInclude Include="$(SrcDir)src\lj_trace.h" />
    <ClInclude Include="$(SrcDir)src\lj_traceerr.h" />
    <ClInclude Include="$(SrcDir)src\lj_udata.h" />
    <ClInclude Include="$(SrcDir)src\lj_vm.h" />
    <ClInclude Include="$(SrcDir)src\lj_vmevent.h" />
  </ItemGroup>

  <ItemGroup>
    <None Include="$(SrcDir)src\jit\bc.lua" />
    <None Include="$(SrcDir)src\jit\bcsave.lua" />
    <None Include="$(SrcDir)src\jit\dis_arm.lua" />
    <None Include="$(SrcDir)src\jit\dis_mips.lua" />
    <None Include="$(SrcDir)src\jit\dis_mipsel.lua" />
    <None Include="$(SrcDir)src\jit\dis_ppc.lua" />
    <None Include="$(SrcDir)src\jit\dis_x64.lua" />
    <None Include="$(SrcDir)src\jit\dis_x86.lua" />
    <None Include="$(SrcDir)src\jit\dump.lua" />
    <None Include="$(SrcDir)src\jit\v.lua" />
    <None Include="$(SrcDir)src\jit\vmdef.lua" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\luajit-buildvm\luajit-buildvm.vcxproj">
      <Project>{7ca6a4eb-a11b-4975-8f3a-f633111c6213}</Project>
    </ProjectReference>
  </ItemGroup>
</Project>
