bmk_config.bmx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. Strict
  2. Import BRL.MaxUtil
  3. Import BRL.StandardIO
  4. ?macos
  5. Import Pub.MacOS
  6. ?
  7. Import brl.map
  8. Import "stringbuffer_core.bmx"
  9. Import "version.bmx"
  10. Const ALL_SRC_EXTS$="bmx;i;c;m;h;cpp;cxx;mm;hpp;hxx;s;cc;asm;S"
  11. Global opt_arch$
  12. Global opt_arch_set=False
  13. Global opt_outfile$
  14. Global opt_infile:String
  15. Global opt_framework$
  16. Global opt_apptype$="console"
  17. Global opt_debug=False
  18. Global opt_threaded=False
  19. Global opt_release=False
  20. Global opt_configmung$=""
  21. Global opt_kill=False
  22. Global opt_modfilter$="."
  23. Global opt_all=False
  24. Global opt_quiet=False
  25. Global opt_verbose=False
  26. Global opt_execute=False
  27. Global opt_appstub$="brl.appstub" ' BaH 28/9/2007
  28. Global opt_universal=False
  29. Global opt_target_platform:String
  30. Global opt_target_platform_set=False
  31. Global opt_gdbdebug=False
  32. Global opt_gdbdebug_set=False
  33. Global opt_standalone=False
  34. Global opt_standalone_set=False
  35. Global opt_nolog
  36. Global opt_quickscan=False
  37. Global opt_quickscan_set=False
  38. Global opt_nostrictupgrade=False
  39. Global opt_nostrictupgrade_set=False
  40. Global opt_warnover=False
  41. Global opt_warnover_set=False
  42. Global opt_musl=False
  43. Global opt_musl_set=False
  44. Global opt_static=False
  45. Global opt_static_set=False
  46. Global opt_boot:Int
  47. Global opt_manifest:Int = True
  48. Global opt_single:Int
  49. Global opt_nodef:Int
  50. Global opt_nohead:Int
  51. Global opt_require_override:Int
  52. Global opt_override_error:Int
  53. Global opt_nopie:Int
  54. Global opt_nopie_set:Int
  55. Global opt_upx:Int
  56. Global opt_userdefs:String
  57. Global opt_gprof:Int
  58. Global opt_hi:Int
  59. Global opt_coverage:Int
  60. Global opt_no_auto_superstrict:Int
  61. Global opt_dumpbuild
  62. 'Global cfg_platform$
  63. Global macos_version:Int=2784 ' 10.14
  64. Global app_main$
  65. Global app_type$
  66. ?MacOS
  67. Function GetVersion:Int()
  68. Local major:Int
  69. Local minor:Int
  70. Local patch:Int
  71. NSOSVersion(major, minor, patch)
  72. Return major Shl 8 | minor Shl 4 | patch
  73. End Function
  74. macos_version = GetVersion()
  75. ?MacOsPPC
  76. If is_pid_native(0) opt_arch="ppc" Else opt_arch="x86"
  77. ?MacOsX86
  78. If is_pid_native(0) opt_arch="x86" Else opt_arch="ppc"
  79. ?MacOsx64
  80. opt_arch="x64"
  81. ?MacOsarm64
  82. opt_arch="arm64"
  83. ?win32x64
  84. opt_arch="x64"
  85. ?Win32x86
  86. opt_arch="x86"
  87. ?win32armv7
  88. opt_arch="armv7"
  89. ?win32arm64
  90. opt_arch="arm64"
  91. ?Win32
  92. 'Fudge PATH so exec sees our MinGW first!
  93. Local mingw$=getenv_( "MINGW" )
  94. If mingw
  95. Local path$=getenv_( "PATH" )
  96. If path
  97. path=mingw+"\bin;"+path
  98. putenv_ "PATH="+path
  99. EndIf
  100. EndIf
  101. ?Linuxx86
  102. opt_arch="x86"
  103. ?linuxx64
  104. opt_arch="x64"
  105. ?linuxarm
  106. opt_arch="arm"
  107. ?linuxarm64
  108. opt_arch="arm64"
  109. ?raspberrypi
  110. opt_arch="arm"
  111. ?raspberrypiarm64
  112. opt_arch="arm64"
  113. ?haikux86
  114. opt_arch="x86"
  115. ?haikux64
  116. opt_arch="x64"
  117. ?linuxRiscv32
  118. opt_arch="riscv32"
  119. ?linuxRiscv64
  120. opt_arch="riscv64"
  121. ?
  122. TStringBuffer.initialCapacity = 128
  123. ChangeDir LaunchDir
  124. Function CmdError(details:String = Null, fullUsage:Int = False)
  125. Local s:String = "Command line error"
  126. If details Then
  127. s:+ " : " + details
  128. End If
  129. s:+ "~n"
  130. s:+ Usage(fullUsage)
  131. Throw s
  132. End Function
  133. Function MissingArg(arg:String)
  134. CmdError "Missing arg for '-" + arg + "'"
  135. End Function
  136. Function ParseConfigArgs$[]( args$[], legacyMax:Int = False )
  137. Local n
  138. If getenv_( "BMKDUMPBUILD" )
  139. opt_dumpbuild=1
  140. opt_quiet=True
  141. EndIf
  142. For n=0 Until args.length
  143. Local arg$=args[n]
  144. If arg[..1]<>"-" Exit
  145. Local argv:String = arg[1..]
  146. Select argv
  147. Case "a", "all"
  148. opt_all=True
  149. Case "q"
  150. opt_quiet=True
  151. Case "v"
  152. opt_verbose=True
  153. Case "x"
  154. opt_execute=True
  155. Case "d", "debug"
  156. opt_debug=True
  157. opt_release=False
  158. Case "r", "release"
  159. opt_debug=False
  160. opt_release=True
  161. Case "h"
  162. opt_threaded=True
  163. Case "k"
  164. opt_kill=True
  165. Case "g", "arch"
  166. n:+1
  167. If n=args.length MissingArg(argv)
  168. opt_arch=args[n].ToLower()
  169. ValidateArch(opt_arch)
  170. opt_arch_set = True
  171. Case "t", "type"
  172. n:+1
  173. If n=args.length MissingArg(argv)
  174. opt_apptype=args[n].ToLower()
  175. Case "o", "output"
  176. n:+1
  177. If n=args.length MissingArg(argv)
  178. opt_outfile=args[n]
  179. Case "f", "framework"
  180. n:+1
  181. If n=args.length MissingArg(argv)
  182. opt_framework=args[n]
  183. Case "b"
  184. n:+1
  185. If n=args.length MissingArg(argv)
  186. opt_appstub=args[n]
  187. Case "i"
  188. ?macos
  189. ' this is mac/ios only... pah!
  190. opt_universal = True
  191. ?
  192. Case "l", "platform"
  193. n:+1
  194. If n=args.length MissingArg(argv)
  195. opt_target_platform=args[n].ToLower()
  196. ValidatePlatform(opt_target_platform)
  197. opt_target_platform_set = True
  198. Case "gdb"
  199. opt_gdbdebug = True
  200. opt_gdbdebug_set = True
  201. Case "standalone"
  202. opt_standalone = True
  203. opt_standalone_set = True
  204. Case "quick"
  205. opt_quickscan = True
  206. opt_quickscan_set = True
  207. Case "nostrictupgrade"
  208. opt_nostrictupgrade = True
  209. opt_nostrictupgrade_set = True
  210. Case "w"
  211. opt_warnover = True
  212. opt_warnover_set = True
  213. Case "musl"
  214. opt_musl = True
  215. opt_musl_set = True
  216. Case "static"
  217. opt_static = True
  218. opt_static_set = True
  219. Case "nomanifest"
  220. opt_manifest = False
  221. Case "single"
  222. opt_single = True
  223. Case "nodef"
  224. opt_nodef = True
  225. Case "nohead"
  226. opt_nohead = True
  227. Case "override"
  228. opt_require_override = True
  229. Case "overerr"
  230. opt_override_error = True
  231. Case "no-pie"
  232. opt_nopie = True
  233. opt_nopie_set = True
  234. Case "upx"
  235. opt_upx = True
  236. Case "ud"
  237. n:+1
  238. If n=args.length MissingArg(argv)
  239. opt_userdefs=args[n]
  240. Case "gprof"
  241. opt_gprof = True
  242. Case "hi"
  243. opt_hi = True
  244. Case "cov"
  245. opt_coverage = True
  246. Case "nas"
  247. opt_no_auto_superstrict = True
  248. Default
  249. CmdError "Invalid option '" + argv + "'"
  250. End Select
  251. Next
  252. If Not legacyMax Then
  253. If opt_threaded And opt_verbose Then
  254. Print "Note: NG builds are threaded by default."
  255. End If
  256. opt_threaded=True
  257. End If
  258. Return args[n..]
  259. End Function
  260. Function CQuote$( t$ )
  261. If t And t[0]=Asc("-") Return t
  262. For Local i=0 Until t.length
  263. If t[i]=Asc(".") Continue
  264. If t[i]=Asc("/") Continue
  265. 'If processor.Platform() = "win32"
  266. If t[i]=Asc("\") Continue
  267. 'End If
  268. If t[i]=Asc("_") Or t[i]=Asc("-") Continue
  269. If t[i]>=Asc("0") And t[i]<=Asc("9") Continue
  270. If t[i]>=Asc("A") And t[i]<=Asc("Z") Continue
  271. If t[i]>=Asc("a") And t[i]<=Asc("z") Continue
  272. Return "~q"+t+"~q"
  273. Next
  274. Return t
  275. End Function
  276. Function ReQuote:String(t:String)
  277. Return t.Replace("~~q", "~q")
  278. End Function
  279. Function CharIsDigit:Int( ch:Int )
  280. Return ch>=Asc("0") And ch<=Asc("9")
  281. End Function
  282. Function CharIsAlpha:Int( ch:Int )
  283. Return ch=Asc("_") Or (ch>=Asc("a") And ch<=Asc("z")) Or (ch>=Asc("A") And ch<=Asc("Z"))
  284. End Function
  285. Function EscapeSpaces:String(path:String)
  286. Return path.Replace(" ", "\\ ")
  287. End Function
  288. Function Usage:String(fullUsage:Int = False)
  289. Local s:String = "~nUsage: bmk <operation> [options] source~n~n"
  290. If Not fullUsage Then
  291. s:+ "(start bmk with no parameters for more usage information)~n~n"
  292. Else
  293. s:+ "Operations :~n"
  294. s:+ "~tmakeapp~n"
  295. s:+ "~t~tBuilds an application from a single root source file."
  296. s:+ "~n~n"
  297. s:+ "~tmakelib~n"
  298. s:+ "~t~tBuilds a shared library/DLL file from a single root source file."
  299. s:+ "~n~n"
  300. s:+ "~tmakemods~n"
  301. s:+ "~t~tBuilds a set of modules."
  302. s:+ "~n~n"
  303. s:+ "Options :~n"
  304. s:+ "~t-a | -all~n"
  305. s:+ "~t~tRecompile all source/modules regardless of timestamp. By default, only those modified~n" + ..
  306. "~t~tsince the last build are recompiled."
  307. s:+ "~n~n"
  308. s:+ "~t-b <custom appstub module>~n"
  309. s:+ "~t~tBuilds an app using a custom appstub (i.e. not BRL.Appstub).~n"
  310. s:+ "~t~tThis can be useful when you want more control over low-level application state."
  311. s:+ "~n~n"
  312. s:+ "~t-cov~n"
  313. s:+ "~t~tBuilds a version with code coverage information.~n"
  314. s:+ "~t~tBy default, when the application ends, an lcov.info is produced.~n"
  315. s:+ "~t~tThis can be used by a variety of tools to generate coverage reports."
  316. s:+ "~n~n"
  317. s:+ "~t-d | -debug~n"
  318. s:+ "~t~tBuilds a debug version. (This is the default for makeapp)."
  319. s:+ "~n~n"
  320. s:+ "~t-g <architecture> | -arch <architecture>~n"
  321. s:+ "~t~tCompiles to the specified architecture. (the default is the native for this binary - "
  322. ?x86
  323. s:+ "x86"
  324. ?x64
  325. s:+ "x64"
  326. ?ppc
  327. s:+ "ppc"
  328. ?arm
  329. s:+ "arm"
  330. ?arm64
  331. s:+ "arm64"
  332. ?armeabi
  333. s:+ "armeabi"
  334. ?armeabiv7a
  335. s:+ "armeabiv7a"
  336. ?arm64v8a
  337. s:+ "arm64v8a"
  338. ?js
  339. s:+ "js"
  340. ?riscv32
  341. s:+ "riscv32"
  342. ?riscv64
  343. s:+ "riscv64"
  344. ?
  345. s:+ ")~n"
  346. s:+ "~t~tOptions vary depending on the current OS/architecture/installed toolchain and version of bcc.~n"
  347. s:+ "~t~t~tMacOS : x86, x64, arm64~n"
  348. s:+ "~t~t~tWin32 : x86, x64, armv7, armv64~n"
  349. s:+ "~t~t~tLinux : x86, x64, arm, arm64, riscv32, riscv64~n"
  350. s:+ "~t~t~tiOS : x86, x64 (simulator), armv7, arm64~n"
  351. s:+ "~t~t~tAndroid : x86, x64, arm, armeabi, armeabiv7a, arm64v8a~n"
  352. s:+ "~t~t~tRaspberryPi : arm, arm64~n"
  353. s:+ "~t~t~tnx : arm64~n"
  354. s:+ "~t~t~thaiku : x86, x64~n"
  355. s:+ "~n~n"
  356. s:+ "~t-gdb~n"
  357. s:+ "~t~tGenerates line mappings suitable for GDB debugging.~n"
  358. s:+ "~t~tBacktrace (etc.) will show .bmx relative source lines rather than that of the generated code."
  359. s:+ "~n~n"
  360. s:+ "~t-gprof~n"
  361. s:+ "~t~tCompiles for gprof profiling.~n"
  362. s:+ "~n~n"
  363. s:+ "~t-h~n"
  364. s:+ "~t~tBuild multithreaded version. (This is the default on NG)~n"
  365. s:+ "~t~tThe default on legacy BlitzMax is to build non-threaded. On legacy, using this option will also~n"
  366. s:+ "~t~tadd a .mt suffix to the executable."
  367. s:+ "~n~n"
  368. s:+ "~t-hi~n"
  369. s:+ "~t~tSpecifies that the application supports high-resolution screens (HiDPI). (GUI only)~n"
  370. s:+ "~t~tThis will, for example, configure the macOS bundle with the appropriate plist settings."
  371. s:+ "~n~n"
  372. s:+ "~t-i~n"
  373. s:+ "~t~tCreates a Universal build for supported platforms.~n"
  374. s:+ "~t~t(see documentation for full list of requirements)"
  375. s:+ "~n~n"
  376. s:+ "~t-l <target platfom> | -platform <target platform>~n"
  377. s:+ "~t~tCross-compiles to the specific target platform.~n"
  378. s:+ "~t~tValid targets are win32, linux, macos, ios, android, raspberrypi and haiku.~n"
  379. s:+ "~t~t(see documentation for full list of requirements)"
  380. s:+ "~n~n"
  381. s:+ "~t-musl~n"
  382. s:+ "~t~tEnable musl libc compatibility. (Linux NG only)"
  383. s:+ "~n~n"
  384. s:+ "~t-nomanifest~n"
  385. s:+ "~t~tDon't add an automatically generated manifest and resources to a Win32 application. (Win32 only)~n"
  386. s:+ "~t~tName .ico file as <app name>.ico to be included in the the resource.~n"
  387. s:+ "~t~tConfigurable application details are placed in the file <app name>.settings"
  388. s:+ "~n~n"
  389. s:+ "~t-nostrictupgrade~n"
  390. s:+ "~t~tDon't upgrade strict method void return types, if required. (NG only)~n"
  391. s:+ "~t~tIf a Strict sub type overrides the method of a SuperStrict type and the return type is void,~n"
  392. s:+ "~t~tdon't upgrade the return type to void (i.e. none), and default it to Int."
  393. s:+ "~n~n"
  394. s:+ "~t-o <output file> | -output <output file>~n"
  395. s:+ "~t~tSpecify output file. (makeapp only)~n"
  396. s:+ "~t~tBy default, the output file is placed into the same directory as the root source file."
  397. s:+ "~n~n"
  398. s:+ "~t-override~n"
  399. s:+ "~t~tWarn if overriding methods are not declared with Override property (NG only)~n"
  400. s:+ "~n~n"
  401. s:+ "~t-overerr~n"
  402. s:+ "~t~tUpgrades -override warnings to errors. (NG only)~n"
  403. s:+ "~n~n"
  404. s:+ "~t-no-pie~n"
  405. s:+ "~t~tDisables option to compile position independent executables. (NG & Linux only)~n"
  406. s:+ "~n~n"
  407. s:+ "~t-q~n"
  408. s:+ "~t~tQuiet build."
  409. s:+ "~n~n"
  410. s:+ "~t-quick~n"
  411. s:+ "~t~tQuick build.~n"
  412. s:+ "~t~tDoes not scans modules for changes. May result in quicker build times on some systems.~n"
  413. s:+ "~t~tThe default behaviour is to scan and build all requirements for the application,~n"
  414. s:+ "~t~tincluding modules."
  415. s:+ "~n~n"
  416. s:+ "~t-r | -release~n"
  417. s:+ "~t~tBuilds a release version."
  418. s:+ "~n~n"
  419. s:+ "~t-standalone~n"
  420. s:+ "~t~tGenerate but do not compile into binary form.~n"
  421. s:+ "~t~tUseful for creating ready-to-build source for a different platform/architecture."
  422. s:+ "~n~n"
  423. s:+ "~t-static~n"
  424. s:+ "~t~tStatically link binary. (Linux NG only)"
  425. s:+ "~n~n"
  426. s:+ "~t-t <app type> | -type <app type>~n"
  427. s:+ "~t~tSpecify application type. (makeapp only)~n"
  428. s:+ "~t~tShould be either 'console' or 'gui' (without single quote!).~n"
  429. s:+ "~t~tThe default is console."
  430. s:+ "~n~n"
  431. s:+ "~t-ud <definitions>~n"
  432. s:+ "~t~tAdd user defined compiler options. (NG only).~n"
  433. s:+ "~t~tA comma-separated list of compiler options that can be used in addition to the defaults.~n"
  434. s:+ "~t~tAlternatively, the option 'adddef' can be used in build scripts to provide the same.~n"
  435. s:+ "~n~n"
  436. s:+ "~t-upx~n"
  437. s:+ "~t~tPack binary using UPX. (makeapp only)."
  438. s:+ "~n~n"
  439. s:+ "~t-v~n"
  440. s:+ "~t~tVerbose (noisy) build."
  441. s:+ "~n~n"
  442. s:+ "~t-w~n"
  443. s:+ "~t~tWarn about function argument casting issues rather than error. (NG only)~n"
  444. s:+ "~t~tWith this warning enabled you may have issues with method overloading."
  445. s:+ "~n~n"
  446. s:+ "~t-x~n"
  447. s:+ "~t~tExecute built application. (makeapp only)"
  448. s:+ "~n~n"
  449. End If
  450. Return s
  451. End Function
  452. Function VersionInfo(gcc:String, cores:Int, xcode:String)
  453. Local s:String = "bmk "
  454. s:+ BMK_VERSION + " "
  455. ?threaded
  456. s:+ "mt-"
  457. ?
  458. ?win32
  459. s:+ "win32"
  460. ?linux
  461. s:+ "linux"
  462. ?macos
  463. s:+ "macos"
  464. ?osx
  465. s:+ "-osx"
  466. ?ios
  467. s:+ "-ios"
  468. ?android
  469. s:+ "-android"
  470. ?raspberrypi
  471. s:+ "-raspberrypi"
  472. ?haiku
  473. s:+ "haiku"
  474. ?emscripten
  475. s:+ "-emscripten"
  476. ?
  477. s:+ "-"
  478. ?x86
  479. s:+ "x86"
  480. ?ppc
  481. s:+ "ppc"
  482. ?x64
  483. s:+ "x64"
  484. ?arm
  485. s:+ "arm"
  486. ?arm64
  487. s:+ "arm64"
  488. ?armeabi
  489. s:+ "armeabi"
  490. ?armeabiv7a
  491. s:+ "armeabiv7a"
  492. ?arm64v8a
  493. s:+ "arm64v8a"
  494. ?js
  495. s:+ "js"
  496. ?riscv32
  497. s:+ "riscv32"
  498. ?riscv64
  499. s:+ "riscv64"
  500. ?
  501. s:+ " / " + gcc
  502. If xcode Then
  503. s:+ " / xcode " + xcode
  504. End If
  505. s:+ " (cpu x" + cores + ")"
  506. Print s + "~n"
  507. End Function
  508. Function AsConfigurable:Int(key:String, value:String)
  509. Local config:Int = False
  510. Local set:Int = 0
  511. Select key
  512. Case "opt_warnover"
  513. If Not opt_warnover_set Then
  514. opt_warnover = Int(value)
  515. set = 1
  516. Else
  517. If opt_warnover <> Int(value) Then
  518. set = 2
  519. End If
  520. End If
  521. config = True
  522. Case "opt_quickscan"
  523. If Not opt_quickscan_set Then
  524. opt_quickscan = Int(value)
  525. set = 1
  526. Else
  527. If opt_quickscan <> Int(value) Then
  528. set = 2
  529. End If
  530. End If
  531. config = True
  532. Case "opt_gdbdebug"
  533. If Not opt_gdbdebug_set Then
  534. opt_gdbdebug = Int(value)
  535. set = 1
  536. Else
  537. If opt_gdbdebug <> Int(value) Then
  538. set = 2
  539. End If
  540. End If
  541. config = True
  542. Case "opt_standalone"
  543. If Not opt_standalone_set Then
  544. opt_standalone = Int(value)
  545. set = 1
  546. Else
  547. If opt_standalone <> Int(value) Then
  548. set = 2
  549. End If
  550. End If
  551. config = True
  552. Case "opt_nostrictupgrade"
  553. If Not opt_nostrictupgrade_set Then
  554. opt_nostrictupgrade = Int(value)
  555. set = 1
  556. Else
  557. If opt_nostrictupgrade <> Int(value) Then
  558. set = 2
  559. End If
  560. End If
  561. config = True
  562. Case "opt_arch"
  563. If Not opt_arch_set Then
  564. opt_arch = value.ToLower()
  565. ValidateArch(opt_arch)
  566. set = 1
  567. Else
  568. If opt_arch <> value.ToLower() Then
  569. set = 2
  570. End If
  571. End If
  572. config = True
  573. Case "opt_target_platform"
  574. If Not opt_target_platform_set Then
  575. opt_target_platform = value.ToLower()
  576. ValidatePlatform(opt_target_platform)
  577. set = 1
  578. Else
  579. If opt_target_platform <> value.ToLower() Then
  580. set = 2
  581. End If
  582. End If
  583. config = True
  584. Case "opt_musl"
  585. If Not opt_musl_set Then
  586. opt_musl = Int(value)
  587. set = 1
  588. Else
  589. If opt_musl <> Int(value) Then
  590. set = 2
  591. End If
  592. End If
  593. config = True
  594. Case "opt_static"
  595. If Not opt_static_set Then
  596. opt_static = Int(value)
  597. set = 1
  598. Else
  599. If opt_static <> Int(value) Then
  600. set = 2
  601. End If
  602. End If
  603. config = True
  604. Case "opt_nopie"
  605. If Not opt_nopie_set Then
  606. opt_nopie = Int(value)
  607. set = 1
  608. Else
  609. If opt_nopie <> Int(value) Then
  610. set = 2
  611. End If
  612. End If
  613. config = True
  614. End Select
  615. If set And opt_verbose Then
  616. If set = 1 Then
  617. Print "Using " + key.ToUpper() + " = " + value
  618. Else
  619. Print "Config " + key.ToUpper() + " = " + value + " was NOT used because command-line arguments override it"
  620. End If
  621. End If
  622. Return config
  623. End Function
  624. Function ValidateArch(arch:String)
  625. Select arch
  626. Case "ppc"
  627. Case "x86"
  628. Case "x64"
  629. Case "arm"
  630. Case "armeabi"
  631. Case "armeabiv7a"
  632. Case "arm64v8a"
  633. Case "armv7"
  634. Case "arm64"
  635. Case "js"
  636. Case "riscv32"
  637. Case "riscv64"
  638. Default
  639. CmdError "Not a valid architecture : '" + arch + "'"
  640. End Select
  641. End Function
  642. Function ValidatePlatform(platform:String)
  643. Select platform
  644. Case "win32"
  645. Case "macos"
  646. Case "osx"
  647. Case "ios"
  648. Case "linux"
  649. Case "android"
  650. Case "raspberrypi"
  651. Case "emscripten"
  652. Case "nx"
  653. Case "haiku"
  654. Default
  655. ' oops
  656. CmdError "Not valid platform : '" + platform + "'"
  657. End Select
  658. End Function
  659. Function ParseApplicationIniFile:TMap()
  660. Local ids:String[] = [StripDir(StripExt(opt_outfile)), StripDir(StripExt(opt_infile))]
  661. Local appId:String = ids[0]
  662. Local buildDir:String = ExtractDir(opt_infile)
  663. Local path:String
  664. Local found:Int
  665. Local settings:TMap = New TMap
  666. For Local id:String = EachIn ids
  667. path = buildDir + "/" + id + ".settings"
  668. If Not FileType(path) Then
  669. If opt_verbose Then
  670. Print "Not Found : application settings file '" + id + ".settings'."
  671. End If
  672. Continue
  673. End If
  674. found = True
  675. Exit
  676. Next
  677. If Not found Then
  678. If opt_verbose Then
  679. Print "Using defaults."
  680. End If
  681. Return DefaultApplicationSettings()
  682. End If
  683. Local file:TStream = ReadFile(path)
  684. If Not file
  685. Return Null
  686. EndIf
  687. Local line:String
  688. Local pos:Int
  689. While Not Eof(file)
  690. line = ReadLine(file).Trim()
  691. If line.Find("#") = 0 Then
  692. Continue
  693. End If
  694. pos = line.Find("=")
  695. If pos = -1 Then
  696. Continue
  697. End If
  698. settings.Insert(line[..pos], line[pos+1..])
  699. Wend
  700. file.Close()
  701. Local id:String = StripDir(StripExt(opt_outfile))
  702. If opt_debug And opt_outfile.EndsWith(".debug") Then
  703. id :+ ".debug"
  704. End If
  705. settings.Insert("app.id", id)
  706. If Not settings.Contains("app.version.major") Then
  707. Local version:String = String(settings.ValueForKey("app.version.name"))
  708. If version Then
  709. Local parts:String[] = version.Split(".")
  710. For Local i:Int = 0 Until parts.length
  711. Select i
  712. Case 0
  713. settings.Insert("app.version.major", String.FromInt(parts[i].ToInt()))
  714. Case 1
  715. settings.Insert("app.version.minor", String.FromInt(parts[i].ToInt()))
  716. Case 2
  717. settings.Insert("app.version.patch", String.FromInt(parts[i].ToInt()))
  718. Case 3
  719. settings.Insert("app.version.build", String.FromInt(parts[i].ToInt()))
  720. End Select
  721. Next
  722. End If
  723. End If
  724. Return settings
  725. End Function
  726. Function DefaultApplicationSettings:TMap()
  727. Local appId:String = StripDir(StripExt(opt_outfile))
  728. If opt_debug And opt_outfile.EndsWith(".debug") Then
  729. appId :+ ".debug"
  730. End If
  731. Local settings:TMap = New TMap
  732. settings.Insert("app.package", "com.blitzmax.app")
  733. settings.Insert("app.version.code", "1")
  734. settings.Insert("app.version.name", "1.0.0")
  735. settings.Insert("app.name", appId)
  736. settings.Insert("app.orientation", "landscape")
  737. settings.Insert("app.comments", "BlitzMax Application")
  738. settings.Insert("app.company", "My company")
  739. settings.Insert("app.description", appId)
  740. settings.Insert("app.copyright", "Copyright")
  741. settings.Insert("app.trademarks", "All rights reserved")
  742. settings.Insert("app.id", appId)
  743. Return settings
  744. End Function