forked from semios/ports
122 lines
3.5 KiB
Python
122 lines
3.5 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from lib import cpp, arch, packie
|
|
from lib.make import *
|
|
|
|
|
|
upstream_version = "7.2.3"
|
|
|
|
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("aws-lc-dev @target")
|
|
builddep("aws-lc-tools")
|
|
builddep("airboot-linux-stage2-mkinitramfs")
|
|
builddep("airboot-linux-stage2-arch @target")
|
|
builddep("flex")
|
|
builddep("bison")
|
|
builddep("bc")
|
|
builddep("gzip")
|
|
builddep("zstd")
|
|
|
|
|
|
def get_arch():
|
|
return arch.get_target().split("-")[0].replace("aarch64", "arm64")
|
|
|
|
def get_variant():
|
|
return os.environ.get("LINUX_VARIANT")
|
|
|
|
|
|
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"HOSTCC={os.environ.get('HOSTCC', 'cc')}"]
|
|
|
|
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 create_initramfs():
|
|
asp_prefix = packie.prefix_of(f"airboot-linux-stage2-arch @{arch.get_target()}")
|
|
subprocess.run([
|
|
"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(f"../KernelInfo.txt", "wt+") as fd:
|
|
fd.write(info)
|
|
|
|
|
|
def build():
|
|
prepare_config()
|
|
make_install_everything()
|
|
create_initramfs()
|
|
generate_info()
|
|
|
|
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")
|
|
|
|
|
|
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")
|
|
on_pack(pack_linux)
|
|
|
|
package(f"{base_name}-dev")
|
|
on_pack(pack_linux_dev)
|