Skip to content

Instantly share code, notes, and snippets.

@rickyzhang82
Last active November 25, 2020 05:25
Show Gist options
  • Save rickyzhang82/40f7116508a1782cd1c0268b8828b970 to your computer and use it in GitHub Desktop.
Save rickyzhang82/40f7116508a1782cd1c0268b8828b970 to your computer and use it in GitHub Desktop.
Patch MacPort locally

General User Guide

Sample -- Create local portfile repository

  1. Open sources.conf in a text editor. For example, to open it into TextEdit:

     open -e ${prefix}/etc/macports/sources.conf
     prefix = /opt/local
  2. Insert a URL pointing to your local repository location before the rsync URL as shown.

    file:///Users/Ricky/ports
    rsync://rsync.macports.org/release/ports [default]
    Note

    The file URL should always appear before the rsync URL so that local Portfiles 
    can be tested that are duplicated in the MacPorts tree, because port will always 
    operate on the first Portfile it encounters.
  1. Place the Portfiles you create inside a directory whose name matches the port, which should in turn be placed inside a directory that reflects the port's primary category (the first category entry in the Portfile). For example, to create the directory for a hypothetical port “bestevergame” and to begin editing its Portfile in TextEdit, you can use these commands:
     mkdir -p ~/ports/games/bestevergame
     cd ~/ports/games/bestevergame
     touch Portfile
     open -e Portfile

See other sections in the Guide for help writing Portfiles. If you've already written the Portfile elsewhere, you can instead copy the Portfile into this directory.

  1. If your Portfile needs to apply any patches to the port's source files, create a files directory and place the patchfiles in it, and reference the patchfiles in your Portfile, as explained in Creating Source Code Patches.

  2. After you create or update your Portfile, use portindex in the local repository's directory to create or update the index of the ports in your local repository.

    cd ~/ports
    portindex
    Creating software index in /Users/julesverne/ports
    Adding port games/bestevergame

    Total number of ports parsed:   1
    Ports successfully parsed:      1
    Ports failed:                   0
Once the local port is added to the PortIndex, it becomes available for searching or installation as with any other Portfile in the MacPorts tree:
%% port search bestever

bestevergame @1.1 (games)
    The Best Ever Game

Another User Guide

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):

mkdir -p ~/ports

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

PORT_CATEGORY=`port dir arb | awk -F\/ '{ print $(NF-1) }'`
mkdir ~/ports/$PORT_CATEGORY
cd ~/ports/$PORT_CATEGORY
cp -r `port dir arb` .
mv arb arb-devel
# edit arb-devel/Portfile and replace "name arb" with "name arb-devel"
cd arb-devel
port lint # to check for problems

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

file:///Users/Ricky/ports

Then run this command:

cd ~/ports && 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 > `port dir arb-devel`/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 -s install arb-devel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment