2017-09-30 00:10:24 +02:00
|
|
|
import subprocess, multiprocessing
|
2023-09-16 23:23:18 +02:00
|
|
|
from typing import Optional
|
2017-10-06 23:06:28 +02:00
|
|
|
|
|
|
|
from build.project import Project
|
|
|
|
|
|
|
|
class MakeProject(Project):
|
2023-09-16 23:23:18 +02:00
|
|
|
def __init__(self, url: str, md5: str, installed: str,
|
|
|
|
install_target: str='install',
|
2017-10-06 23:06:28 +02:00
|
|
|
**kwargs):
|
|
|
|
Project.__init__(self, url, md5, installed, **kwargs)
|
|
|
|
self.install_target = install_target
|
|
|
|
|
2023-09-16 23:23:18 +02:00
|
|
|
def get_simultaneous_jobs(self) -> int:
|
2017-09-30 00:10:24 +02:00
|
|
|
try:
|
|
|
|
# use twice as many simultaneous jobs as we have CPU cores
|
|
|
|
return multiprocessing.cpu_count() * 2
|
|
|
|
except NotImplementedError:
|
|
|
|
# default to 12, if multiprocessing.cpu_count() is not implemented
|
|
|
|
return 12
|
2017-10-06 23:06:28 +02:00
|
|
|
|
2023-09-16 23:23:18 +02:00
|
|
|
def get_make_args(self, toolchain) -> list[str]:
|
2017-10-06 23:06:28 +02:00
|
|
|
return ['--quiet', '-j' + str(self.get_simultaneous_jobs())]
|
|
|
|
|
2023-09-16 23:23:18 +02:00
|
|
|
def get_make_install_args(self, toolchain) -> list[str]:
|
2017-10-06 23:06:28 +02:00
|
|
|
return ['--quiet', self.install_target]
|
|
|
|
|
2023-09-16 23:23:18 +02:00
|
|
|
def make(self, toolchain, wd: str, args: list[str]) -> None:
|
2017-10-10 00:08:14 +02:00
|
|
|
subprocess.check_call(['make'] + args,
|
2017-10-06 23:06:28 +02:00
|
|
|
cwd=wd, env=toolchain.env)
|
|
|
|
|
2023-09-16 23:23:18 +02:00
|
|
|
def build_make(self, toolchain, wd: str, install: bool=True) -> None:
|
2017-10-06 23:06:28 +02:00
|
|
|
self.make(toolchain, wd, self.get_make_args(toolchain))
|
|
|
|
if install:
|
|
|
|
self.make(toolchain, wd, self.get_make_install_args(toolchain))
|