build.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python3
  2. from os import (system, path, mkdir, chdir)
  3. from shutil import copy2
  4. from argparse import ArgumentParser
  5. SUPPORTED_PLATFORMS = ("linux")
  6. DEFAULT_TARGET_PLATFORM = SUPPORTED_PLATFORMS[0]
  7. ROOT = path.abspath(path.curdir)
  8. arg_parser = ArgumentParser(
  9. description="A script for build automation for different target platforms"
  10. )
  11. arg_parser.add_argument("-p", "--platform",
  12. action="store",
  13. default=DEFAULT_TARGET_PLATFORM,
  14. help=f"Select target platform: {SUPPORTED_PLATFORMS}")
  15. arg_parser.add_argument("-r", "--rebuild",
  16. action="store_true",
  17. default=False,
  18. help="Clean and rebuild existing build")
  19. def print_banner():
  20. print(
  21. '''
  22. ╔═╗╔═╗┌┐┌┌─┐┬┌┐┌┌─┐
  23. ╠═╣║╣ ││││ ┬││││├┤
  24. ╩ ╩╚═╝┘└┘└─┘┴┘└┘└─┘
  25. ╔═╗╔═╗╔═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐ ┌─┐┌┐┌┌─┐┬┌┐┌┌─┐
  26. ╠╣ ║ ║╚═╗╚═╗ │ ┬├─┤│││├┤ ├┤ ││││ ┬││││├┤
  27. ╚ ╚═╝╚═╝╚═╝ └─┘┴ ┴┴ ┴└─┘ └─┘┘└┘└─┘┴┘└┘└─┘
  28. ╦ ╦┬─┐┬┌┬┐┌┬┐┌─┐┌┐┌ ┬┌┐┌ ╔═╗ ┌─┐┌┐┌┌┬┐ ╔═╗┌─┐┌─┐┌┐┌╔═╗╦
  29. ║║║├┬┘│ │ │ ├┤ │││ ││││ ║ ++ ├─┤│││ ││ ║ ║├─┘├┤ │││║ ╦║
  30. ╚╩╝┴└─┴ ┴ ┴ └─┘┘└┘ ┴┘└┘ ╚═╝ ┴ ┴┘└┘─┴┘ ╚═╝┴ └─┘┘└┘╚═╝╩═╝
  31. ''')
  32. def check_deps_linux():
  33. if path.exists("/usr/bin/cmake"):
  34. print("[+] CMake: found")
  35. else:
  36. print("[-] CMake: NOT FOUND!")
  37. exit(2)
  38. if path.exists("/usr/bin/gcc"):
  39. print("[+] GCC: found")
  40. else:
  41. print("[-] GCC: NOT FOUND")
  42. exit(3)
  43. if path.exists("/usr/bin/g++"):
  44. print("[+] G++: found")
  45. else:
  46. print("[-] G++: NOT FOUND")
  47. exit(3)
  48. def check_deps(target_platform):
  49. if not target_platform in SUPPORTED_PLATFORMS:
  50. print(f"Error: unknown target platform: '{target_platform}'")
  51. exit(1)
  52. if target_platform == SUPPORTED_PLATFORMS[0]: # linux
  53. print(f"Checking build dependencies for platform: {target_platform}")
  54. check_deps_linux()
  55. def prepare(target_platform):
  56. dir = "build-" + target_platform
  57. if not path.exists(dir):
  58. mkdir(dir)
  59. def build(target_platform, rebuild = False):
  60. dir = "build-" + target_platform
  61. chdir(dir)
  62. if rebuild:
  63. system("make clean")
  64. cmake_cmd = "cmake .."
  65. system(cmake_cmd)
  66. system("make -j$(nproc)")
  67. chdir(ROOT)
  68. def post_build(target_platform):
  69. dir = "build-" + target_platform
  70. if __name__ == "__main__":
  71. args = arg_parser.parse_args()
  72. print_banner()
  73. check_deps(args.platform)
  74. prepare(args.platform)
  75. build(args.platform, args.rebuild)
  76. post_build(args.platform)