options.bmx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. ' Copyright (c) 2013-2024 Bruce A Henderson
  2. '
  3. ' Based on the public domain Monkey "trans" by Mark Sibly
  4. '
  5. ' This software is provided 'as-is', without any express or implied
  6. ' warranty. In no event will the authors be held liable for any damages
  7. ' arising from the use of this software.
  8. '
  9. ' Permission is granted to anyone to use this software for any purpose,
  10. ' including commercial applications, and to alter it and redistribute it
  11. ' freely, subject to the following restrictions:
  12. '
  13. ' 1. The origin of this software must not be misrepresented; you must not
  14. ' claim that you wrote the original software. If you use this software
  15. ' in a product, an acknowledgment in the product documentation would be
  16. ' appreciated but is not required.
  17. '
  18. ' 2. Altered source versions must be plainly marked as such, and must not be
  19. ' misrepresented as being the original software.
  20. '
  21. ' 3. This notice may not be removed or altered from any source
  22. ' distribution.
  23. '
  24. SuperStrict
  25. Import "base.configmap.bmx"
  26. Import "version.bmx"
  27. Const BUILDTYPE_APP:Int = 0
  28. Const BUILDTYPE_MODULE:Int = 1
  29. Const APPTYPE_NONE:Int = 0
  30. Const APPTYPE_CONSOLE:Int = 1
  31. Const APPTYPE_GUI:Int = 2
  32. Global WORD_SIZE:Int = 4
  33. ' buildtype
  34. ' module
  35. ' app
  36. Global opt_buildtype:Int = BUILDTYPE_APP
  37. ' modulename
  38. ' name of the module to build
  39. Global opt_modulename:String
  40. ' arch
  41. ' x86
  42. ' ppc
  43. ' x64
  44. ' arm
  45. ' armeabi
  46. ' armeabiv7a
  47. ' armv7
  48. ' arm64
  49. Global opt_arch:String
  50. ' platform
  51. ' win32
  52. ' macos
  53. ' osx
  54. ' ios
  55. ' linux
  56. ' android
  57. ' raspberrypi
  58. ' nx
  59. ' haiku
  60. Global opt_platform:String
  61. ' framework
  62. Global opt_framework:String
  63. ' filename
  64. ' the base filename for app/module to compile against
  65. Global opt_filename:String
  66. ' outfile
  67. ' full path to the outputfile (excluding final extension - there will be a .h, .c and .i generated)
  68. Global opt_outfile:String
  69. ' apptype
  70. ' console
  71. ' gui
  72. Global opt_apptype:Int = APPTYPE_NONE
  73. ' debug
  74. Global opt_debug:Int = True
  75. ' threaded
  76. Global opt_threaded:Int = True
  77. ' release
  78. Global opt_release:Int = False
  79. ' quiet
  80. Global opt_quiet:Int = False
  81. ' verbose
  82. Global opt_verbose:Int = False
  83. ' ismain
  84. ' this is the main file for either the module, or the application.
  85. Global opt_ismain:Int = False
  86. ' issuperstrict
  87. '
  88. Global opt_issuperstrict:Int = False
  89. ' gdbdebug
  90. ' output debug useful for gdb, #line <bmx line> <bmx file>
  91. Global opt_gdbdebug:Int = False
  92. '
  93. ' upgrade strict subclass method/function return types to match superstrict superclass.
  94. ' default is to auto-upgrade. Set flag if you want to throw an error - because of mismatch. (strict is Int, superstrict is Void).
  95. Global opt_strictupgrade:Int = True
  96. ' overload warnings
  97. ' generate warnings (and accept) instead of errors for calling methods with arguments that need to be cast down.
  98. ' May cause issues using overloaded methods.
  99. Global opt_warnover:Int = False
  100. ' musl libc support
  101. '
  102. Global opt_musl:Int = False
  103. ' def
  104. ' generate .def files for dlls
  105. Global opt_def:Int = False
  106. ' don't generate .def files for dlls
  107. Global opt_nodef:Int = False
  108. ' generate header for dlls
  109. Global opt_head:Int = False
  110. ' don't generate header for dlls
  111. Global opt_nohead:Int = False
  112. ' makelib
  113. Global opt_makelib:Int = False
  114. ' override
  115. ' require override keyword
  116. Global opt_require_override:Int = False
  117. ' overerr
  118. ' missing override is error
  119. Global opt_override_error:Int = False
  120. ' ud
  121. ' user defines
  122. Global opt_userdefs:String
  123. '
  124. Global opt_need_strict:Int = False
  125. '
  126. Global opt_legacy_incbin:Int = False
  127. Global opt_filepath:String
  128. Global opt_coverage:Int = False
  129. Global opt_no_auto_superstrict:Int = False
  130. Function CmdError(details:String = Null, fullUsage:Int = False)
  131. Local s:String = "Compile Error"
  132. If details Then
  133. s:+ ": " + details
  134. End If
  135. s:+ "~n"
  136. 's:+ Usage(fullUsage)
  137. Throw s
  138. End Function
  139. Function ParseArgs:String[](args:String[])
  140. DefaultOptions()
  141. CheckConfig()
  142. Local count:Int
  143. While count < args.length
  144. Local arg:String = args[count]
  145. If arg[..1] <> "-" Then
  146. Exit
  147. End If
  148. Select arg[1..]
  149. Case "q"
  150. opt_quiet=True
  151. Case "v"
  152. opt_verbose=True
  153. Case "r"
  154. opt_debug=False
  155. opt_release=True
  156. Case "h"
  157. opt_threaded=True
  158. Case "s"
  159. ' disable with option
  160. opt_strictupgrade=False
  161. Case "g"
  162. count:+1
  163. If count = args.length Then
  164. CmdError "Command line error - Missing arg for '-g'"
  165. End If
  166. opt_arch = args[count].ToLower()
  167. Case "m"
  168. count:+1
  169. If count = args.length Then
  170. CmdError "Command line error - Missing arg for '-m'"
  171. End If
  172. opt_buildtype = BUILDTYPE_MODULE
  173. opt_modulename = args[count].ToLower()
  174. Case "o"
  175. count:+1
  176. If count = args.length Then
  177. CmdError "Command line error - Missing arg for '-o'"
  178. End If
  179. opt_outfile = args[count]
  180. Case "p"
  181. count:+1
  182. If count = args.length Then
  183. CmdError "Command line error - Missing arg for '-p'"
  184. End If
  185. opt_platform = args[count].ToLower()
  186. Case "t"
  187. count:+1
  188. If count = args.length Then
  189. CmdError "Command line error - Missing arg for '-t'"
  190. End If
  191. Local apptype:String = args[count].ToLower()
  192. Select apptype
  193. Case "console"
  194. opt_apptype = APPTYPE_CONSOLE
  195. Case "gui"
  196. opt_apptype = APPTYPE_GUI
  197. Default
  198. CmdError "Command line error - Invalid app type '" + opt_apptype + "'"
  199. End Select
  200. Case "f"
  201. count:+1
  202. If count = args.length Then
  203. CmdError "Command line error - Missing arg for '-f'"
  204. End If
  205. opt_framework = args[count]
  206. Case "d"
  207. opt_gdbdebug=True
  208. Case "w"
  209. opt_warnover=True
  210. Case "musl"
  211. opt_musl=True
  212. Case "nodef"
  213. opt_nodef=True
  214. Case "nohead"
  215. opt_nohead=True
  216. Case "makelib"
  217. opt_makelib=True
  218. Case "override"
  219. opt_require_override=True
  220. Case "overerr"
  221. opt_override_error=True
  222. Case "ud"
  223. count:+1
  224. If count = args.length Then
  225. CmdError "Command line error - Missing arg for '-ud'"
  226. End If
  227. opt_userdefs = args[count].ToLower()
  228. Case "strict"
  229. opt_need_strict=True
  230. Case "ib"
  231. opt_legacy_incbin=True
  232. Case "cov"
  233. opt_coverage=True
  234. Case "nas"
  235. opt_no_auto_superstrict=True
  236. End Select
  237. count:+ 1
  238. Wend
  239. If opt_buildtype = BUILDTYPE_MODULE Then
  240. opt_apptype = APPTYPE_NONE
  241. End If
  242. If opt_arch = "x64" Or opt_arch = "arm64v8a" Or opt_arch = "arm64" Or opt_arch = "riscv64" Then
  243. WORD_SIZE = 8
  244. End If
  245. ' new incbin doesn't work on win32 x86
  246. If opt_arch = "x86" And opt_platform = "win32" Then
  247. opt_legacy_incbin = True
  248. End If
  249. If opt_makelib Then
  250. If Not opt_nodef Then
  251. opt_def = True
  252. End If
  253. If Not opt_nohead Then
  254. opt_head = True
  255. End If
  256. End If
  257. Return args[count..]
  258. End Function
  259. Function DefaultOptions()
  260. ?x86
  261. opt_arch = "x86"
  262. ?ppc
  263. opt_arch = "ppc"
  264. ?x64
  265. opt_arch = "x64"
  266. ?arm
  267. opt_arch = "arm"
  268. ?arm64
  269. opt_arch = "arm64"
  270. ?armeabi
  271. opt_arch = "armeabi"
  272. ?armeabiv7a
  273. opt_arch = "armeabiv7a"
  274. ?arm64v8a
  275. opt_arch = "arm64v8a"
  276. ?js
  277. opt_arch = "js"
  278. ?riscv32
  279. opt_arch = "riscv32"
  280. ?riscv64
  281. opt_arch = "riscv64"
  282. ?
  283. ?win32
  284. opt_platform = "win32"
  285. ?macos
  286. opt_platform = "macos"
  287. ?linux
  288. opt_platform = "linux"
  289. ?android
  290. opt_platform = "android"
  291. ?raspberrypi
  292. opt_platform = "raspberrypi"
  293. ?haiku
  294. opt_platform = "haiku"
  295. ?emscripten
  296. opt_platform = "emscripten"
  297. ?
  298. End Function
  299. Function CheckConfig()
  300. Local config:TConfigMap = New TConfigMap.Init("bcc.conf")
  301. 'try to load an OS-specific path (so all bcc builds could share
  302. 'one single bcc.conf)
  303. Local osBmxPath:String = ""
  304. ?win32
  305. osBmxPath = config.GetString("BMXPATH_WIN32")
  306. ?linux
  307. osBmxPath = config.GetString("BMXPATH_LINUX")
  308. ?macos
  309. osBmxPath = config.GetString("BMXPATH_MACOS")
  310. ?android
  311. ' override BMXPATH_LINUX if available
  312. Local tmp:String = config.GetString("BMXPATH_ANDROID")
  313. If tmp Then
  314. osBmxPath = tmp
  315. End If
  316. ?raspberrypi
  317. ' override BMXPATH_LINUX if available
  318. Local tmp:String = config.GetString("BMXPATH_RASPBERRYPI")
  319. If tmp Then
  320. osBmxPath = tmp
  321. End If
  322. ?haiku
  323. osBmxPath = config.GetString("BMXPATH_HAIKU")
  324. ?
  325. 'load default/generic path
  326. If osBmxPath = "" Then osBmxPath = config.GetString("BMXPATH")
  327. 'replace windows backslashes with crossplatform slashes
  328. osBmxPath = osBmxPath.Replace("\", "/")
  329. If osBmxPath <> "" Then putenv_("BMXPATH="+osBmxPath)
  330. End Function