import os import subprocess from . import make as libmake from . import pkgcomposer def configure(rem: list[str] = []): subprocess.run(["./configure"] + rem, check=True) def make(rem: list[str] = []): subprocess.run(["make", f"-j{os.cpu_count()}"] + rem, check=True) def make_install(rem: list[str] | None = None, chdir: bool = True): default_rem = ["DESTDIR=" + os.getcwd() + "/../cpp_install"] subprocess.run(["make", "install"] + (rem or default_rem), check=True) if rem is None and chdir: os.chdir("../cpp_install") def _do_auto_pack(pc: pkgcomposer.PkgComposer, srcdir: str, dstdir: str, filter): pc.makedir(srcdir) with os.scandir(srcdir) as entries: for ent in entries: if filter(ent): if ent.is_dir(follow_symlinks=False): pc.makedir(f"{dstdir}/{ent.name}") else: pc.addfile(ent.path, f"{dstdir}/{ent.name}") def _autopack_filter_lib(ent) -> bool: if ent.name.endswith(".o") or ent.name.endswith(".a"): return False return True def _autopack_filter_bin(ent) -> bool: return True def _autopack_filter_dev(ent): if ".so" in ent.name: return False return True def _auto_pack(profiles: list[str], pc: pkgcomposer.PkgComposer): if "lib" in profiles: _do_auto_pack(pc, "lib", "lib", _autopack_filter_lib) if "bin" in profiles: _do_auto_pack(pc, "bin", "bin", _autopack_filter_bin) _do_auto_pack(pc, "sbin", "bin", _autopack_filter_bin) if "dev" in profiles: _do_auto_pack(pc, "lib", "lib", _autopack_filter_dev) _do_auto_pack(pc, "include", "include", _autopack_filter_dev) def use_auto_pack(profiles: list[str]): libmake.on_pack(lambda pc: _auto_pack(profiles, pc))