Patching
Appearance
Introduction
The most common use-case is, that you want to package an Android kernel. But it does not compile with our GCC6, so you need to patch the kernel. Unlike in the Android world, we do not fork the kernel repository and apply our patches there. Instead we ship our custom patches with the package build recipe in the aport folder.
This guide assumes, that you already know what to patch - if you don't know what to patch and only have the error, try to search the web for that error message. More often than not, there is a patch already available, that will fix it. If you don't have any luck, ask in the chat.
As everywhere else in the wiki, please expand this guide wherever information is missing that would have helped you!
Workflow
- Try to compile your program with
pmbootstrap build my-package
. Note in which chroot it will actually build, it is the start of the building message. When it starts with(native)
for example, the chroot is the "native" chroot (which is the default). - Wait until it fails or runs through (it works in both cases)
- The sources of the kernel are now extracted in
/home/user/build/src
in the chroot where it was building. - Use
pmbootstrap chroot
to enter the chroot and to create the patch. It will enter the native chroot by default, if you need another chroot, then look atpmbootstrap chroot --help
. Then do the following inside the chroot shell:- Install
git
and a editor such asnano
with:apk add git nano
- Switch from root to user:
su - user
- Go into the source folder:
cd ~/build/src/
- Patches get applied in the builddir, so usually there is another folder inside
src
, that you need to enter. You can check withls
which folders/files are inside thesrc
folder. Enter that subfolder if necessary. - We'll be using git to create a patch file, so we will initialize a new repository and add everything:
git init .
(it will say: "Initialized empty Git repository in /home/user/build/src/.git/")git add -A
git commit -m "initial"
- Now it's time to edit the file you want to edit.
export TERM=xterm
nano Makefile
(or whichever file you want to edit)- NOTE: nano is glitchy when used like that. If it is unusable for you, run
chmod 777 Makefile
and then edit the file from outside the chroot with your favorite editor (a graphical one works, too!). The path is similar to:~/.local/var/pmbootstrap/chroot_native/home/user/build/src/(optional builddir)/Makefile
.
- (in the chroot again) run
git diff
to get a patch file generated to the screen. You can save it to a file by redirecting it:git diff > /tmp/mypatch.patch
. - Quit the chroot by pressing
^D
(CTRL+D) twice (typingexit
also works).
- Install
- Copy the patch file you have created to your aport folder (adjust the work path, that you have given
pmbootstrap init
and the chroot suffixnative
if necessary):cp ~/.local/var/pmbootstrap/chroot_native/tmp/mypatch.patch ~/code/pmbootstrap/aports/device/linux-my-cool-kernel/mypatch.patch
- Rename the
mypatch.patch
file to give it a meaningful name! - You can add arbitrary text at the top of the patch file. Use this to paste the error message that you got during compilation there, with a note that this will be fixed by this patch.