166 lines
4.9 KiB
Python
166 lines
4.9 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from lib import cpp, arch, packie
|
|
from lib.make import *
|
|
|
|
|
|
upstream_version = "7.3.1"
|
|
|
|
version(f"{upstream_version}")
|
|
description("the Linux operating system kernel")
|
|
maintainer("sisungo <[email protected]>")
|
|
source_url(f"https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-{upstream_version}.tar.xz")
|
|
|
|
builddep("shortcut/c")
|
|
builddep("shortcut/autotools")
|
|
builddep("libncurses-dev")
|
|
builddep("libexpat")
|
|
builddep("openssl-dev")
|
|
builddep("openssl-tools")
|
|
builddep("flex")
|
|
builddep("bison")
|
|
builddep("bc")
|
|
builddep("gzip")
|
|
builddep("zstd")
|
|
builddep("bash")
|
|
builddep("util-linux-text")
|
|
builddep("rsync (=3.5.2)")
|
|
builddep("kmod")
|
|
builddep("airboot-linux-stage2-mkinitramfs")
|
|
builddep("airboot-linux-stage2-arch @target")
|
|
builddep("libgelf-dev @target")
|
|
builddep("libtraceevent-dev @target")
|
|
|
|
|
|
def get_arch():
|
|
return arch.get_target().split("-")[0].replace("riscv64", "riscv").replace("aarch64", "arm64")
|
|
|
|
def get_variant():
|
|
return os.environ.get("LINUX_VARIANT")
|
|
|
|
|
|
def prepare_atomenv():
|
|
if in_atomic():
|
|
packie.select("/bin/openssl", "openssl-tools")
|
|
# FIXME: Currently, `bash` do not provide link `/bin/sh`
|
|
os.system("ln -sf /bin/bash /bin/sh")
|
|
|
|
def prepare_config():
|
|
config_name = get_arch()
|
|
if get_variant():
|
|
config_name += "-" + get_variant()
|
|
config_file = "../../configs/config." + config_name
|
|
|
|
shutil.copy2(config_file, ".config")
|
|
|
|
def make_install_everything():
|
|
makeopts = [
|
|
f"ARCH={get_arch()}",
|
|
"LLVM=1",
|
|
f"CC={packie.prefix_of('clang')}/bin/clang",
|
|
f"HOSTCC={os.environ.get('HOSTCC', 'cc')}",
|
|
f"KCFLAGS=-isystem {packie.prefix_of('clang')}/lib/clang/23/include",
|
|
]
|
|
|
|
cpp.make(makeopts + ["olddefconfig"])
|
|
cpp.make(makeopts)
|
|
cpp.make(makeopts + ["headers_install", "INSTALL_HDR_PATH=../kheaders_install"])
|
|
cpp.make(makeopts + ["install", "INSTALL_PATH=../kimage_install"])
|
|
cpp.make(
|
|
makeopts + ["modules_install", "INSTALL_MOD_STRIP=1", "INSTALL_MOD_PATH=../kmod_install"]
|
|
)
|
|
os.remove(f"../kmod_install/lib/modules/{upstream_version}/build")
|
|
|
|
def make_perf():
|
|
oldpwd = os.getcwd()
|
|
os.chdir("tools/perf")
|
|
cpp.make([
|
|
f"ARCH={get_arch()}",
|
|
"LLVM=1",
|
|
"NO_LIBDW=1",
|
|
"NO_LIBELF=0",
|
|
"NO_JEVENTS=1",
|
|
"EXTRA_CFLAGS=-Wno-error=unused-but-set-global -Wno-error=initializer-overrides",
|
|
])
|
|
os.chdir(oldpwd)
|
|
|
|
def create_initramfs():
|
|
asp_prefix = packie.prefix_of(f"airboot-linux-stage2-arch @{arch.get_target()}")
|
|
subprocess.run([
|
|
f"{packie.prefix_of('airboot-linux-stage2-mkinitramfs')}/bin/mkinitramfs",
|
|
"-a", f"{asp_prefix}/data",
|
|
"-o", f"{os.getcwd()}/../initramfs.img",
|
|
"-m", f"{os.getcwd()}/../kmod_install",
|
|
"-k", upstream_version,
|
|
], check=True)
|
|
|
|
def generate_info():
|
|
info = ""
|
|
info += f"KERNEL_INFO_UPSTREAM_VERSION={upstream_version}\n"
|
|
info += f"KERNEL_INFO_VARIANT={get_variant() or ''}\n"
|
|
info += f"KERNEL_INFO_ARCHITECTURE={get_arch()}\n"
|
|
with open("../KernelInfo.txt", "wt+") as fd:
|
|
fd.write(info)
|
|
|
|
|
|
def build():
|
|
prepare_atomenv()
|
|
prepare_config()
|
|
make_install_everything()
|
|
create_initramfs()
|
|
generate_info()
|
|
make_perf()
|
|
|
|
on_build(build)
|
|
|
|
|
|
def pack_linux_dev(composer):
|
|
composer.add_dir(
|
|
"../kheaders_install/include",
|
|
"include",
|
|
)
|
|
|
|
def pack_linux(composer):
|
|
vmlinux_origin = f"../kimage_install/vmlinux-{upstream_version}"
|
|
vmlinuz_origin = f"../kimage_install/vmlinuz-{upstream_version}"
|
|
system_map_origin = f"../kimage_install/System.map-{upstream_version}"
|
|
modules_origin = f"../kmod_install/lib/modules/{upstream_version}"
|
|
initramfs_origin = "../initramfs.img"
|
|
if os.path.exists(vmlinux_origin):
|
|
composer.addfile(vmlinux_origin, "vmlinux")
|
|
if os.path.exists(vmlinuz_origin):
|
|
composer.addfile(vmlinuz_origin, "vmlinuz")
|
|
if os.path.exists(system_map_origin):
|
|
composer.addfile(system_map_origin, "System.map")
|
|
composer.add_dir(modules_origin, "modules")
|
|
composer.addfile(initramfs_origin, "initramfs.img")
|
|
composer.addfile("../KernelInfo.txt", "KernelInfo.txt")
|
|
|
|
def pack_perf(composer):
|
|
composer.makedir("bin")
|
|
composer.add("tools/perf/perf", "bin/perf")
|
|
|
|
base_name = "linux"
|
|
if os.environ.get("LINUX_VARIANT"):
|
|
base_name += "-" + os.environ["LINUX_VARIANT"]
|
|
|
|
package(f"{base_name}")
|
|
configure_script("configure/kernel-install")
|
|
configure_script("configure/kernel-remove")
|
|
link("modules", f"/lib/modules/{upstream_version}")
|
|
on_pack(pack_linux)
|
|
|
|
package(f"{base_name}-dev")
|
|
description("the Linux operating system kernel -- development files (e.g. headers)")
|
|
on_pack(pack_linux_dev)
|
|
|
|
if base_name == "linux":
|
|
package("perf")
|
|
description("the Linux operating system kernel -- performance counter tool")
|
|
dep("semi-libc @same-arch")
|
|
dep("libgelf @same-arch")
|
|
dep("libtraceevent @same-arch")
|
|
on_pack(pack_perf)
|