Skip to content

Instantly share code, notes, and snippets.

Last active December 12, 2015 08:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessicah/7cb987f925321fde818c to your computer and use it in GitHub Desktop.
Save jessicah/7cb987f925321fde818c to your computer and use it in GitHub Desktop.
Example of patching software with HaikuPorter

Patching Walkthrough

Let's say we are creating a recipe for cpio. We'll delete the patchset, and walk through the steps to create it again.

Assuming you're at the root of the ports tree you cloned, we'll start with the following:

> cd app-arch/cpio
> mv patches/cpio-2.12.patchset patches/cpio-2.12.patchset.old
> lpe cpio-2.12.recipe
# in Pe, delete the PATCHES line, save and close

Now, in our recipe, in BUILD_REQUIRES, it needs devel:libiconv, which likely won't be installed, so we'll execute the following:

pkgman install -y devel:libiconv

Now we can try to build cpio and see what happens:

> haikuporter --no-dependencies cpio
# eventually, we'll run into an issue!
/sources/cpio-2.12/src/makepath.c: In function `make_path':
/sources/cpio-2.12/src/makepath.c:72: parse error before `char'
/sources/cpio-2.12/src/makepath.c:73: `slash' undeclared (first use in this function)
/sources/cpio-2.12/src/makepath.c:73: (Each undeclared identifier is reported only once
/sources/cpio-2.12/src/makepath.c:73: for each function it appears in.)
# some more error output
keeping chroot folder /path/to/ports/tree/app-arch/cpio/work-2.12 intact for inspection

This error is common when building with gcc2, due to it being very old. The problem here is that gcc2 expects variable declarations to be at the start of the function or block (e.g. an if statement), which is not an error with newer versions of gcc.

So to fix this, we need to go edit the makepath.c file:

# you can use tab completion to get to the source folder
> open work-2.12/sources/cpio-2.12/

This opens a Tracker window, which you can then right-click on src, and click on makepath.c to open it in Pe. Then locate the error, and fix as required, save the file and close it once done. Let's see if that fixed our problem:

> haikuporter --no-dependencies cpio
# we see that we get past the make_path.c error now, yay! but a new problem arises...
../lib/libpax.a(rtapelib.o): In function `rmt_open__':
rtapelib.c:(.text+0x85c): undefined reference to `gethostbyname'
collect2: ld returned 1 exit status

Before we move onto the linker error, we'll commit our change to makepath.c. With the Tracker window of the sources still open, we can use the nifty CTRL+ALT+T shortcut to open a new Terminal session. We'll add the file we modified, and commit it:

> git add src/makepath.c
> git commit
# This will open an editor for you to add the commit message. Add your message, save, and close,
# e.g. "Build fixes for gcc2."

Now let's go and address the linker error. This happens because Haiku has a differently named library compared to Linux and other UNIX-likes. On Haiku, gethostbyname is located in libnetwork, whereas other UNIX-likes normally have gethostbyname in libsocket.

To fix this, we'll modify, and add a check for gethostbyname with a list of libraries to search. See the old patchset for details ;-)

Let's try to build the package once more!

> haikuporter --no-dependencies cpio
grabbing cpio-2.12-1-x86_gcc2.hpkg ...

This time, the build finishes successfully! So let's commit our final change to the sources. Back to our second Terminal window:

> git add
> git commit
# Add your message (e.g. "Search for gethostbyname in libsocket and libnetwork."), save, and close

We can now close this Terminal window, and go back to our first to finish up and test out our work.

> haikuporter --no-dependenices -e cpio
Extracting patchset for cpio-2.12.tar.gz
> ls patches
cpio-2.12.patchset   cpio-2.12.patchset.old
# There's our new patchset!
lpe cpio-2.12.recipe
# Now we can add a line as follows: PATCHES="cpio-2.12.patchset"
# Save and close our updated recipe
> haikuporter --no-dependencies --force cpio

This time, HaikuPorter will delete the source tree, and start the build from scratch. This allows us to test that the patching actually works. It will run through the whole process, and at the beginning, you will see some output of HaikuPorter applying our new patchset!

Now our recipe is complete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment