2015-11-30 23:47:28 +01:00
|
|
|
import os.path, subprocess, sys
|
2023-09-26 14:14:33 +02:00
|
|
|
from typing import Collection, Iterable, Optional, Sequence, Union
|
2015-11-21 00:05:48 +01:00
|
|
|
|
2017-10-06 23:06:28 +02:00
|
|
|
from build.makeproject import MakeProject
|
2023-09-26 12:47:44 +02:00
|
|
|
from .toolchain import AnyToolchain
|
2015-11-21 00:05:48 +01:00
|
|
|
|
2017-10-06 23:06:28 +02:00
|
|
|
class AutotoolsProject(MakeProject):
|
2023-09-26 14:14:33 +02:00
|
|
|
def __init__(self, url: Union[str, Sequence[str]], md5: str, installed: str,
|
2023-09-16 23:23:18 +02:00
|
|
|
configure_args: Iterable[str]=[],
|
|
|
|
autogen: bool=False,
|
|
|
|
autoreconf: bool=False,
|
|
|
|
cppflags: str='',
|
|
|
|
ldflags: str='',
|
|
|
|
libs: str='',
|
|
|
|
subdirs: Optional[Collection[str]]=None,
|
2015-11-21 00:05:48 +01:00
|
|
|
**kwargs):
|
2017-10-06 23:06:28 +02:00
|
|
|
MakeProject.__init__(self, url, md5, installed, **kwargs)
|
2015-11-21 00:05:48 +01:00
|
|
|
self.configure_args = configure_args
|
|
|
|
self.autogen = autogen
|
2018-02-20 22:46:54 +01:00
|
|
|
self.autoreconf = autoreconf
|
2015-11-21 00:05:48 +01:00
|
|
|
self.cppflags = cppflags
|
2018-01-05 07:56:49 +01:00
|
|
|
self.ldflags = ldflags
|
|
|
|
self.libs = libs
|
2018-01-19 11:39:33 +01:00
|
|
|
self.subdirs = subdirs
|
2015-11-21 00:05:48 +01:00
|
|
|
|
2023-09-26 12:47:44 +02:00
|
|
|
def configure(self, toolchain: AnyToolchain) -> str:
|
2015-11-21 00:05:48 +01:00
|
|
|
src = self.unpack(toolchain)
|
|
|
|
if self.autogen:
|
2015-11-30 23:47:28 +01:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
subprocess.check_call(['glibtoolize', '--force'], cwd=src)
|
|
|
|
else:
|
|
|
|
subprocess.check_call(['libtoolize', '--force'], cwd=src)
|
2015-11-30 23:44:57 +01:00
|
|
|
subprocess.check_call(['aclocal'], cwd=src)
|
|
|
|
subprocess.check_call(['automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
|
|
|
|
subprocess.check_call(['autoconf'], cwd=src)
|
2018-02-20 22:46:54 +01:00
|
|
|
if self.autoreconf:
|
|
|
|
subprocess.check_call(['autoreconf', '-vif'], cwd=src)
|
2015-11-21 00:05:48 +01:00
|
|
|
|
|
|
|
build = self.make_build_path(toolchain)
|
|
|
|
|
|
|
|
configure = [
|
|
|
|
os.path.join(src, 'configure'),
|
|
|
|
'CC=' + toolchain.cc,
|
|
|
|
'CXX=' + toolchain.cxx,
|
|
|
|
'CFLAGS=' + toolchain.cflags,
|
|
|
|
'CXXFLAGS=' + toolchain.cxxflags,
|
|
|
|
'CPPFLAGS=' + toolchain.cppflags + ' ' + self.cppflags,
|
2018-01-05 07:56:49 +01:00
|
|
|
'LDFLAGS=' + toolchain.ldflags + ' ' + self.ldflags,
|
|
|
|
'LIBS=' + toolchain.libs + ' ' + self.libs,
|
2015-11-21 00:05:48 +01:00
|
|
|
'AR=' + toolchain.ar,
|
2023-03-06 13:25:43 +01:00
|
|
|
'ARFLAGS=' + toolchain.arflags,
|
2016-10-26 10:40:19 +02:00
|
|
|
'RANLIB=' + toolchain.ranlib,
|
2015-11-21 00:05:48 +01:00
|
|
|
'STRIP=' + toolchain.strip,
|
|
|
|
'--host=' + toolchain.arch,
|
|
|
|
'--prefix=' + toolchain.install_prefix,
|
2022-08-08 10:05:30 +02:00
|
|
|
'--disable-silent-rules',
|
2015-11-21 00:05:48 +01:00
|
|
|
] + self.configure_args
|
|
|
|
|
2021-08-13 18:52:00 +02:00
|
|
|
try:
|
2022-08-08 10:05:30 +02:00
|
|
|
print(configure)
|
2021-08-13 18:52:00 +02:00
|
|
|
subprocess.check_call(configure, cwd=build, env=toolchain.env)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# dump config.log after a failed configure run
|
|
|
|
try:
|
|
|
|
with open(os.path.join(build, 'config.log')) as f:
|
|
|
|
sys.stdout.write(f.read())
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
# re-raise the exception
|
|
|
|
raise
|
|
|
|
|
2017-10-06 23:06:28 +02:00
|
|
|
return build
|
|
|
|
|
2023-09-26 12:47:44 +02:00
|
|
|
def _build(self, toolchain: AnyToolchain) -> None:
|
2017-10-06 23:06:28 +02:00
|
|
|
build = self.configure(toolchain)
|
2018-01-19 11:39:33 +01:00
|
|
|
if self.subdirs is not None:
|
|
|
|
for subdir in self.subdirs:
|
2021-08-28 22:38:02 +02:00
|
|
|
self.build_make(toolchain, os.path.join(build, subdir))
|
2018-01-19 11:39:33 +01:00
|
|
|
else:
|
2021-08-28 22:38:02 +02:00
|
|
|
self.build_make(toolchain, build)
|