make.bmk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #!BMK
  2. @define assemble
  3. local src = nvl(arg1, %infile%)
  4. local obj = nvl(arg2, %outfile%)
  5. sys.DeleteFile(obj)
  6. if bmk.Platform() == "macos" then
  7. if bmk.CPU() == "ppc" then
  8. cmd = "as -arch ppc"
  9. elseif bmk.CPU() == "x86" then
  10. cmd = "as -arch i386"
  11. else
  12. cmd = "as -arch x86_64"
  13. end
  14. cmd = cmd .. " -W -o " .. bmk.Quote(obj) .. " " .. bmk.Quote(src)
  15. else
  16. if bmk.Platform() == "win32" then
  17. local prefix = bmk.Option("path_to_wine", "")
  18. if prefix ~= "" then
  19. prefix = prefix .. " "
  20. end
  21. cmd = prefix .. bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm.exe") .. " "
  22. else
  23. cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm") .. " "
  24. end
  25. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  26. cmd = cmd .. " -m32768 "
  27. end
  28. cmd = cmd .. bmk.Quote(src) .. " " .. bmk.Quote(obj)
  29. end
  30. if bmk.MultiSys(cmd, src) ~= 0 then
  31. bmk.ThrowNew("Build Error: Failed to assemble " .. src)
  32. end
  33. @end
  34. @define compileBMX
  35. local src = nvl(arg1, %infile%)
  36. local obj = nvl(arg2, %outfile%)
  37. local opts = nvl(arg3, %options%)
  38. sys.DeleteFile(obj)
  39. local bcc_app = "bcc"
  40. # if we are doing a universal build, be sure and call the correct bcc!
  41. if %universal% == "1" and bmk.CPU() == "ppc" then
  42. bcc_app = bcc_app .. "_ppc"
  43. end
  44. if bmk.Platform() == "win32" then
  45. bcc_app = bcc_app .. ".exe"
  46. end
  47. local prefix = ""
  48. if bmk.Platform() == "win32" then
  49. prefix = bmk.Option("path_to_wine", "")
  50. if prefix ~= "" then
  51. prefix = prefix .. " "
  52. end
  53. end
  54. azm = sys.StripExt(obj) .. ".s"
  55. cmd = prefix .. bmk.Quote(utils.BlitzMaxPath() .. "/bin/" .. bcc_app) .." " .. opts .. " -o " .. bmk.Quote(azm) .. " " .. bmk.Quote(src)
  56. if bmk.MultiSys( cmd, src ) ~= 0 then
  57. bmk.ThrowNew("Build Error: failed to compile " .. src)
  58. end
  59. #if bmk.Platform() == "macos" and bmk.CPU() == "x86" and bmk.BCCVersion() == "BlitzMax" then
  60. # cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm2as") .. " " .. bmk.Quote(azm)
  61. # if bmk.Sys( cmd ) ~= 0 then
  62. # bmk.ThrowNew("Fasm2as failed - please contact BRL!")
  63. # end
  64. #end
  65. # TODO : we can't call another generated function from here... so we'd need to make sure this is called elsewhere.
  66. #assemble(nil, azm, obj)
  67. @end
  68. @define fasm2as
  69. local src = nvl(arg1, %infile%)
  70. local obj = nvl(arg2, %outfile%)
  71. local azm = sys.StripExt(obj) .. ".s"
  72. if bmk.Platform() == "macos" and bmk.CPU() == "x86" and bmk.BCCVersion() == "BlitzMax" then
  73. cmd = bmk.Quote(utils.BlitzMaxPath() .. "/bin/fasm2as") .. " " .. bmk.Quote(azm)
  74. if bmk.MultiSys( cmd ) ~= 0 then
  75. bmk.ThrowNew("Fasm2as failed - please contact BRL!")
  76. end
  77. end
  78. @end
  79. @define compileC
  80. local src = nvl(arg1, %infile%)
  81. local obj = nvl(arg2, %outfile%)
  82. local opts = arg3
  83. sys.DeleteFile(obj)
  84. #opts = opts .. " " .. %cc_opts% .. " " .. %BMK_CC_OPTS%
  85. local ext = sys.ExtractExt(src)
  86. if bmk.Platform() == "macos" then
  87. cmd = "gcc"
  88. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  89. cmd = "g++"
  90. end
  91. # need to use gcc, not llvm...
  92. # 10.7
  93. # but for 10.8 we have no choice...
  94. if tonumber(%macos_version%) >= 4208 and tonumber(%macos_version%) < 4224 then
  95. cmd = cmd .. "-4.2"
  96. end
  97. if bmk.CPU() == "ppc" then
  98. cmd = cmd .. " -arch ppc "
  99. elseif bmk.CPU() == "x86" then
  100. cmd = cmd .. " -arch i386 "
  101. else
  102. cmd = cmd .. " -arch x86_64 "
  103. end
  104. elseif bmk.Platform() == "win32" then
  105. if bmk.BCCVersion() == "BlitzMax" then
  106. cmd = bmk.Option("path_to_gcc", "gcc.exe")
  107. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  108. cmd = bmk.Option("path_to_gpp", "g++.exe")
  109. end
  110. else
  111. cmd = bmk.Option("path_to_gcc", bmk.MinGWBinPath() .. "/gcc.exe")
  112. if ext == "cpp" or ext == "cxx" or ext == "mm" or ext == "cc" then
  113. cmd = bmk.Option("path_to_gpp", bmk.MinGWBinPath() .. "/g++.exe")
  114. end
  115. end
  116. elseif bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  117. cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
  118. elseif bmk.Platform() == "emscripten" then
  119. cmd = bmk.Option(bmk.BuildName("gcc"), "emcc")
  120. cmd = cmd .. " -Wno-warn-absolute-paths "
  121. end
  122. # disable warnings ?
  123. if %CC_WARNINGS% == "" then
  124. opts = opts .. " -w"
  125. end
  126. if bmk.BCCVersion() ~= "BlitzMax" then
  127. opts = opts .. " -DBMX_NG"
  128. end
  129. local genDebug = ""
  130. if bmk.IsDebugBuild() == 1 then
  131. genDebug = " -g"
  132. end
  133. # Remove -fno-exceptions if we have provided -fexceptions
  134. local cc_opts = %cc_opts%
  135. if cc_opts:find("-fexceptions") ~= nil then
  136. cc_opts = cc_opts:gsub("%-fno%-exceptions", print)
  137. end
  138. if opts:find("-fexceptions") ~= nil then
  139. cc_opts = cc_opts:gsub("%-fno%-exceptions", "")
  140. end
  141. cmd = cmd .. opts .. cc_opts .. %mod_ccopts% .. genDebug .. " -o " .. bmk.Quote(obj) .. " " .. bmk.Quote(src)
  142. if bmk.MultiSys( cmd, src ) ~= 0 then
  143. bmk.ThrowNew("Build Error: failed to compile " .. src)
  144. end
  145. @end
  146. @define addlib
  147. globals.Add("libs", arg1)
  148. @end
  149. @define addoption
  150. globals.Add(arg1, arg2)
  151. @end
  152. ## adds a cc_opt option
  153. @define addccopt
  154. globals.AddOption("cc_opts", arg1, arg2)
  155. @end
  156. @define setccopt
  157. globals.SetOption("cc_opts", arg1, arg2)
  158. @end
  159. @define addwin32ccopt
  160. if bmk.Platform() == "win32" then
  161. globals.AddOption("cc_opts", arg1, arg2)
  162. end
  163. @end
  164. @define setwin32ccopt
  165. if bmk.Platform() == "win32" then
  166. globals.SetOption("cc_opts", arg1, arg2)
  167. end
  168. @end
  169. @define addmacccopt
  170. if bmk.Platform() == "macos" then
  171. globals.AddOption("cc_opts", arg1, arg2)
  172. end
  173. @end
  174. @define setmacccopt
  175. if bmk.Platform() == "macos" then
  176. globals.SetOption("cc_opts", arg1, arg2)
  177. end
  178. @end
  179. @define addmacppcccopt
  180. if bmk.Platform() == "macos" and bmk.CPU() == "ppc" then
  181. globals.AddOption("cc_opts", arg1, arg2)
  182. end
  183. @end
  184. @define setmacppcccopt
  185. if bmk.Platform() == "macos" and bmk.CPU() == "ppc" then
  186. globals.SetOption("cc_opts", arg1, arg2)
  187. end
  188. @end
  189. @define addmacx86ccopt
  190. if bmk.Platform() == "macos" and bmk.CPU() == "x86" then
  191. globals.AddOption("cc_opts", arg1, arg2)
  192. end
  193. @end
  194. @define setmacx86ccopt
  195. if bmk.Platform() == "macos" and bmk.CPU() == "x86" then
  196. globals.SetOption("cc_opts", arg1, arg2)
  197. end
  198. @end
  199. @define addlinuxccopt
  200. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  201. globals.AddOption("cc_opts", arg1, arg2)
  202. end
  203. @end
  204. @define setlinuxccopt
  205. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  206. globals.SetOption("cc_opts", arg1, arg2)
  207. end
  208. @end
  209. ## removes a cc_opt option
  210. @define rmccopt
  211. globals.Remove("cc_opts", arg1)
  212. @end
  213. @define addldopt
  214. globals.AddOption("ld_opts", arg1, arg2)
  215. @end
  216. @define setldopt
  217. globals.SetOption("ld_opts", arg1, arg2)
  218. @end
  219. @define addwin32ldopt
  220. if bmk.Platform() == "win32" then
  221. globals.AddOption("ld_opts", arg1, arg2)
  222. end
  223. @end
  224. @define addmacldopt
  225. if bmk.Platform() == "macos" then
  226. globals.AddOption("ld_opts", arg1, arg2)
  227. end
  228. @end
  229. @define addlinuxldopt
  230. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  231. globals.AddOption("ld_opts", arg1, arg2)
  232. end
  233. @end
  234. # compiles the specified file, using the current options.
  235. @define make
  236. make.Make(arg1)
  237. @end
  238. @define skipmod
  239. globals.Add("skip_mod", arg1)
  240. @end
  241. @define skipmodwin32
  242. if bmk.Platform() == "win32" then
  243. globals.Add("skip_mod", arg1)
  244. end
  245. @end
  246. @define skipmodmac
  247. if bmk.Platform() == "macos" then
  248. globals.Add("skip_mod", arg1)
  249. end
  250. @end
  251. @define skipmodlinux
  252. if bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
  253. globals.Add("skip_mod", arg1)
  254. end
  255. @end
  256. # the default ccopts
  257. # used for compiling c-type files
  258. @define default_cc_opts
  259. globals.Clear("cc_opts")
  260. if bmk.Platform() == "macos" then
  261. # compile for 10.3 ?
  262. # macos version >= 0x1050 ?
  263. if tonumber(%macos_version%) >= 4208 then
  264. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.4")
  265. if tonumber(%macos_version%) >= 4224 then
  266. globals.SetOption("cc_opts", "isysroot", "-isysroot /Developer/SDKs/MacOSX10.6.sdk")
  267. end
  268. elseif tonumber(%macos_version%) >= 4176 then
  269. globals.SetOption("cc_opts", "osversion", "-mmacosx-version-min=10.3")
  270. end
  271. elseif bmk.Platform() == "win32" then
  272. if bmk.BCCVersion() == "BlitzMax" then
  273. globals.SetOption("cc_opts", "arch", "-march=pentium")
  274. else
  275. if bmk.hasTarget("x86_64") then
  276. if bmk.CPU() == "x86" then
  277. globals.SetOption("cc_opts", "arch", "-m32")
  278. elseif bmk.CPU() == "x64" then
  279. globals.SetOption("cc_opts", "arch", "-m64")
  280. end
  281. else
  282. globals.SetOption("cc_opts", "arch", "-march=pentium")
  283. end
  284. end
  285. globals.SetOption("cc_opts", "fastmath", "-ffast-math")
  286. elseif bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" or bmk.Platform() == "emscripten" then
  287. globals.SetOption("cc_opts", "aliasing", "-fno-strict-aliasing")
  288. if bmk.CPU() == "x86" then
  289. globals.SetOption("cc_opts", "arch", "-m32")
  290. globals.SetOption("cc_opts", "fancymath", "-mfancy-math-387")
  291. end
  292. end
  293. globals.SetOption("cc_opts", "exceptions", "-fno-exceptions")
  294. globals.SetOption("cc_opts", "linker", "-c")
  295. globals.SetOption("cc_opts", "optimization", "-O2")
  296. if bmk.IsDebugBuild() == 0 then
  297. if bmk.Platform() ~= "emscripten" then
  298. globals.SetOption("cc_opts", "stripsymbols", "-s")
  299. end
  300. end
  301. @end
  302. # Supported file extensions
  303. #
  304. # SOURCE_UNKNOWN = 0
  305. # SOURCE_BMX = 1
  306. # SOURCE_IFACE = 2
  307. # SOURCE_C = 4
  308. # SOURCE_HEADER = 8
  309. # SOURCE_ASM = 16
  310. @define source_type
  311. local ext = ";" .. arg0 .. ";"
  312. if string.find(";bmx;", ext) then
  313. return 1
  314. elseif string.find(";i;", ext) then
  315. return 2
  316. elseif string.find(";c;m;cc;cpp;cxx;mm;", ext) then
  317. return 4
  318. elseif string.find(";h;hpp;hxx;", ext) then
  319. return 8
  320. elseif string.find(";s;asm;", ext) then
  321. return 16
  322. end
  323. return 0
  324. @end