make.bmk 21 KB

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