crown-make.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  2. # Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. #
  4. # Permission is hereby granted, free of charge, to any person
  5. # obtaining a copy of this software and associated documentation
  6. # files (the "Software"), to deal in the Software without
  7. # restriction, including without limitation the rights to use,
  8. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following
  11. # conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be
  14. # included in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. # OTHER DEALINGS IN THE SOFTWARE.
  24. require 'optparse'
  25. require 'ostruct'
  26. require 'fileutils'
  27. # README
  28. # LINUX ONLY RIGHT NOW
  29. #------------------------------------------------------------------------------
  30. def validate_command_line(args)
  31. # if args.length < 8
  32. # return false
  33. # end
  34. # if args[0] != "--build"
  35. # return false
  36. # end
  37. # if args[2] != "--path"
  38. # return false
  39. # end
  40. # return true
  41. end
  42. #------------------------------------------------------------------------------
  43. def parse_command_line(args)
  44. banner = "Usage: crown-make.rb --build BUILD --path PATH\n"
  45. # if not validate_command_line(args)
  46. # print banner
  47. # exit
  48. # end
  49. options = OpenStruct.new
  50. OptionParser.new do |opts|
  51. opts.banner = banner
  52. opts.on("-m", "--mode MODE", "Crown build mode(debug, development, release, all)") do |m|
  53. options.mode = m
  54. end
  55. opts.on("-e", "--engine-path ENGINE_PATH", "Engine path") do |e|
  56. options.engine_path = e
  57. end
  58. opts.on("-b", "--build-path BUILD_PATH", "Build path") do |b|
  59. options.build_path = b
  60. end
  61. opts.on("-i", "--install-path PATH", "Install path") do |i|
  62. options.install_path = i
  63. end
  64. opts.on_tail("-h", "--help", "Show this message") do
  65. puts opts
  66. exit
  67. end
  68. end.parse!(args)
  69. return options
  70. end
  71. #------------------------------------------------------------------------------
  72. def build_linux_debug(engine_path, build_path, install_path)
  73. Dir.chdir(build_path)
  74. FileUtils.mkdir_p("debug")
  75. Dir.chdir(build_path + "/debug")
  76. if not system("cmake " + engine_path + " -DCMAKE_INSTALL_PREFIX=" + install_path + "/debug" + " -DCROWN_BUILD=linux-debug-64")
  77. print ("Unable to run cmake")
  78. return
  79. end
  80. if not system("make install -j 8")
  81. print ("Unable to compile")
  82. return
  83. end
  84. end
  85. #------------------------------------------------------------------------------
  86. def build_linux_development(engine_path, build_path, install_path)
  87. Dir.chdir(build_path)
  88. FileUtils.mkdir_p("development")
  89. Dir.chdir(build_path + "/development")
  90. if not system("cmake " + engine_path + " -DCMAKE_INSTALL_PREFIX=" + install_path + "/development" + " -DCROWN_BUILD=linux-development-64")
  91. print ("Unable to run cmake")
  92. return
  93. end
  94. if not system("make install -j 8")
  95. print ("Unable to compile")
  96. return
  97. end
  98. end
  99. #------------------------------------------------------------------------------
  100. def build_linux_release(engine_path, build_path, install_path)
  101. Dir.chdir(build_path)
  102. FileUtils.mkdir_p("release")
  103. Dir.chdir(build_path + "/release")
  104. if not system("cmake " + engine_path + " -DCMAKE_INSTALL_PREFIX=" + install_path + "/release" + " -DCROWN_BUILD=linux-release-64")
  105. print ("Unable to run cmake")
  106. return
  107. end
  108. if not system("make install -j 8")
  109. print ("Unable to compile")
  110. return
  111. end
  112. end
  113. #------------------------------------------------------------------------------
  114. opts = parse_command_line(ARGV)
  115. case opts.mode
  116. when "debug"
  117. build_linux_debug(opts.engine_path, opts.build_path, opts.install_path)
  118. when "development"
  119. build_linux_development(opts.engine_path, opts.build_path, opts.install_path)
  120. when "release"
  121. build_linux_release(opts.engine_path, opts.build_path, opts.install_path)
  122. when "all"
  123. build_linux_debug(opts.engine_path, opts.build_path, opts.install_path)
  124. build_linux_development(opts.engine_path, opts.build_path, opts.install_path)
  125. build_linux_release(opts.engine_path, opts.build_path, opts.install_path)
  126. end