mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-13 20:12:26 +00:00
93 lines
2.4 KiB
Python
Executable File
93 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import shutil
|
|
|
|
import common
|
|
|
|
class LinuxComponent(common.Component):
|
|
def add_parser_arguments(self, parser):
|
|
parser.add_argument(
|
|
'extra_make_args',
|
|
default=[],
|
|
metavar='extra-make-args',
|
|
nargs='*'
|
|
)
|
|
|
|
def do_build(self, args):
|
|
build_dir = self.get_build_dir(args)
|
|
os.makedirs(build_dir, exist_ok=True)
|
|
common.cp(
|
|
os.path.join(common.linux_config_dir, 'buildroot-{}'.format(args.arch)),
|
|
os.path.join(build_dir, '.config'),
|
|
)
|
|
tool = 'gcc'
|
|
gcc = common.get_toolchain_tool(tool)
|
|
prefix = gcc[:-len(tool)]
|
|
common_args = {
|
|
'cwd': common.linux_src_dir,
|
|
}
|
|
ccache = shutil.which('ccache')
|
|
if ccache is not None:
|
|
cc = '{} {}'.format(ccache, gcc)
|
|
else:
|
|
cc = gcc
|
|
common_make_args = [
|
|
'ARCH={}'.format(common.linux_arch),
|
|
'CROSS_COMPILE={}'.format(prefix),
|
|
'CC={}'.format(cc),
|
|
'O={}'.format(build_dir),
|
|
]
|
|
if args.verbose:
|
|
verbose = ['V=1']
|
|
else:
|
|
verbose = []
|
|
common.run_cmd(
|
|
[
|
|
os.path.join(common.linux_src_dir, 'scripts', 'kconfig', 'merge_config.sh'),
|
|
'-m',
|
|
'-O', build_dir,
|
|
os.path.join(build_dir, '.config'),
|
|
os.path.join(common.linux_config_dir, 'min'),
|
|
os.path.join(common.linux_config_dir, 'default'),
|
|
],
|
|
)
|
|
common.run_cmd(
|
|
(
|
|
[
|
|
'make',
|
|
'-j', str(args.nproc),
|
|
] +
|
|
common_make_args +
|
|
[
|
|
'olddefconfig',
|
|
]
|
|
),
|
|
**common_args,
|
|
)
|
|
common.run_cmd(
|
|
(
|
|
[
|
|
'make',
|
|
'-j', str(args.nproc),
|
|
] +
|
|
common_make_args +
|
|
verbose +
|
|
args.extra_make_args
|
|
),
|
|
**common_args,
|
|
)
|
|
|
|
def get_argparse_args(self):
|
|
return {
|
|
'description': '''\
|
|
Build the Linux kernel.
|
|
'''
|
|
}
|
|
|
|
def get_build_dir(self, args):
|
|
return common.linux_build_dir
|
|
|
|
if __name__ == '__main__':
|
|
LinuxComponent().build()
|