11using System ;
22using System . IO ;
33using System . Linq ;
4+ using System . Text . RegularExpressions ;
45
56namespace LuaInstaller . Core
67{
@@ -36,6 +37,50 @@ public InstallationManager(ICompiler compiler, ILinker linker)
3637 _objExtension = _compiler . DefaultObjectExtension ;
3738 }
3839
40+ private AbstractLuaCompatibility GetLuaCompatibility ( string srcDir )
41+ {
42+ bool result = false ;
43+ string luaCompat = null ;
44+
45+ string srcMakefile = Path . Combine ( srcDir , "Makefile" ) ;
46+
47+ if ( File . Exists ( srcMakefile ) )
48+ {
49+ using ( FileStream fileStream = File . OpenRead ( srcMakefile ) )
50+ using ( StreamReader Makefile = new StreamReader ( fileStream ) )
51+ {
52+ string line = null ;
53+ Match match = null ;
54+ Regex regex = new Regex ( @"\-D(LUA_COMPAT_[a-zA-Z0-9_]+)\b" ) ;
55+
56+ while ( ! ( result || Makefile . EndOfStream ) )
57+ {
58+ line = Makefile . ReadLine ( ) ;
59+
60+ match = regex . Match ( line ) ;
61+
62+ if ( match . Success )
63+ {
64+ luaCompat = match . Groups [ 1 ] . Value ;
65+
66+ result = true ;
67+ }
68+ }
69+ }
70+ }
71+
72+ AbstractLuaCompatibility compatibility ;
73+ if ( result )
74+ {
75+ compatibility = new LuaCompatibility ( luaCompat ) ;
76+ }
77+ else
78+ {
79+ compatibility = new LuaNoCompatibility ( ) ;
80+ }
81+ return compatibility ;
82+ }
83+
3984 private void LinkDll ( string srcDir , string outputFile , VisualStudio vs , WindowsSdk winsdk )
4085 {
4186 try
@@ -72,14 +117,16 @@ private void LinkDll(string srcDir, string outputFile, VisualStudio vs, WindowsS
72117 _linker . Reset ( ) ;
73118 }
74119 }
75- private void BuildDll ( string srcDir , string outputFile , VisualStudio vs , WindowsSdk winsdk )
120+ private void BuildDll ( string srcDir , string outputFile , VisualStudio vs , WindowsSdk winsdk , AbstractLuaCompatibility luaCompat )
76121 {
77122 string buildDir = Path . Combine (
78123 Path . GetTempPath ( ) , "li-build-dll-" + Guid . NewGuid ( ) . ToString ( "N" )
79124 ) ;
80125
81126 try
82127 {
128+ luaCompat . TryAddDefine ( _compiler ) ;
129+
83130 _compiler . AddDefine ( "LUA_BUILD_AS_DLL" ) ;
84131
85132 foreach ( string inc in vs . IncludeDirectories )
@@ -167,14 +214,16 @@ private void LinkInterpreter(string srcDir, string luaLibPath, string outputFile
167214 _linker . Reset ( ) ;
168215 }
169216 }
170- private void BuildInterpreter ( string srcDir , string luaLibPath , string outputFile , VisualStudio vs , WindowsSdk winsdk )
217+ private void BuildInterpreter ( string srcDir , string luaLibPath , string outputFile , VisualStudio vs , WindowsSdk winsdk , AbstractLuaCompatibility luaCompat )
171218 {
172219 string buildDir = Path . Combine (
173220 Path . GetTempPath ( ) , "li-interpreter-" + Guid . NewGuid ( ) . ToString ( "N" )
174221 ) ;
175222
176223 try
177224 {
225+ luaCompat . TryAddDefine ( _compiler ) ;
226+
178227 foreach ( string inc in vs . IncludeDirectories )
179228 {
180229 _compiler . AddIncludeDirectory ( inc ) ;
@@ -258,14 +307,16 @@ private void LinkCompiler(string srcDir, string outputFile, VisualStudio vs, Win
258307 _linker . Reset ( ) ;
259308 }
260309 }
261- private void BuildCompiler ( string srcDir , string outputFile , VisualStudio vs , WindowsSdk winsdk )
310+ private void BuildCompiler ( string srcDir , string outputFile , VisualStudio vs , WindowsSdk winsdk , AbstractLuaCompatibility luaCompat )
262311 {
263312 string buildDir = Path . Combine (
264313 Path . GetTempPath ( ) , "li-build-compiler-" + Guid . NewGuid ( ) . ToString ( "N" )
265314 ) ;
266315
267316 try
268317 {
318+ luaCompat . TryAddDefine ( _compiler ) ;
319+
269320 foreach ( string inc in vs . IncludeDirectories )
270321 {
271322 _compiler . AddIncludeDirectory ( inc ) ;
@@ -392,11 +443,11 @@ private void InstallOnDestDir(LuaDestinationDirectory workDir, LuaDestinationDir
392443 }
393444 }
394445
395- private void CreatePkgConfigFile ( LuaDestinationDirectory destDir , LuaVersion version , LuaGeneratedBinaries generatedBinaries )
446+ private void CreatePkgConfigFile ( LuaDestinationDirectory destDir , LuaVersion version , LuaGeneratedBinaries generatedBinaries , AbstractLuaCompatibility luaCompat )
396447 {
397448 try
398449 {
399- PkgConfigOutputInfo pkgConfigOutput = new PkgConfigOutputInfo ( version , generatedBinaries , destDir ) ;
450+ PkgConfigOutputInfo pkgConfigOutput = new PkgConfigOutputInfo ( version , generatedBinaries , destDir , luaCompat ) ;
400451
401452 if ( pkgConfigOutput . WritePkgConfigFile ( ) )
402453 {
@@ -494,21 +545,25 @@ public void Build(LuaVersion version, string luaDestDir, VisualStudio vs, Window
494545 LuaSourcesDirectory sourcesDir = new LuaSourcesDirectory ( luaSourcesDir ) ;
495546 LuaDestinationDirectory workDir = new LuaDestinationDirectory ( luaWorkDir ) ;
496547 LuaGeneratedBinaries generatedBinaries = new LuaGeneratedBinaries ( version ) ;
548+
549+ AbstractLuaCompatibility luaCompat = GetLuaCompatibility ( sourcesDir . Src ) ;
497550
498551 workDir . CreateFrom ( sourcesDir ) ;
499552
500553 BuildDll (
501554 sourcesDir . Src ,
502555 Path . Combine ( workDir . Lib , generatedBinaries . DllName ) ,
503556 vs ,
504- winsdk
557+ winsdk ,
558+ luaCompat
505559 ) ;
506560 BuildInterpreter (
507561 sourcesDir . Src ,
508562 Path . Combine ( workDir . Lib , generatedBinaries . ImportLibName ) ,
509563 Path . Combine ( workDir . Bin , generatedBinaries . InterpreterName ) ,
510564 vs ,
511- winsdk
565+ winsdk ,
566+ luaCompat
512567 ) ;
513568 File . Copy (
514569 Path . Combine ( workDir . Lib , generatedBinaries . DllName ) ,
@@ -519,7 +574,8 @@ public void Build(LuaVersion version, string luaDestDir, VisualStudio vs, Window
519574 sourcesDir . Src ,
520575 Path . Combine ( workDir . Bin , generatedBinaries . CompilerName ) ,
521576 vs ,
522- winsdk
577+ winsdk ,
578+ luaCompat
523579 ) ;
524580
525581 if ( File . Exists ( Path . Combine ( workDir . Lib , generatedBinaries . DllName ) ) )
@@ -531,7 +587,7 @@ public void Build(LuaVersion version, string luaDestDir, VisualStudio vs, Window
531587
532588 LuaDestinationDirectory destDir = new LuaDestinationDirectory ( luaDestDir ) ;
533589 InstallOnDestDir ( workDir , destDir ) ;
534- CreatePkgConfigFile ( destDir , version , generatedBinaries ) ;
590+ CreatePkgConfigFile ( destDir , version , generatedBinaries , luaCompat ) ;
535591 SetEnvironmentVariables ( destDir , variableTarget ) ;
536592 }
537593 finally
0 commit comments