123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #!/usr/bin/env python3
- from os import (system, path, mkdir, chdir)
- from shutil import copy2
- from argparse import ArgumentParser
- SUPPORTED_PLATFORMS = ("linux")
- DEFAULT_TARGET_PLATFORM = SUPPORTED_PLATFORMS[0]
- ROOT = path.abspath(path.curdir)
- arg_parser = ArgumentParser(
- description="A script for build automation for different target platforms"
- )
- arg_parser.add_argument("-p", "--platform",
- action="store",
- default=DEFAULT_TARGET_PLATFORM,
- help=f"Select target platform: {SUPPORTED_PLATFORMS}")
- arg_parser.add_argument("-r", "--rebuild",
- action="store_true",
- default=False,
- help="Clean and rebuild existing build")
- def print_banner():
- print(
- '''
- ╔═╗╔═╗┌┐┌┌─┐┬┌┐┌┌─┐
- ╠═╣║╣ ││││ ┬││││├┤
- ╩ ╩╚═╝┘└┘└─┘┴┘└┘└─┘
- ╔═╗╔═╗╔═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐ ┌─┐┌┐┌┌─┐┬┌┐┌┌─┐
- ╠╣ ║ ║╚═╗╚═╗ │ ┬├─┤│││├┤ ├┤ ││││ ┬││││├┤
- ╚ ╚═╝╚═╝╚═╝ └─┘┴ ┴┴ ┴└─┘ └─┘┘└┘└─┘┴┘└┘└─┘
- ╦ ╦┬─┐┬┌┬┐┌┬┐┌─┐┌┐┌ ┬┌┐┌ ╔═╗ ┌─┐┌┐┌┌┬┐ ╔═╗┌─┐┌─┐┌┐┌╔═╗╦
- ║║║├┬┘│ │ │ ├┤ │││ ││││ ║ ++ ├─┤│││ ││ ║ ║├─┘├┤ │││║ ╦║
- ╚╩╝┴└─┴ ┴ ┴ └─┘┘└┘ ┴┘└┘ ╚═╝ ┴ ┴┘└┘─┴┘ ╚═╝┴ └─┘┘└┘╚═╝╩═╝
- ''')
- def check_deps_linux():
- if path.exists("/usr/bin/cmake"):
- print("[+] CMake: found")
- else:
- print("[-] CMake: NOT FOUND!")
- exit(2)
- if path.exists("/usr/bin/gcc"):
- print("[+] GCC: found")
- else:
- print("[-] GCC: NOT FOUND")
- exit(3)
- if path.exists("/usr/bin/g++"):
- print("[+] G++: found")
- else:
- print("[-] G++: NOT FOUND")
- exit(3)
- def check_deps(target_platform):
- if not target_platform in SUPPORTED_PLATFORMS:
- print(f"Error: unknown target platform: '{target_platform}'")
- exit(1)
- if target_platform == SUPPORTED_PLATFORMS[0]: # linux
- print(f"Checking build dependencies for platform: {target_platform}")
- check_deps_linux()
- def prepare(target_platform):
- dir = "build-" + target_platform
- if not path.exists(dir):
- mkdir(dir)
- def build(target_platform, rebuild = False):
- dir = "build-" + target_platform
- chdir(dir)
- if rebuild:
- system("make clean")
- cmake_cmd = "cmake .."
- system(cmake_cmd)
- system("make -j$(nproc)")
- chdir(ROOT)
- def post_build(target_platform):
- dir = "build-" + target_platform
- if __name__ == "__main__":
- args = arg_parser.parse_args()
- print_banner()
- check_deps(args.platform)
- prepare(args.platform)
- build(args.platform, args.rebuild)
- post_build(args.platform)
|