gmake_makefile.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --
  2. -- make_makefile.lua
  3. -- Generate a C/C++ project makefile.
  4. -- Copyright (c) 2002-2014 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. p.make.makefile = {}
  8. local make = p.make
  9. local makefile = p.make.makefile
  10. local project = p.project
  11. local config = p.config
  12. local fileconfig = p.fileconfig
  13. ---
  14. -- Add namespace for element definition lists for p.callarray()
  15. ---
  16. makefile.elements = {}
  17. --
  18. -- Generate a GNU make makefile project makefile.
  19. --
  20. makefile.elements.makefile = {
  21. "header",
  22. "phonyRules",
  23. "makefileConfigs",
  24. "makefileTargetRules"
  25. }
  26. function make.makefile.generate(prj)
  27. p.eol("\n")
  28. p.callarray(make, makefile.elements.makefile, prj)
  29. end
  30. makefile.elements.configuration = {
  31. "target",
  32. "buildCommands",
  33. "cleanCommands",
  34. }
  35. function make.makefileConfigs(prj)
  36. for cfg in project.eachconfig(prj) do
  37. -- identify the toolset used by this configurations (would be nicer if
  38. -- this were computed and stored with the configuration up front)
  39. local toolset = p.tools[cfg.toolset or "gcc"]
  40. if not toolset then
  41. error("Invalid toolset '" .. cfg.toolset .. "'")
  42. end
  43. _x('ifeq ($(config),%s)', cfg.shortname)
  44. p.callarray(make, makefile.elements.configuration, cfg, toolset)
  45. _p('endif')
  46. _p('')
  47. end
  48. end
  49. function make.makefileTargetRules(prj)
  50. _p('$(TARGET):')
  51. _p('\t$(BUILDCMDS)')
  52. _p('')
  53. _p('clean:')
  54. _p('\t$(CLEANCMDS)')
  55. _p('')
  56. end
  57. function make.buildCommands(cfg)
  58. _p(' define BUILDCMDS')
  59. local steps = cfg.buildcommands
  60. if #steps > 0 then
  61. steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
  62. _p('\t@echo Running build commands')
  63. _p('\t%s', table.implode(steps, "", "", "\n\t"))
  64. end
  65. _p(' endef')
  66. end
  67. function make.cleanCommands(cfg)
  68. _p(' define CLEANCMDS')
  69. local steps = cfg.cleancommands
  70. if #steps > 0 then
  71. steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
  72. _p('\t@echo Running clean commands')
  73. _p('\t%s', table.implode(steps, "", "", "\n\t"))
  74. end
  75. _p(' endef')
  76. end