Skip to content

kernel: Move kernel part build rules from Makefile to Kbuild#3003

Merged
Ylarod merged 5 commits into
tiann:mainfrom
dabao1955:spilt-makefile-kbuild
Nov 29, 2025
Merged

kernel: Move kernel part build rules from Makefile to Kbuild#3003
Ylarod merged 5 commits into
tiann:mainfrom
dabao1955:spilt-makefile-kbuild

Conversation

@dabao1955

Copy link
Copy Markdown
Contributor

This commit reorganizes the KernelSU build system by relocating all kernel-specific build definitions—previously embedded in kernel/Makefile—into a dedicated kernel/Kbuild file, in strict accordance with the Linux kernel's out-of-tree module conventions.

The Kbuild file is the standard and only appropriate location for declaring:

  • Object file lists (kernelsu-objs),
  • Compiler flags (ccflags-y),
  • Conditional logic for versioning (Git revision count),
  • Security-related macros (e.g., KSU_VERSION, EXPECTED_HASH, KSU_MANAGER_PACKAGE),
  • Header include paths and warning suppressions.

The top-level kernel/Makefile is now reduced to its intended role: a minimal user-facing entry point that invokes the kernel’s build system via make -C $(KDIR) M=$(MDIR) modules. This separation ensures compatibility with the kernel’s build infrastructure (including O= out-of-source builds, LLVM builds, and modpost) and adheres to guidelines in Documentation/kbuild/modules.rst.

No functional or behavioral changes are introduced—this is a pure build-system refactor to improve correctness, maintainability, and alignment with upstream practices.

This commit reorganizes the KernelSU build system by relocating all kernel-specific build definitions—previously embedded in `kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`, `KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a minimal user-facing entry point that invokes the kernel’s build system via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures compatibility with the kernel’s build infrastructure (including `O=` out-of-source builds, LLVM builds, and modpost) and adheres to guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure build-system refactor to improve correctness, maintainability, and alignment with upstream practices.

Signed-off-by: dabao1955 <dabao1955@163.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the KernelSU build system by moving kernel module build definitions from kernel/Makefile to kernel/Kbuild, following Linux kernel out-of-tree module conventions. The Makefile now serves only as a user-facing entry point that invokes the kernel build system.

Key Changes:

  • Relocated all object file declarations (kernelsu-objs), compiler flags (ccflags-y), and versioning logic from Makefile to Kbuild
  • Simplified Makefile to contain only build invocation targets (all, compdb, clean)
  • Maintained all functional definitions including git version detection, manager signature configuration, and warning suppressions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
kernel/Makefile Simplified to contain only PHONY targets that invoke the kernel build system via make -C $(KDIR) M=$(MDIR) modules
kernel/Kbuild New file containing all kernel module build rules, object file lists, compiler flags, versioning logic, and security macros previously in Makefile

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread kernel/Kbuild
Comment thread kernel/Kbuild
dabao1955 and others added 2 commits November 29, 2025 13:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Ylarod

Ylarod commented Nov 29, 2025

Copy link
Copy Markdown
Collaborator

missing kernel/selinux/Makefile

@dabao1955

dabao1955 commented Nov 29, 2025

Copy link
Copy Markdown
Contributor Author

missing kernel/selinux/Makefile

kernel/selinux objects already defined in Kbuild.

  CC [M]  /__w/KernelSU/KernelSU/kernel/selinux/selinux.o
  CC [M]  /__w/KernelSU/KernelSU/kernel/selinux/sepolicy.o
  CC [M]  /__w/KernelSU/KernelSU/kernel/selinux/rules.o
  LD [M]  /__w/KernelSU/KernelSU/kernel/kernelsu.o

@Ylarod

Ylarod commented Nov 29, 2025

Copy link
Copy Markdown
Collaborator

so remove it, since it's not needed

selinux objects already defined on Kbuild.
@dabao1955

Copy link
Copy Markdown
Contributor Author

so remove it, since it's not needed

Deleted.

@dabao1955

Copy link
Copy Markdown
Contributor Author

CC @Ylarod please review

@Ylarod Ylarod merged commit 1ad5ef3 into tiann:main Nov 29, 2025
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Nov 29, 2025
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Nov 29, 2025
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
larpedd pushed a commit to larpedd/KernelSU that referenced this pull request Dec 20, 2025
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 5, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 5, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 8, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 13, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
RapliVx pushed a commit to RapliVx/KernelSU that referenced this pull request Jan 26, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
LeCmnGend pushed a commit to LeCmnGend/KernelSU that referenced this pull request Feb 23, 2026
)

This commit reorganizes the KernelSU build system by relocating all
kernel-specific build definitions—previously embedded in
`kernel/Makefile`—into a dedicated `kernel/Kbuild` file, in strict
accordance with the Linux kernel's out-of-tree module conventions.

The `Kbuild` file is the standard and only appropriate location for
declaring:
- Object file lists (`kernelsu-objs`),
- Compiler flags (`ccflags-y`),
- Conditional logic for versioning (Git revision count),
- Security-related macros (e.g., `KSU_VERSION`, `EXPECTED_HASH`,
`KSU_MANAGER_PACKAGE`),
- Header include paths and warning suppressions.

The top-level `kernel/Makefile` is now reduced to its intended role: a
minimal user-facing entry point that invokes the kernel’s build system
via `make -C $(KDIR) M=$(MDIR) modules`. This separation ensures
compatibility with the kernel’s build infrastructure (including `O=`
out-of-source builds, LLVM builds, and modpost) and adheres to
guidelines in `Documentation/kbuild/modules.rst`.

No functional or behavioral changes are introduced—this is a pure
build-system refactor to improve correctness, maintainability, and
alignment with upstream practices.

---------

Signed-off-by: dabao1955 <dabao1955@163.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants