Files
semios-packages/lib/cpp.py
T
2026-06-10 04:53:01 +08:00

70 lines
2.0 KiB
Python

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):
if not os.path.exists(srcdir):
return
try:
pc.makedir(dstdir)
except Exception:
pass
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}")
elif ent.is_file(follow_symlinks=False):
pc.addfile(ent.path, f"{dstdir}/{ent.name}")
elif ent.is_symlink() and not os.path.isabs(os.readlink(ent.path)):
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))