gmake_utility.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --
  2. -- make_utility.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.utility = {}
  8. local make = p.make
  9. local utility = p.make.utility
  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. utility.elements = {}
  17. --
  18. -- Generate a GNU make utility project makefile.
  19. --
  20. utility.elements.makefile = {
  21. "header",
  22. "phonyRules",
  23. "utilityConfigs",
  24. "utilityTargetRules"
  25. }
  26. function make.utility.generate(prj)
  27. p.eol("\n")
  28. p.callarray(make, utility.elements.makefile, prj)
  29. end
  30. utility.elements.configuration = {
  31. "target",
  32. "preBuildCmds",
  33. "postBuildCmds",
  34. }
  35. function make.utilityConfigs(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, utility.elements.configuration, cfg, toolset)
  45. _p('endif')
  46. _p('')
  47. end
  48. end
  49. function make.utilityTargetRules(prj)
  50. _p('$(TARGET):')
  51. _p('\t$(PREBUILDCMDS)')
  52. _p('\t$(POSTBUILDCMDS)')
  53. _p('')
  54. end