33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from .util import libs_dir, print_error_message
|
|
from .console import console
|
|
|
|
import sys
|
|
import os
|
|
import glob
|
|
import pathlib
|
|
import subprocess
|
|
|
|
def build(args):
|
|
comet_libs_dir = libs_dir()
|
|
|
|
folder_path = pathlib.Path(args.path).resolve()
|
|
folder_name = folder_path.name
|
|
|
|
out_path = os.path.join(comet_libs_dir, f"{folder_name}.cometlib")
|
|
|
|
c_files = glob.glob(f"{args.path}/src/*.c", recursive=True)
|
|
if len(c_files) == 0:
|
|
print_error_message(f"No C files were found in that directory! [d white]({folder_name}/src)[/d white]")
|
|
sys.exit(1)
|
|
|
|
with console.status("Building", spinner="moon") as status:
|
|
try:
|
|
subprocess.run(
|
|
["gcc"] + c_files + ["-fPIC", "-shared", "-Wl,-undefined,symbol_lookup", "-o", out_path] + args.gcc_args,
|
|
check=True
|
|
)
|
|
except subprocess.CalledProcessError as e:
|
|
print_error_message(f"Failed to install [b]{folder_name}[/]: build failed!")
|
|
sys.exit(1)
|
|
|
|
console.log(f"[b][:white_check_mark:] Installed [green]{folder_name}[/green]![/b]") |