make.bmk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. #!BMK
  2. @define assemble
  3. local src = nvl(arg1, %infile%)
  4. local obj = nvl(arg2, %outfile%)
  5. if bmk.Platform() == "macos" then
  6. if bmk.CPU() == "ppc" then
  7. cmd = "as -arch ppc"
  8. elseif bmk.CPU() == "x86" then
  9. cmd = "as -arch i386"
  10. else
  11. cmd = "as -arch x86_64"
  12. end
  13. cmd = cmd .. " -W -o " .. bmk.Quote(obj) .. " " .. bmk.Quote(src)
  14. else
  15. if bmk.Platform() == "win32" then
  16. local prefix = bmk.Option("path_to_wine", "")
  17. if prefix ~= "" then
  18. prefix = prefix .. " "
  19. end
  20. cmd = prefix .. bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm.exe") .. " "
  21. else
  22. cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm") .. " "
  23. end
  24. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  25. cmd = cmd .. " -m32768 "
  26. end
  27. cmd = cmd .. bmk.Quote(src) .. " " .. bmk.Quote(obj)
  28. end
  29. if bmk.MultiSys(cmd, src, obj, "") ~= 0 then
  30. bmk.ThrowNew("Build Error: Failed to assemble " .. src)
  31. end
  32. @end
  33. @define assembleNative
  34. local src = nvl(arg1, %infile%)
  35. local obj = nvl(arg2, %outfile%)
  36. local nativeAssembler = bmk.Option("native.assembler", "as")
  37. local asmPath = bmk.Option(bmk.BuildName(nativeAssembler), nativeAssembler)
  38. cmd = asmPath
  39. if nativeAssembler == "as" then
  40. if bmk.Platform() == "win32" then
  41. if bmk.CPU() == "x86" then
  42. cmd = cmd .. " -arch i686"
  43. else
  44. cmd = cmd .. " -arch generic64"
  45. end
  46. end
  47. cmd = cmd .. " -W"
  48. end
  49. if nativeAssembler == "nasm" or nativeAssembler == "yasm" then
  50. if bmk.Platform() == "win32" then
  51. if bmk.CPU() == "x86" then
  52. cmd = cmd .. " -f win32"
  53. else
  54. cmd = cmd .. " -f win64"
  55. end
  56. end
  57. if bmk.Platform() == "linux" then
  58. if bmk.CPU() == "x86" then
  59. cmd = cmd .. " -f elf32"
  60. else
  61. cmd = cmd .. " -f elf64"
  62. end
  63. end
  64. if bmk.Platform() == "macos" then
  65. if bmk.CPU() == "x86" then
  66. cmd = cmd .. " -f macho32"
  67. else
  68. cmd = cmd .. " -f macho64"
  69. end
  70. end
  71. end
  72. if nativeAssembler == "as" or nativeAssembler == "nasm" or nativeAssembler == "yasm" then
  73. cmd = cmd .. " -o " .. bmk.Quote(obj) .. " " .. bmk.Quote(src)
  74. end
  75. if nativeAssembler == "fasm" then
  76. cmd = cmd .. " " .. bmk.Quote(src) .. " " .. bmk.Quote(obj)
  77. end
  78. if bmk.MultiSys(cmd, src, obj, "") ~= 0 then
  79. bmk.ThrowNew("Build Error: Failed to assemble " .. src)
  80. end
  81. @end
  82. @define compileBMX
  83. local src = nvl(arg1, %infile%)
  84. local obj = nvl(arg2, %outfile%)
  85. local opts = nvl(arg3, %options%)
  86. local gen = ""
  87. azm = sys.StripExt(obj)
  88. if bmk.BCCVersion() == "BlitzMax" then
  89. # remove any "NG" generated source.
  90. gen = azm .. ".c"
  91. else
  92. # remove any "legacy" generated source.
  93. gen = azm .. ".s"
  94. end
  95. azm = azm .. ".s"
  96. local bcc_app = "bcc"
  97. # if we are doing a universal build, be sure and call the correct bcc!
  98. if %universal% == "1" and bmk.CPU() == "ppc" then
  99. bcc_app = bcc_app .. "_ppc"
  100. end
  101. if bmk.OSPlatform() == "win32" then
  102. bcc_app = bcc_app .. ".exe"
  103. end
  104. local prefix = ""
  105. if bmk.Platform() == "win32" then
  106. prefix = bmk.Option("path_to_wine", "")
  107. if prefix ~= "" then
  108. prefix = prefix .. " "
  109. end
  110. end
  111. cmd = prefix .. bmk.Quote(utils.BlitzMaxPath() .. "/bin/" .. bcc_app) .." " .. opts .. " -o " .. bmk.Quote(azm) .. " " .. bmk.Quote(src)
  112. if bmk.MultiSys( cmd, src, obj, gen ) ~= 0 then
  113. bmk.ThrowNew("Build Error: failed to compile " .. src)
  114. end
  115. #if bmk.Platform() == "macos" and bmk.CPU() == "x86" and bmk.BCCVersion() == "BlitzMax" then
  116. # cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm2as") .. " " .. bmk.Quote(azm)
  117. # if bmk.Sys( cmd ) ~= 0 then
  118. # bmk.ThrowNew("Fasm2as failed - please contact BRL!")
  119. # end
  120. #end
  121. # TODO : we can't call another generated function from here... so we'd need to make sure this is called elsewhere.
  122. #assemble(nil, azm, obj)
  123. @end
  124. @define fasm2as
  125. local src = nvl(arg1, %infile%)
  126. local obj = nvl(arg2, %outfile%)
  127. local azm = sys.StripExt(obj) .. ".s"
  128. if bmk.Platform() == "macos" and bmk.CPU() == "x86" and bmk.BCCVersion() == "BlitzMax" then
  129. cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm2as") .. " " .. bmk.Quote(azm)
  130. if bmk.MultiSys( cmd, "", "", "" ) ~= 0 then
  131. bmk.ThrowNew("Fasm2as failed - please contact BRL!")
  132. end
  133. end
  134. @end
  135. @define compileC
  136. local src = nvl(arg1, %infile%)
  137. local obj = nvl(arg2, %outfile%)
  138. local opts = arg3
  139. #opts = opts .. " " .. %cc_opts% .. " " .. %BMK_CC_OPTS%
  140. local ext = sys.ExtractExt(src)
  141. if bmk.Platform() == "macos" or bmk.Platform() == "osx" or bmk.Platform() == "ios" then
  142. if bmk.Platform() == "macos" or bmk.Platform() == "osx" then
  143. cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
  144. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  145. cmd = bmk.Option(bmk.BuildName("gpp"), "g++")
  146. end
  147. else
  148. cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
  149. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  150. cmd = bmk.Option(bmk.BuildName("gpp"), "g++")
  151. end
  152. end
  153. # need to use gcc, not llvm...
  154. # 10.7
  155. # but for 10.8 we have no choice...
  156. if tonumber(%macos_version%) >= 4208 and tonumber(%macos_version%) < 4224 then
  157. cmd = cmd .. "-4.2"
  158. end
  159. if bmk.CPU() == "ppc" and (bmk.Platform() == "macos" or bmk.Platform() == "osx") then
  160. cmd = cmd .. " -arch ppc "
  161. elseif bmk.CPU() == "x86" then
  162. cmd = cmd .. " -arch i386 "
  163. elseif bmk.CPU() == "x64" then
  164. cmd = cmd .. " -arch x86_64 "
  165. elseif bmk.CPU() == "armv7" and bmk.Platform() == "ios" then
  166. cmd = cmd .. " -arch armv7 "
  167. elseif bmk.CPU() == "arm64" then
  168. cmd = cmd .. " -arch arm64 "
  169. end
  170. if bmk.Option(bmk.BuildName("sysroot"), "") ~= "" then
  171. cmd = cmd .. " -isysroot " .. bmk.Option(bmk.BuildName("sysroot"), "")
  172. end
  173. elseif bmk.Platform() == "win32" then
  174. local prefix = bmk.MinGWExePrefix()
  175. if bmk.OSPlatform() == "win32" then
  176. ext = ".exe"
  177. else
  178. ext = ""
  179. end
  180. cmd = bmk.Option("path_to_gcc", bmk.MinGWBinPath() .. "/" .. prefix .. "gcc" .. ext)
  181. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  182. cmd = bmk.Option("path_to_gpp", bmk.MinGWBinPath() .. "/" .. prefix .. "g++" .. ext)
  183. end
  184. elseif bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" or bmk.Platform() == "haiku" then
  185. cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
  186. if bmk.Option("nopie", "") == "true" then
  187. globals.SetOption("cc_opts", "pie", "")
  188. end
  189. elseif bmk.Platform() == "emscripten" then
  190. cmd = bmk.Option(bmk.BuildName("gcc"), "emcc")
  191. cmd = cmd .. " -Wno-warn-absolute-paths "
  192. elseif bmk.Platform() == "nx" then
  193. cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
  194. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  195. cmd = bmk.Option(bmk.BuildName("gpp"), "g++")
  196. end
  197. end
  198. if bmk.Platform() == "nx" then
  199. cmd = cmd .. " -ffunction-sections"
  200. cmd = cmd .. " -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE"
  201. cmd = cmd .. " -I" .. bmk.Option("nx.devkitpro", "") .. "/libnx/include"
  202. cmd = cmd .. " -I" .. bmk.Option("nx.devkitpro", "")
  203. cmd = cmd .. " -I" .. bmk.Option("nx.devkitpro", "") .. "/portlibs/switch/include"
  204. end
  205. # disable warnings ?
  206. if %CC_WARNINGS% == "" then
  207. opts = opts .. " -w"
  208. end
  209. if bmk.BCCVersion() ~= "BlitzMax" then
  210. opts = opts .. " -DBMX_NG"
  211. if bmk.Platform() == "nx" then
  212. opts = opts .. " -D__SWITCH__"
  213. end
  214. end
  215. local genDebug = ""
  216. if bmk.IsDebugBuild() == 1 then
  217. genDebug = " -g"
  218. end
  219. # Remove -fno-exceptions if we have provided -fexceptions
  220. local cc_opts = %cc_opts%
  221. if cc_opts:find("-fexceptions") ~= nil then
  222. cc_opts = cc_opts:gsub("%-fno%-exceptions", print)
  223. end
  224. if opts:find("-fexceptions") ~= nil then
  225. cc_opts = cc_opts:gsub("%-fno%-exceptions", "")
  226. end
  227. cmd = cmd .. opts .. cc_opts .. %mod_ccopts% .. genDebug .. " -o " .. bmk.Quote(obj) .. " " .. bmk.Quote(src)
  228. if bmk.MultiSys( cmd, src, obj, "" ) ~= 0 then
  229. bmk.ThrowNew("Build Error: failed to compile " .. src)
  230. end
  231. @end
  232. @define addresourcepath
  233. globals.Add("resource_path", arg1)
  234. @end
  235. @define addlib
  236. globals.Add("libs", arg1)
  237. @end
  238. @define addoption
  239. globals.Add(arg1, arg2, 0)
  240. @end
  241. @define setoption
  242. globals.Add(arg1, arg2, 1)
  243. @end
  244. ## adds a cc_opt option
  245. @define addccopt
  246. globals.AddOption("cc_opts", arg1, arg2)
  247. @end
  248. @define setccopt
  249. globals.SetOption("cc_opts", arg1, arg2)
  250. @end
  251. @define addwin32ccopt
  252. if bmk.Platform() == "win32" then
  253. globals.AddOption("cc_opts", arg1, arg2)
  254. end
  255. @end
  256. @define setwin32ccopt
  257. if bmk.Platform() == "win32" then
  258. globals.SetOption("cc_opts", arg1, arg2)
  259. end
  260. @end
  261. @define setwin32x86ccopt
  262. if bmk.Platform() == "win32" and bmk.CPU() == "x86" then
  263. globals.SetOption("cc_opts", arg1, arg2)
  264. end
  265. @end
  266. @define setwin32x64ccopt
  267. if bmk.Platform() == "win32" and bmk.CPU() == "x64" then
  268. globals.SetOption("cc_opts", arg1, arg2)
  269. end
  270. @end
  271. @define addmacccopt
  272. if bmk.Platform() == "macos" then
  273. globals.AddOption("cc_opts", arg1, arg2)
  274. end
  275. @end
  276. @define setmacccopt
  277. if bmk.Platform() == "macos" then
  278. globals.SetOption("cc_opts", arg1, arg2)
  279. end
  280. @end
  281. @define addmacppcccopt
  282. if bmk.Platform() == "macos" and bmk.CPU() == "ppc" then
  283. globals.AddOption("cc_opts", arg1, arg2)
  284. end
  285. @end
  286. @define setmacppcccopt
  287. if bmk.Platform() == "macos" and bmk.CPU() == "ppc" then
  288. globals.SetOption("cc_opts", arg1, arg2)
  289. end
  290. @end
  291. @define addmacx86ccopt
  292. if bmk.Platform() == "macos" and bmk.CPU() == "x86" then
  293. globals.AddOption("cc_opts", arg1, arg2)
  294. end
  295. @end
  296. @define setmacx86ccopt
  297. if bmk.Platform() == "macos" and bmk.CPU() == "x86" then
  298. globals.SetOption("cc_opts", arg1, arg2)
  299. end
  300. @end
  301. @define addlinuxccopt
  302. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  303. globals.AddOption("cc_opts", arg1, arg2)
  304. end
  305. @end
  306. @define setlinuxccopt
  307. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  308. globals.SetOption("cc_opts", arg1, arg2)
  309. end
  310. @end
  311. @define addasmopt
  312. globals.AddOption("asm_opts", arg1, arg2)
  313. @end
  314. ## removes a cc_opt option
  315. @define rmccopt
  316. globals.Remove("cc_opts", arg1)
  317. @end
  318. @define rmasmopt
  319. globals.Remove("asm_opts", arg1)
  320. @end
  321. @define addldopt
  322. globals.AddOption("ld_opts", arg1, arg2)
  323. @end
  324. @define setldopt
  325. globals.SetOption("ld_opts", arg1, arg2)
  326. @end
  327. @define addwin32ldopt
  328. if bmk.Platform() == "win32" then
  329. globals.AddOption("ld_opts", arg1, arg2)
  330. end
  331. @end
  332. @define addmacldopt
  333. if bmk.Platform() == "macos" then
  334. globals.AddOption("ld_opts", arg1, arg2)
  335. end
  336. @end
  337. @define addlinuxldopt
  338. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  339. globals.AddOption("ld_opts", arg1, arg2)
  340. end
  341. @end
  342. @define setmacldopt
  343. if bmk.Platform() == "macos" then
  344. globals.SetOption("ld_opts", arg1, arg2)
  345. end
  346. @end
  347. @define setwin32ldopt
  348. if bmk.Platform() == "win32" then
  349. globals.SetOption("ld_opts", arg1, arg2)
  350. end
  351. @end
  352. @define setlinuxldopt
  353. if bmk.Platform() == "linux" then
  354. globals.SetOption("ld_opts", arg1, arg2)
  355. end
  356. @end
  357. @define setraspberrypildopt
  358. if bmk.Platform() == "raspberrypi" then
  359. globals.SetOption("ld_opts", arg1, arg2)
  360. end
  361. @end
  362. # compiles the specified file, using the current options.
  363. @define make
  364. make.Make(arg1)
  365. @end
  366. @define skipmod
  367. globals.Add("skip_mod", arg1)
  368. @end
  369. @define skipmodwin32
  370. if bmk.Platform() == "win32" then
  371. globals.Add("skip_mod", arg1)
  372. end
  373. @end
  374. @define skipmodmac
  375. if bmk.Platform() == "macos" then
  376. globals.Add("skip_mod", arg1)
  377. end
  378. @end
  379. @define skipmodlinux
  380. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  381. globals.Add("skip_mod", arg1)
  382. end
  383. @end
  384. @define adddef
  385. globals.AddC("user_defs", arg1)
  386. @end
  387. # the default ccopts
  388. # used for compiling c-type files
  389. @define default_cc_opts
  390. globals.Clear("cc_opts")
  391. if bmk.Platform() == "macos" or bmk.Platform() == "osx" then
  392. if tonumber(%macos_version%) >= 2800 then
  393. # macos version >= 10.15.0 ?
  394. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.15")
  395. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.15")
  396. globals.SetOption("ld_opts", "stdlib", "-stdlib=libc++")
  397. elseif tonumber(%macos_version%) >= 2784 then
  398. # macos version >= 10.14.0 ?
  399. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.12")
  400. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.12")
  401. globals.SetOption("ld_opts", "stdlib", "-stdlib=libc++")
  402. elseif tonumber(%macos_version%) >= 2752 then
  403. # macos version >= 10.12.0 ?
  404. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.9")
  405. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.9")
  406. globals.SetOption("ld_opts", "stdlib", "-stdlib=libc++")
  407. elseif tonumber(%macos_version%) >= 2704 then
  408. # macos version >= 10.9.0 ?
  409. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.7")
  410. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.7")
  411. elseif tonumber(%macos_version%) >= 2688 then
  412. # macos version >= 10.8.0 ?
  413. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.5")
  414. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.5")
  415. elseif tonumber(%macos_version%) >= 2672 then
  416. # macos version >= 10.7.0 ?
  417. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.4")
  418. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.4")
  419. elseif tonumber(%macos_version%) >= 2640 then
  420. # macos version >= 10.5.0 ?
  421. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.3")
  422. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.3")
  423. else
  424. # otherwise, fallback on same as latest (10.6)
  425. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.6")
  426. globals.SetOption("ld_opts", "osversion", "-mmacosx-version-min=10.6")
  427. end
  428. elseif bmk.Platform() == "ios" then
  429. globals.SetOption("cc_opts", "osversion", "-miphoneos-version-min=10.0.0")
  430. globals.SetOption("cc_opts", "ostarget", "-target arm64-apple-ios10.0")
  431. elseif bmk.Platform() == "win32" then
  432. if bmk.HasClang() == 1 then
  433. globals.SetOption("cc_opts", "win_family", "-DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP")
  434. else
  435. if bmk.hasTarget("x86_64") then
  436. if bmk.CPU() == "x86" then
  437. globals.SetOption("cc_opts", "arch", "-m32")
  438. elseif bmk.CPU() == "x64" then
  439. globals.SetOption("cc_opts", "arch", "-m64")
  440. end
  441. else
  442. globals.SetOption("cc_opts", "arch", "-march=pentium")
  443. end
  444. end
  445. globals.SetOption("cc_opts", "fastmath", "-ffast-math")
  446. elseif bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" or bmk.Platform() == "emscripten" or bmk.Platform() == "haiku" then
  447. globals.SetOption("cc_opts", "aliasing", "-fno-strict-aliasing")
  448. if bmk.CPU() == "x86" then
  449. globals.SetOption("cc_opts", "arch", "-m32")
  450. globals.SetOption("cc_opts", "fancymath", "-mfancy-math-387")
  451. end
  452. if bmk.Platform() ~= "haiku" then
  453. globals.SetOption("cc_opts", "pie", "-fpie")
  454. end
  455. end
  456. globals.SetOption("cc_opts", "exceptions", "-fno-exceptions")
  457. globals.SetOption("cc_opts", "linker", "-c")
  458. if bmk.IsGdbDebugBuild() == 0 then
  459. if bmk.Platform() ~= "nx" then
  460. globals.SetOption("cc_opts", "optimization", "-O3")
  461. else
  462. globals.SetOption("cc_opts", "optimization", "-O2")
  463. end
  464. if bmk.CPU() == "x64" then
  465. globals.SetOption("cc_opts", "simd", "-msse3")
  466. end
  467. if bmk.IsDebugBuild() == 0 then
  468. if bmk.Platform() ~= "emscripten" then
  469. globals.SetOption("cc_opts", "stripsymbols", "-s")
  470. end
  471. end
  472. end
  473. @end
  474. # Supported file extensions
  475. #
  476. # SOURCE_UNKNOWN = 0
  477. # SOURCE_BMX = 1
  478. # SOURCE_IFACE = 2
  479. # SOURCE_C = 4
  480. # SOURCE_HEADER = 8
  481. # SOURCE_ASM = 16
  482. @define source_type
  483. local ext = ";" .. arg0 .. ";"
  484. if string.find(";bmx;", ext) then
  485. return 1
  486. elseif string.find(";i;", ext) then
  487. return 2
  488. elseif string.find(";c;m;cc;cpp;cxx;mm;", ext) then
  489. return 4
  490. elseif string.find(";h;hpp;hxx;", ext) then
  491. return 8
  492. elseif string.find(";s;asm;", ext) then
  493. return 16
  494. end
  495. return 0
  496. @end
  497. @define make_win32_resource
  498. if bmk.OSPlatform() == "win32" then
  499. ext = ".exe"
  500. else
  501. ext = ""
  502. end
  503. local windres = bmk.Option("path_to_windres", bmk.MinGWBinPath() .. "/" .. bmk.MinGWExePrefix() .. "windres") .. ext
  504. local windresExe = sys.StripDir(windres)
  505. local windresDir = sys.ExtractDir(windres)
  506. local outfile = %outfile%
  507. local undecorated_outfile = outfile
  508. local infile = %infile%
  509. local decoration = ""
  510. if bmk.IsDebugBuild() == 1 then
  511. decoration = ".debug"
  512. end
  513. if bmk.IsThreadedBuild() == 1 and bmk.BCCVersion() == "BlitzMax" then
  514. decoration = decoration .. ".mt"
  515. end
  516. if string.sub( outfile, -string.len( decoration ) ) ~= decoration then
  517. outfile = outfile .. decoration
  518. end
  519. if sys.FileType(windres) == 0 then
  520. if bmk.VerboseBuild() == 1 then
  521. print(windresExe .. " not found in '" .. windresDir .. "'. Unable to apply any manifest files.")
  522. end
  523. return
  524. end
  525. windresExe = bmk.Quote(windresExe)
  526. if bmk.VerboseBuild() == 1 then
  527. print("Compiling resources...")
  528. end
  529. local arch = "amd64"
  530. if bmk.CPU() == "x86" then
  531. arch = "x86"
  532. end
  533. local tmp_path = %buildpath% .. "/.bmx/"
  534. local user_manifest_path = %buildpath% .. "/" .. outfile .. ".exe.manifest"
  535. local manifest_path = tmp_path .. outfile .. "." .. bmk.CPU() .. ".manifest"
  536. local resource_path = tmp_path .. outfile .. "." .. bmk.CPU() .. ".rc"
  537. local object_path = bmk.Quote(tmp_path .. outfile .. "." .. bmk.CPU() .. ".res.o")
  538. local icon_path = %buildpath% .. "/" .. outfile .. ".ico"
  539. if sys.FileType(icon_path) == 0 then
  540. -- fall back to undecorated icon file
  541. icon_path = %buildpath% .. "/" .. undecorated_outfile .. ".ico"
  542. if sys.FileType(icon_path) == 0 then
  543. icon_path = %buildpath% .. "/" .. infile .. ".ico"
  544. end
  545. end
  546. local manifest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" ..
  547. "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">" ..
  548. "<asmv3:application xmlns:asmv3=\"urn:schemas-microsoft-com:asm.v3\">" ..
  549. "<asmv3:windowsSettings xmlns=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\">"
  550. if bmk.SupportsHiRes() == 1 then
  551. manifest = manifest .. "<dpiAware>true</dpiAware>"
  552. end
  553. manifest = manifest .. "</asmv3:windowsSettings>" ..
  554. "</asmv3:application>" ..
  555. "<assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"" ..
  556. arch ..
  557. "\" name=\"Application\" type=\"win32\"/>" ..
  558. "<description>"
  559. if bmk.AppSetting("app.description") ~= "" then
  560. manifest = manifest .. bmk.AppSetting("app.description")
  561. else
  562. manifest = manifest .. outfile
  563. end
  564. manifest = manifest .. "</description>" ..
  565. "<dependency>" ..
  566. "<dependentAssembly>" ..
  567. "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"" ..
  568. arch ..
  569. "\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" />" ..
  570. "</dependentAssembly>" ..
  571. "</dependency>" ..
  572. "</assembly>"
  573. local resource = "1 24 \""
  574. if sys.FileType(user_manifest_path) == 1 then
  575. resource = resource .. user_manifest_path
  576. else
  577. resource = resource .. manifest_path
  578. end
  579. resource = resource .. "\"\n" ..
  580. "\n"
  581. if sys.FileType(icon_path) == 1 then
  582. resource = resource .. "APP_ICON ICON \"" .. icon_path .. "\"\n" ..
  583. "\n"
  584. end
  585. resource = resource .. "1 VERSIONINFO\n" ..
  586. "FILEVERSION "
  587. if bmk.AppSetting("app.version.major") ~= "" then
  588. resource = resource .. bmk.AppSetting("app.version.major")
  589. else
  590. resource = resource .. "1"
  591. end
  592. if bmk.AppSetting("app.version.minor") ~= "" then
  593. resource = resource .. "," .. bmk.AppSetting("app.version.minor")
  594. else
  595. resource = resource .. ",0"
  596. end
  597. if bmk.AppSetting("app.version.patch") ~= "" then
  598. resource = resource .. "," .. bmk.AppSetting("app.version.patch")
  599. else
  600. resource = resource .. ",0"
  601. end
  602. if bmk.AppSetting("app.version.build") ~= "" then
  603. resource = resource .. "," .. bmk.AppSetting("app.version.build")
  604. else
  605. resource = resource .. ",0"
  606. end
  607. resource = resource .. "\n" ..
  608. "PRODUCTVERSION 1,0,0,0\n" ..
  609. "FILEOS 0x40004\n" ..
  610. "FILETYPE 0x1\n" ..
  611. "{\n" ..
  612. "BLOCK \"StringFileInfo\"\n" ..
  613. "{\n" ..
  614. "BLOCK \"040904b0\"\n" ..
  615. "{\n"
  616. if bmk.AppSetting("app.comments") ~= "" then
  617. resource = resource .. "VALUE \"Comments\", \"" .. bmk.AppSetting("app.comments") .. "\"\n"
  618. end
  619. if bmk.AppSetting("app.company") ~= "" then
  620. resource = resource .. "VALUE \"CompanyName\", \"" .. bmk.AppSetting("app.company") .. "\"\n"
  621. end
  622. if bmk.AppSetting("app.version.name") ~= "" then
  623. resource = resource .. "VALUE \"FileVersion\", \"" .. bmk.AppSetting("app.version.name") .. "\"\n" ..
  624. "VALUE \"ProductVersion\", \"" .. bmk.AppSetting("app.version.name") .. "\"\n"
  625. end
  626. if bmk.AppSetting("app.description") ~= "" then
  627. resource = resource .. "VALUE \"FileDescription\", \"" .. bmk.AppSetting("app.description") .. "\"\n"
  628. end
  629. if bmk.AppSetting("app.name") ~= "" then
  630. resource = resource .. "VALUE \"InternalName\", \"" .. bmk.AppSetting("app.name") .. "\"\n" ..
  631. "VALUE \"ProductName\", \"" .. bmk.AppSetting("app.name") .. "\"\n"
  632. end
  633. if bmk.AppSetting("app.copyright") ~= "" then
  634. resource = resource .. "VALUE \"LegalCopyright\", \"" .. bmk.AppSetting("app.copyright") .. "\"\n"
  635. end
  636. if bmk.AppSetting("app.trademarks") ~= "" then
  637. resource = resource .. "VALUE \"LegalTrademarks\", \"" .. bmk.AppSetting("app.trademarks") .. "\"\n"
  638. end
  639. resource = resource .. "VALUE \"OriginalFilename\", \"" .. outfile .. ".exe\"\n" ..
  640. "}\n" ..
  641. "}\n" ..
  642. "BLOCK \"VarFileInfo\"\n" ..
  643. "{\n" ..
  644. "VALUE \"Translation\", 0x0409, 0\n" ..
  645. "}\n" ..
  646. "}"
  647. if futils.SaveText(manifest_path, manifest) then
  648. if futils.SaveText(resource_path, resource) then
  649. local cmd = windresExe .. " -i " .. bmk.Quote(resource_path) .. " -o " .. object_path
  650. -- windres should be run from its location in order to avoid issues with spaces in paths
  651. local cwd = sys.CurrentDir()
  652. sys.ChangeDir(windresDir)
  653. bmk.Sys(cmd)
  654. sys.ChangeDir(cwd)
  655. end
  656. end
  657. @end