gdc.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. --
  2. -- d/tools/gdc.lua
  3. -- Provides GDC-specific configuration strings.
  4. -- Copyright (c) 2013-2015 Andrew Gough, Manu Evans, and the Premake project
  5. --
  6. local p = premake
  7. p.tools.gdc = { }
  8. local gdc = p.tools.gdc
  9. local project = p.project
  10. local config = p.config
  11. local d = p.modules.d
  12. --
  13. -- Set default tools
  14. --
  15. gdc.dc = "gdc"
  16. --
  17. -- Returns list of D compiler flags for a configuration.
  18. --
  19. gdc.dflags = {
  20. architecture = {
  21. x86 = "-m32",
  22. x86_64 = "-m64",
  23. },
  24. flags = {
  25. Documentation = "-fdoc",
  26. FatalWarnings = "-Werror",
  27. GenerateHeader = "-fintfc",
  28. GenerateJSON = "-fX",
  29. -- Release = "-frelease",
  30. RetainPaths = "-op",
  31. SymbolsLikeC = "-fdebug-c",
  32. UnitTest = "-funittest",
  33. Verbose = "-fd-verbose",
  34. -- THESE ARE THE DMD ARGS...
  35. -- ProfileGC = "-profile=gc",
  36. -- StackFrame = "-gs",
  37. -- StackStomp = "-gx",
  38. -- AllInstantiate = "-allinst",
  39. -- BetterC = "-betterC",
  40. -- Main = "-main",
  41. -- PerformSyntaxCheckOnly = "-o-",
  42. ShowTLS = "-fd-vtls",
  43. -- ShowGC = "-vgc",
  44. -- IgnorePragma = "-ignore",
  45. ShowDependencies = "-fdeps",
  46. },
  47. boundscheck = {
  48. Off = "-fno-bounds-check",
  49. -- On = "-boundscheck=on",
  50. -- SafeOnly = "-boundscheck=safeonly",
  51. },
  52. deprecatedfeatures = {
  53. Allow = "-fdeprecated",
  54. -- Warn = "-dw",
  55. -- Error = "-de",
  56. },
  57. floatingpoint = {
  58. Fast = "-ffast-math",
  59. Strict = "-ffloat-store",
  60. },
  61. optimize = {
  62. Off = "-O0",
  63. On = "-O2 -finline-functions",
  64. Debug = "-Og",
  65. Full = "-O3 -finline-functions",
  66. Size = "-Os -finline-functions",
  67. Speed = "-O3 -finline-functions",
  68. },
  69. pic = {
  70. On = "-fPIC",
  71. },
  72. vectorextensions = {
  73. AVX = "-mavx",
  74. SSE = "-msse",
  75. SSE2 = "-msse2",
  76. },
  77. warnings = {
  78. -- Default = "-w", -- TODO: check this...
  79. High = "-Wall",
  80. Extra = "-Wall -Wextra",
  81. Everything = "-Weverything",
  82. },
  83. symbols = {
  84. On = "-g",
  85. FastLink = "-g",
  86. Full = "-g -gf",
  87. }
  88. }
  89. function gdc.getdflags(cfg)
  90. local flags = config.mapFlags(cfg, gdc.dflags)
  91. if config.isDebugBuild(cfg) then
  92. table.insert(flags, "-fdebug")
  93. else
  94. table.insert(flags, "-frelease")
  95. end
  96. if cfg.flags.Documentation then
  97. if cfg.docname then
  98. table.insert(flags, "-fdoc-file=" .. p.quoted(cfg.docname))
  99. end
  100. if cfg.docdir then
  101. table.insert(flags, "-fdoc-dir=" .. p.quoted(cfg.docdir))
  102. end
  103. end
  104. if cfg.flags.GenerateHeader then
  105. if cfg.headername then
  106. table.insert(flags, "-fintfc-file=" .. p.quoted(cfg.headername))
  107. end
  108. if cfg.headerdir then
  109. table.insert(flags, "-fintfc-dir=" .. p.quoted(cfg.headerdir))
  110. end
  111. end
  112. return flags
  113. end
  114. --
  115. -- Decorate versions for the DMD command line.
  116. --
  117. function gdc.getversions(versions, level)
  118. local result = {}
  119. for _, version in ipairs(versions) do
  120. table.insert(result, '-fversion=' .. version)
  121. end
  122. if level then
  123. table.insert(result, '-fversion=' .. level)
  124. end
  125. return result
  126. end
  127. --
  128. -- Decorate debug constants for the DMD command line.
  129. --
  130. function gdc.getdebug(constants, level)
  131. local result = {}
  132. for _, constant in ipairs(constants) do
  133. table.insert(result, '-fdebug=' .. constant)
  134. end
  135. if level then
  136. table.insert(result, '-fdebug=' .. level)
  137. end
  138. return result
  139. end
  140. --
  141. -- Decorate import file search paths for the DMD command line.
  142. --
  143. function gdc.getimportdirs(cfg, dirs)
  144. local result = {}
  145. for _, dir in ipairs(dirs) do
  146. dir = project.getrelative(cfg.project, dir)
  147. table.insert(result, '-I' .. p.quoted(dir))
  148. end
  149. return result
  150. end
  151. --
  152. -- Decorate import file search paths for the DMD command line.
  153. --
  154. function gdc.getstringimportdirs(cfg, dirs)
  155. local result = {}
  156. for _, dir in ipairs(dirs) do
  157. dir = project.getrelative(cfg.project, dir)
  158. table.insert(result, '-J' .. p.quoted(dir))
  159. end
  160. return result
  161. end
  162. --
  163. -- Returns the target name specific to compiler
  164. --
  165. function gdc.gettarget(name)
  166. return "-o " .. name
  167. end
  168. --
  169. -- Return a list of LDFLAGS for a specific configuration.
  170. --
  171. gdc.ldflags = {
  172. architecture = {
  173. x86 = { "-m32" },
  174. x86_64 = { "-m64" },
  175. },
  176. kind = {
  177. SharedLib = function(cfg)
  178. local r = { iif(cfg.system == p.MACOSX, "-dynamiclib", "-shared") }
  179. if cfg.system == "windows" and not cfg.flags.NoImportLib then
  180. table.insert(r, '-Wl,--out-implib="' .. cfg.linktarget.relpath .. '"')
  181. end
  182. return r
  183. end,
  184. WindowedApp = function(cfg)
  185. if cfg.system == p.WINDOWS then return "-mwindows" end
  186. end,
  187. },
  188. }
  189. function gdc.getldflags(cfg)
  190. local flags = config.mapFlags(cfg, gdc.ldflags)
  191. return flags
  192. end
  193. --
  194. -- Return a list of decorated additional libraries directories.
  195. --
  196. gdc.libraryDirectories = {
  197. architecture = {
  198. x86 = "-L/usr/lib",
  199. x86_64 = "-L/usr/lib64",
  200. }
  201. }
  202. function gdc.getLibraryDirectories(cfg)
  203. local flags = config.mapFlags(cfg, gdc.libraryDirectories)
  204. -- Scan the list of linked libraries. If any are referenced with
  205. -- paths, add those to the list of library search paths
  206. for _, dir in ipairs(config.getlinks(cfg, "system", "directory")) do
  207. table.insert(flags, '-Wl,-L' .. project.getrelative(cfg.project, dir))
  208. end
  209. return flags
  210. end
  211. --
  212. -- Return the list of libraries to link, decorated with flags as needed.
  213. --
  214. function gdc.getlinks(cfg, systemonly)
  215. local result = {}
  216. local links
  217. if not systemonly then
  218. links = config.getlinks(cfg, "siblings", "object")
  219. for _, link in ipairs(links) do
  220. -- skip external project references, since I have no way
  221. -- to know the actual output target path
  222. if not link.project.external then
  223. if link.kind == p.STATICLIB then
  224. -- Don't use "-l" flag when linking static libraries; instead use
  225. -- path/libname.a to avoid linking a shared library of the same
  226. -- name if one is present
  227. table.insert(result, "-Wl," .. project.getrelative(cfg.project, link.linktarget.abspath))
  228. else
  229. table.insert(result, "-Wl,-l" .. link.linktarget.basename)
  230. end
  231. end
  232. end
  233. end
  234. -- The "-l" flag is fine for system libraries
  235. links = config.getlinks(cfg, "system", "fullpath")
  236. for _, link in ipairs(links) do
  237. if path.isframework(link) then
  238. table.insert(result, "-framework " .. path.getbasename(link))
  239. elseif path.isobjectfile(link) then
  240. table.insert(result, "-Wl," .. link)
  241. else
  242. table.insert(result, "-Wl,-l" .. path.getbasename(link))
  243. end
  244. end
  245. return result
  246. end
  247. --
  248. -- Returns makefile-specific configuration rules.
  249. --
  250. gdc.makesettings = {
  251. }
  252. function gdc.getmakesettings(cfg)
  253. local settings = config.mapFlags(cfg, gdc.makesettings)
  254. return table.concat(settings)
  255. end
  256. --
  257. -- Retrieves the executable command name for a tool, based on the
  258. -- provided configuration and the operating environment.
  259. --
  260. -- @param cfg
  261. -- The configuration to query.
  262. -- @param tool
  263. -- The tool to fetch, one of "dc" for the D compiler, or "ar" for the static linker.
  264. -- @return
  265. -- The executable command name for a tool, or nil if the system's
  266. -- default value should be used.
  267. --
  268. gdc.tools = {
  269. ps3 = {
  270. dc = "ppu-lv2-gdc",
  271. ar = "ppu-lv2-ar",
  272. },
  273. }
  274. function gdc.gettoolname(cfg, tool)
  275. local names = gdc.tools[cfg.architecture] or gdc.tools[cfg.system] or {}
  276. local name = names[tool]
  277. return name or gdc[tool]
  278. end