#!/usr/bin/env python3 import multiprocessing 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 = [] assert 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'), ], ) == 0 assert common.run_cmd( ( [ 'make', '-j', str(multiprocessing.cpu_count()), ] + common_make_args + [ 'olddefconfig', ] ), **common_args, ) == 0 assert common.run_cmd( ( [ 'make', '-j', str(multiprocessing.cpu_count()), ] + common_make_args + verbose + args.extra_make_args ), **common_args, ) == 0 def get_argparse_args(self): return { 'description': '''\ Build the Linux kernel. ''' } def get_build_dir(self, args): return common.linux_build_dir LinuxComponent().build()