options.bmx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. ' Copyright (c) 2013-2026 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. Global opt_alloc_stats:Int = False
  131. Function CmdError(details:String = Null, fullUsage:Int = False)
  132. Local s:String = "Compile Error"
  133. If details Then
  134. s:+ ": " + details
  135. End If
  136. s:+ "~n"
  137. 's:+ Usage(fullUsage)
  138. Throw s
  139. End Function
  140. Function ParseArgs:String[](args:String[])
  141. DefaultOptions()
  142. CheckConfig()
  143. Local count:Int
  144. While count < args.length
  145. Local arg:String = args[count]
  146. If arg[..1] <> "-" Then
  147. Exit
  148. End If
  149. Select arg[1..]
  150. Case "q"
  151. opt_quiet=True
  152. Case "v"
  153. opt_verbose=True
  154. Case "r"
  155. opt_debug=False
  156. opt_release=True
  157. Case "h"
  158. opt_threaded=True
  159. Case "s"
  160. ' disable with option
  161. opt_strictupgrade=False
  162. Case "g"
  163. count:+1
  164. If count = args.length Then
  165. CmdError "Command line error - Missing arg for '-g'"
  166. End If
  167. opt_arch = args[count].ToLower()
  168. Case "m"
  169. count:+1
  170. If count = args.length Then
  171. CmdError "Command line error - Missing arg for '-m'"
  172. End If
  173. opt_buildtype = BUILDTYPE_MODULE
  174. opt_modulename = args[count].ToLower()
  175. Case "o"
  176. count:+1
  177. If count = args.length Then
  178. CmdError "Command line error - Missing arg for '-o'"
  179. End If
  180. opt_outfile = args[count]
  181. Case "p"
  182. count:+1
  183. If count = args.length Then
  184. CmdError "Command line error - Missing arg for '-p'"
  185. End If
  186. opt_platform = args[count].ToLower()
  187. Case "t"
  188. count:+1
  189. If count = args.length Then
  190. CmdError "Command line error - Missing arg for '-t'"
  191. End If
  192. Local apptype:String = args[count].ToLower()
  193. Select apptype
  194. Case "console"
  195. opt_apptype = APPTYPE_CONSOLE
  196. Case "gui"
  197. opt_apptype = APPTYPE_GUI
  198. Default
  199. CmdError "Command line error - Invalid app type '" + opt_apptype + "'"
  200. End Select
  201. Case "f"
  202. count:+1
  203. If count = args.length Then
  204. CmdError "Command line error - Missing arg for '-f'"
  205. End If
  206. opt_framework = args[count]
  207. Case "d"
  208. opt_gdbdebug=True
  209. Case "w"
  210. opt_warnover=True
  211. Case "musl"
  212. opt_musl=True
  213. Case "nodef"
  214. opt_nodef=True
  215. Case "nohead"
  216. opt_nohead=True
  217. Case "makelib"
  218. opt_makelib=True
  219. Case "override"
  220. opt_require_override=True
  221. Case "overerr"
  222. opt_override_error=True
  223. Case "ud"
  224. count:+1
  225. If count = args.length Then
  226. CmdError "Command line error - Missing arg for '-ud'"
  227. End If
  228. opt_userdefs = args[count].ToLower()
  229. Case "strict"
  230. opt_need_strict=True
  231. Case "ib"
  232. opt_legacy_incbin=True
  233. Case "cov"
  234. opt_coverage=True
  235. Case "nas"
  236. opt_no_auto_superstrict=True
  237. Case "allocstats"
  238. ?bmxng
  239. opt_alloc_stats=True
  240. CountObjectInstances = True
  241. 'CountObjectInstanceTotals = True
  242. ?
  243. End Select
  244. count:+ 1
  245. Wend
  246. If opt_buildtype = BUILDTYPE_MODULE Then
  247. opt_apptype = APPTYPE_NONE
  248. End If
  249. If opt_arch = "x64" Or opt_arch = "arm64v8a" Or opt_arch = "arm64" Or opt_arch = "riscv64" Then
  250. WORD_SIZE = 8
  251. End If
  252. ' new incbin doesn't work on win32 x86
  253. If opt_arch = "x86" And opt_platform = "win32" Then
  254. opt_legacy_incbin = True
  255. End If
  256. If opt_makelib Then
  257. If Not opt_nodef Then
  258. opt_def = True
  259. End If
  260. If Not opt_nohead Then
  261. opt_head = True
  262. End If
  263. End If
  264. Return args[count..]
  265. End Function
  266. Function DefaultOptions()
  267. ?x86
  268. opt_arch = "x86"
  269. ?ppc
  270. opt_arch = "ppc"
  271. ?x64
  272. opt_arch = "x64"
  273. ?arm
  274. opt_arch = "arm"
  275. ?arm64
  276. opt_arch = "arm64"
  277. ?armeabi
  278. opt_arch = "armeabi"
  279. ?armeabiv7a
  280. opt_arch = "armeabiv7a"
  281. ?arm64v8a
  282. opt_arch = "arm64v8a"
  283. ?js
  284. opt_arch = "js"
  285. ?riscv32
  286. opt_arch = "riscv32"
  287. ?riscv64
  288. opt_arch = "riscv64"
  289. ?
  290. ?win32
  291. opt_platform = "win32"
  292. ?macos
  293. opt_platform = "macos"
  294. ?linux
  295. opt_platform = "linux"
  296. ?android
  297. opt_platform = "android"
  298. ?raspberrypi
  299. opt_platform = "raspberrypi"
  300. ?haiku
  301. opt_platform = "haiku"
  302. ?emscripten
  303. opt_platform = "emscripten"
  304. ?
  305. End Function
  306. Function CheckConfig()
  307. Local config:TConfigMap = New TConfigMap.Init("bcc.conf")
  308. 'try to load an OS-specific path (so all bcc builds could share
  309. 'one single bcc.conf)
  310. Local osBmxPath:String = ""
  311. ?win32
  312. osBmxPath = config.GetString("BMXPATH_WIN32")
  313. ?linux
  314. osBmxPath = config.GetString("BMXPATH_LINUX")
  315. ?macos
  316. osBmxPath = config.GetString("BMXPATH_MACOS")
  317. ?android
  318. ' override BMXPATH_LINUX if available
  319. Local tmp:String = config.GetString("BMXPATH_ANDROID")
  320. If tmp Then
  321. osBmxPath = tmp
  322. End If
  323. ?raspberrypi
  324. ' override BMXPATH_LINUX if available
  325. Local tmp:String = config.GetString("BMXPATH_RASPBERRYPI")
  326. If tmp Then
  327. osBmxPath = tmp
  328. End If
  329. ?haiku
  330. osBmxPath = config.GetString("BMXPATH_HAIKU")
  331. ?
  332. 'load default/generic path
  333. If osBmxPath = "" Then osBmxPath = config.GetString("BMXPATH")
  334. 'replace windows backslashes with crossplatform slashes
  335. osBmxPath = osBmxPath.Replace("\", "/")
  336. If osBmxPath <> "" Then putenv_("BMXPATH="+osBmxPath)
  337. End Function