options.bmx 8.4 KB

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