wiki:howto/PatchLocal

Version 4 (modified by pk@…, 12 years ago) (diff)

portindex will only work if the port is in a known category directory.

<- Back to the HOWTO section

How to Patch a Port on Your System

  • Audience: People who want to change the code of an existing port
  • Requires: MacPorts >= 2.1.2?

Introduction

If you've ever found a port that doesn't work, then found a patch for it with Google, the next step is to apply the patch to the source code, then compile, test, and install the new version of the port so you can use it and get on with your work. This HOWTO will show you how to do that. In this example, I'll be using the 'arb' program as an example.

Installation

Step 1: Set up a local repository

If you want to make changes that stick and won't be overwritten by accident, you need to set up a local repository, described in full here: http://guide.macports.org/#development.local-repositories

Do this to create a new Port (as root):

umask 022
mkdir -p /usr/local/ports

Create the port's category directory (using port "arb" as an example):

PORT_CATEGORY=`port dir arb | awk -F\/ '{ print $(NF-1) }'`
mkdir /usr/local/ports/$PORT_CATEGORY
cd /usr/local/ports/$PORT_CATEGORY
cp -r `port dir arb` .
mv arb arb-devel

Add this line before the 'rsync://.......' line in /opt/local/etc/macports/sources.conf, at the end of the file:

file:///usr/local/ports

Then run this command:

portindex 

Step 2: Get your port's sourcecode

port patch arb-devel
cd `port work arb-devel`

Step 3: Modify the source with your patch

cp Makefile Makefile.orig
vi Makefile
* make changes, compile it, test it *

Step 4: Make a patch

See http://guide.macports.org/#development.patches.source

diff -u Makefile.orig Makefile > /usr/local/ports/arb/files/patch-ARB-makefile2.diff
port edit arb-devel     (add the patch-ARB-makefile2.diff file to the list of patches)

Step 5: Test the modified port

port clean arb-devel
port build arb-devel

Step 6: Make it real

port install arb-devel

<- Back to the HOWTO section