make_quicky.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env python3
  2. # ##### BEGIN GPL LICENSE BLOCK #####
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. #
  18. # ##### END GPL LICENSE BLOCK #####
  19. # <pep8 compliant>
  20. def print_help(targets):
  21. print("CMake quicky wrapper, no valid targets given.")
  22. print(" * targets can contain a subset of the full target name.")
  23. print(" * arguments with a '-' prefix are passed onto make.")
  24. print(" * this must run from the cmake build dir")
  25. print(" * alias this with a short command for speedy access, in bash:")
  26. print(" alias mk='../blender/build_files/cmake/example_scripts/make_quicky.py'")
  27. print("")
  28. print(" eg: make_quicky.py -j3 extern python")
  29. print(" ...will execute")
  30. print(" make -j3 extern_binreloc extern_glew bf_python bf_python_ext blender/fast")
  31. print("")
  32. print("Target List:")
  33. for t in targets:
  34. print(" %s" % t)
  35. print("...exiting")
  36. def main():
  37. targets = set()
  38. # collect targets
  39. makefile = open("Makefile", "r")
  40. for line in makefile:
  41. line = line.rstrip()
  42. if not line or line[0] in ". \t@$#":
  43. continue
  44. line = line.split("#", 1)[0]
  45. if ":" not in line:
  46. continue
  47. line = line.split(":", 1)[0]
  48. if "/" in line: # cmake terget options, dont need these
  49. continue
  50. targets.add(line)
  51. makefile.close()
  52. # remove cmake targets
  53. bad = set([
  54. "help",
  55. "clean",
  56. "all",
  57. "preinstall",
  58. "install",
  59. "default_target",
  60. "edit_cache",
  61. "cmake_force",
  62. "rebuild_cache",
  63. "depend",
  64. "cmake_check_build_system",
  65. ])
  66. targets -= set(bad)
  67. # parse args
  68. targets = list(targets)
  69. targets.sort()
  70. import sys
  71. if len(sys.argv) == 1:
  72. print_help(targets)
  73. return
  74. targets_new = []
  75. args = []
  76. for arg in sys.argv[1:]:
  77. if arg[0] in "/-":
  78. args.append(arg)
  79. else:
  80. found = False
  81. for t in targets:
  82. if arg in t and t not in targets_new:
  83. targets_new.append(t)
  84. found = True
  85. if not found:
  86. print("Error '%s' not found in...")
  87. for t in targets:
  88. print(" %s" % t)
  89. print("...aborting.")
  90. return
  91. # execute
  92. cmd = "make %s %s blender/fast" % (" ".join(args), " ".join(targets_new))
  93. print("cmake building with targets: %s" % " ".join(targets_new))
  94. print("executing: %s" % cmd)
  95. import os
  96. os.system(cmd)
  97. if __name__ == "__main__":
  98. main()