From d349134180448123e4abb6fcb961daa238ef7467 Mon Sep 17 00:00:00 2001
From: Joao Matos <joao@tritao.eu>
Date: Fri, 30 Sep 2016 15:59:39 +0100
Subject: [PATCH] Reworked parser bindings build scripts to be more easily
 re-usable.

---
 build/Parser.lua                           | 19 ------
 build/premake5.lua                         | 30 +++++-----
 src/CppParser/Bindings/CLI/premake5.lua    | 37 ++++++++++++
 src/CppParser/Bindings/CSharp/premake5.lua | 43 ++++++++++++++
 src/CppParser/Bindings/premake5.lua        | 69 +---------------------
 src/CppParser/premake5.lua                 |  5 +-
 src/Parser/premake5.lua                    |  2 -
 7 files changed, 100 insertions(+), 105 deletions(-)
 delete mode 100644 build/Parser.lua
 create mode 100644 src/CppParser/Bindings/CLI/premake5.lua
 create mode 100644 src/CppParser/Bindings/CSharp/premake5.lua

diff --git a/build/Parser.lua b/build/Parser.lua
deleted file mode 100644
index e8fc9a1c..00000000
--- a/build/Parser.lua
+++ /dev/null
@@ -1,19 +0,0 @@
-function SetupCLIParser()
-  links { "CppSharp.Parser.CLI" }
-end
-
-function SetupCSharpParser()
-  links
-  {
-    "CppSharp.Parser.CSharp",
-    "CppSharp.Runtime"
-  }
-end
-
-function SetupParser()
-  if string.match(action, "vs*") and os.is("windows") then
-    SetupCLIParser()
-  else
-    SetupCSharpParser()
-  end
-end
\ No newline at end of file
diff --git a/build/premake5.lua b/build/premake5.lua
index a1b1dd18..a1cf7e1b 100644
--- a/build/premake5.lua
+++ b/build/premake5.lua
@@ -5,9 +5,7 @@
 config = {}
 
 dofile "Helpers.lua"
-dofile "Tests.lua"
 dofile "LLVM.lua"
-dofile "Parser.lua"
 
 solution "CppSharp"
 
@@ -26,22 +24,26 @@ solution "CppSharp"
     defines { "WINDOWS" }
 	
   configuration {}
-    
-  if string.starts(action, "vs") then
 
-  group "Examples"
-    IncludeExamples()
-  
-  end
-  
-  group "Tests"
-      IncludeTests()
-      
   group "Libraries"
     include (srcdir .. "/Core")
     include (srcdir .. "/AST")
+    include (srcdir .. "/CppParser")
+    include (srcdir .. "/CppParser/Bindings")
+    include (srcdir .. "/CppParser/ParserGen")
+    include (srcdir .. "/Parser")    
     include (srcdir .. "/Generator")
     include (srcdir .. "/Generator.Tests")
     include (srcdir .. "/Runtime")
-    include (srcdir .. "/Parser")
-    include (srcdir .. "/CppParser")
+
+  dofile "Tests.lua"
+
+  group "Tests"
+      IncludeTests()
+
+  if string.starts(action, "vs") then
+
+  group "Examples"
+    IncludeExamples()
+  
+  end
diff --git a/src/CppParser/Bindings/CLI/premake5.lua b/src/CppParser/Bindings/CLI/premake5.lua
new file mode 100644
index 00000000..0b55875f
--- /dev/null
+++ b/src/CppParser/Bindings/CLI/premake5.lua
@@ -0,0 +1,37 @@
+include "../../../../build/LLVM.lua"
+
+project "CppSharp.Parser.CLI"
+  
+  kind "SharedLib"
+  language "C++"
+  SetupNativeProject()
+  SetupLLVMIncludes()
+  
+  dependson { "CppSharp.CppParser" }
+  flags { common_flags, "Managed" }
+
+  configuration "vs*"
+    buildoptions { clang_msvc_flags }  
+
+  configuration "*"
+  
+  files
+  {
+    "**.h",
+    "**.cpp",
+    "**.lua"
+  }
+  
+  includedirs
+  {
+    "../../../../include/",
+    "../../../../src/CppParser/"
+  }
+  
+  configuration "*"
+
+  links { "CppSharp.CppParser" }
+
+function SetupParser()
+  links { "CppSharp.Parser.CLI" }
+end  
\ No newline at end of file
diff --git a/src/CppParser/Bindings/CSharp/premake5.lua b/src/CppParser/Bindings/CSharp/premake5.lua
new file mode 100644
index 00000000..7360c781
--- /dev/null
+++ b/src/CppParser/Bindings/CSharp/premake5.lua
@@ -0,0 +1,43 @@
+project "CppSharp.Parser.CSharp"
+
+  SetupManagedProject()
+
+  kind "SharedLib"
+  language "C#"
+  clr "Unsafe"
+
+  dependson { "CppSharp.CppParser" }
+
+  files
+  {
+    "**.lua"
+  }
+
+  links { "CppSharp.Runtime" }
+
+  if os.is("windows") then
+      files { "i686-pc-win32-msvc/**.cs" }
+  elseif os.is("macosx") then
+      local file = io.popen("lipo -info `which mono`")
+      local output = file:read('*all')
+      if string.find(output, "x86_64") then  
+        files { "x86_64-apple-darwin12.4.0/**.cs" }
+      else
+        files { "i686-apple-darwin12.4.0/**.cs" }
+      end
+
+  elseif os.is("linux") then
+      files { "x86_64-linux-gnu/**.cs" }
+  else
+      print "Unknown architecture"
+  end
+
+  configuration ""
+
+function SetupParser()
+  links
+  {
+    "CppSharp.Parser.CSharp",
+    "CppSharp.Runtime"
+  }
+end
\ No newline at end of file
diff --git a/src/CppParser/Bindings/premake5.lua b/src/CppParser/Bindings/premake5.lua
index 8acecfe3..baf9c39b 100644
--- a/src/CppParser/Bindings/premake5.lua
+++ b/src/CppParser/Bindings/premake5.lua
@@ -1,70 +1,7 @@
-include "../../../build/LLVM.lua"
-
-project "CppSharp.Parser.CSharp"
-
-  SetupManagedProject()
-
-  kind "SharedLib"
-  language "C#"
-  clr "Unsafe"
-
-  dependson { "CppSharp.CppParser" }
-
-  files
-  {
-    "**.lua"
-  }
-
-  links { "CppSharp.Runtime" }
-
-  if os.is("windows") then
-      files { "CSharp/i686-pc-win32-msvc/**.cs" }
-  elseif os.is("macosx") then
-      local file = io.popen("lipo -info `which mono`")
-      local output = file:read('*all')
-      if string.find(output, "x86_64") then  
-        files { "CSharp/x86_64-apple-darwin12.4.0/**.cs" }
-      else
-        files { "CSharp/i686-apple-darwin12.4.0/**.cs" }
-      end
-
-  elseif os.is("linux") then
-      files { "CSharp/x86_64-linux-gnu/**.cs" }
-  else
-      print "Unknown architecture"
-  end
-
-  configuration ""
+include ("CSharp")
 
 if string.starts(action, "vs") and os.is("windows") then
 
-  project "CppSharp.Parser.CLI"
-    
-    kind "SharedLib"
-    language "C++"
-    SetupNativeProject()
-    SetupLLVMIncludes()
-    
-    dependson { "CppSharp.CppParser" }
-    flags { common_flags, "Managed" }
-
-    configuration "vs*"
-      buildoptions { clang_msvc_flags }  
-
-    configuration "*"
-    
-    files
-    {
-      "CLI/AST.h",
-      "CLI/AST.cpp",
-      "CLI/**.h",
-      "CLI/**.cpp",
-      "**.lua"
-    }
-    
-    includedirs { "../../../include/", "../../../src/CppParser/" }
-    
-    configuration "*"
-    links { "CppSharp.CppParser" }
+include ("CLI")
 
-end
+end
\ No newline at end of file
diff --git a/src/CppParser/premake5.lua b/src/CppParser/premake5.lua
index b0b438e4..49cc7e1e 100644
--- a/src/CppParser/premake5.lua
+++ b/src/CppParser/premake5.lua
@@ -38,7 +38,4 @@ project "CppSharp.CppParser"
   
   configuration "*"
 
-end
-
-include ("Bindings")
-include ("ParserGen")
\ No newline at end of file
+end
\ No newline at end of file
diff --git a/src/Parser/premake5.lua b/src/Parser/premake5.lua
index 03a98313..158012e7 100644
--- a/src/Parser/premake5.lua
+++ b/src/Parser/premake5.lua
@@ -1,5 +1,3 @@
-include("../../build/Parser.lua")
-
 project "CppSharp.Parser"
 
   SetupManagedProject()