maxutil.bmx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. Strict
  2. Module BRL.MaxUtil
  3. ModuleInfo "Version: 1.01"
  4. ModuleInfo "Author: Mark Sibly"
  5. ModuleInfo "License: zlib/libpng"
  6. ModuleInfo "Copyright: Blitz Research Ltd"
  7. ModuleInfo "Modserver: BRL"
  8. ModuleInfo "History: 1.01 Release"
  9. ModuleInfo "History: 1.00 Release"
  10. Import BRL.LinkedList
  11. Import BRL.FileSystem
  12. Import Pub.StdC
  13. Function BlitzMaxPath:String()
  14. Global bmxpath:String
  15. If bmxpath And FileType(bmxpath)=FILETYPE_DIR Return bmxpath
  16. Local p:String=getenv_("BMXPATH")
  17. If p And FileType(p)=FILETYPE_DIR
  18. bmxpath=p
  19. Return p
  20. EndIf
  21. p=AppDir
  22. Repeat
  23. Local t:String=p+"/bin/bmk"
  24. ?Win32
  25. t:+".exe"
  26. ?
  27. If FileType(t)=FILETYPE_FILE
  28. putenv_ "BMXPATH="+p
  29. bmxpath=p
  30. Return p
  31. EndIf
  32. Local q:String=ExtractDir( p )
  33. If q=p Throw "Unable to locate BlitzMax path"
  34. p=q
  35. Forever
  36. End Function
  37. Function ModulePath:String( modid:String )
  38. Local p:String=BlitzMaxPath()+"/mod"
  39. If modid p:+"/"+modid.Replace(".",".mod/")+".mod"
  40. Return p
  41. End Function
  42. Function ModuleIdent:String( modid:String )
  43. Return modid[modid.FindLast(".")+1..]
  44. End Function
  45. Function ModuleSource:String( modid:String )
  46. Return ModulePath(modid)+"/"+ModuleIdent(modid)+".bmx"
  47. End Function
  48. Function ModuleArchive:String( modid:String,mung:String="" )
  49. If mung And mung[0]<>Asc(".") mung="."+mung
  50. Return ModulePath(modid)+"/"+ModuleIdent(modid)+mung+".a"
  51. End Function
  52. Function ModuleInterface:String( modid:String,mung:String="" )
  53. If mung And mung[0]<>Asc(".") mung="."+mung
  54. Return ModulePath(modid)+"/"+ModuleIdent(modid)+mung+".i"
  55. End Function
  56. Function EnumModules:TList( modid:String="",mods:TList=Null )
  57. If Not mods mods=New TList
  58. Local dir:String=ModulePath( modid )
  59. Local files:String[]=LoadDir( dir )
  60. For Local file:String=EachIn files
  61. Local path:String=dir+"/"+file
  62. If file[file.length-4..]<>".mod" Or FileType(path)<>FILETYPE_DIR Continue
  63. Local t:String=file[..file.length-4]
  64. If modid t=modid+"."+t
  65. Local i=t.Find( "." )
  66. If i<>-1 And t.Find( ".",i+1)=-1 mods.AddLast t
  67. mods=EnumModules( t,mods )
  68. Next
  69. Return mods
  70. End Function
  71. Private
  72. ?win32
  73. Global _minGWPath:String
  74. ?
  75. Public
  76. Function MinGWPath:String()
  77. ?Not win32
  78. Return ""
  79. ?win32
  80. If Not _minGWPath Then
  81. Local path:String
  82. ' look for local MinGW32 dir
  83. ' some distros (eg. MinGW-w64) only support a single target architecture - x86 or x64
  84. ' to compile for both, requires two separate MinGW installations. Check against
  85. ' CPU target based dir first, before working through the fallbacks.
  86. Local cpuMinGW:String
  87. ?win32x86
  88. cpuMinGW ="/MinGW32x86"
  89. ?win32x64
  90. cpuMinGW = "/MinGW32x64"
  91. ?win32arm
  92. cpuMinGW = "/llvm-mingw"
  93. ?win32arm64
  94. cpuMinGW = "/llvm-mingw"
  95. ?win32
  96. If cpuMinGW Then
  97. path = BlitzMaxPath() + cpuMinGW + "/bin"
  98. If FileType(path) = FILETYPE_DIR Then
  99. ' bin dir exists, go with that
  100. _minGWPath = BlitzMaxPath() + cpuMinGW
  101. Return _minGWPath
  102. End If
  103. End If
  104. path = BlitzMaxPath() + "/MinGW32/bin"
  105. If FileType(path) = FILETYPE_DIR Then
  106. ' bin dir exists, go with that
  107. _minGWPath = BlitzMaxPath() + "/MinGW32"
  108. Return _minGWPath
  109. End If
  110. path = BlitzMaxPath() + "/llvm-mingw/bin"
  111. If FileType(path) = FILETYPE_DIR Then
  112. ' bin dir exists, go with that
  113. _minGWPath = BlitzMaxPath() + "/llvm-mingw"
  114. Return _minGWPath
  115. End If
  116. ' try MINGW environment variable
  117. path = getenv_("MINGW")
  118. If path And FileType(path) = FILETYPE_DIR Then
  119. ' check for bin dir
  120. If FileType(path + "/bin") = FILETYPE_DIR Then
  121. ' go with that
  122. _minGWPath = path
  123. Return _minGWPath
  124. End If
  125. End If
  126. ' none of the above? fallback to BlitzMax dir (for bin and lib)
  127. _minGWPath = BlitzMaxPath()
  128. End If
  129. Return _minGWPath
  130. ?
  131. End Function