# Problem creating patch file



## roddierod (Dec 23, 2008)

I am working on a port of screenlets and I'm having trouble with get the patch file to apply when I try and build the port.

When it comes time to apply the patches the port stops like this


```
Applying FreeBSD patches for screenlets-0.1.2_1
File to patch:
```

I created the patch like this:

```
diff -ruN screenlets/src/bin/screenlets.orig screenlets/src/bin/screenlets > ../files/patch-screenlets
```

I'm using FreeBSD 7.1 Prerelease built Dec 13th.

this is one of the patch files, patch-screenlets

```
--- screenlets.orig     2008-06-04 08:31:25.000000000 -0400
+++ screenlets  2008-12-23 11:42:10.000000000 -0500
@@ -1,5 +1,5 @@
 #!/bin/sh
-PREFIX=$(cat /etc/screenlets/prefix)
+PREFIX=/usr/local
 if [ -e $PREFIX/share/screenlets-manager/screenlets-manager.py ]; then
        exec python -u $PREFIX/share/screenlets-manager/screenlets-manager.py $@
 else
```


----------



## amdmi3@ (Dec 23, 2008)

Patches should be relative to ${PATCH_WRKSRC} which I assume is work/screenlets in your case.

Thus the correct patch would be (note path in +++ line):


```
% diff -u src/bin/screenlets.orig src/bin/screenlets 
--- src/bin/screenlets.orig	2008-12-24 02:36:29.000000000 +0300
+++ src/bin/screenlets	2008-12-24 02:36:37.000000000 +0300
@@ -1,5 +1,5 @@
 #!/bin/sh
-PREFIX=$(cat /etc/screenlets/prefix)
+PREFIX=/usr/local
 if [ -e $PREFIX/share/screenlets-manager/screenlets-manager.py ]; then
 	exec python -u $PREFIX/share/screenlets-manager/screenlets-manager.py $@
 else
```

But, actually you should not use patch in this case at all.

I'd recommend this:


```
post-patch:
    @${REINPLACE_CMD} -e '/^PREFIX=/ s|=.*|=${PREFIX}|' \
        ${WRKSRC}/src/bin/screenlets
```

Note that this is shorter, easier to handle and it respects PREFIX (it should!).


----------



## tingo (Dec 25, 2008)

@roddierod:
I prefer patchtool (/usr/ports/Tools/scripts/patchtool.py and /usr/ports/Tools/scripts/README.patchtool) for creating patches when I try to fix things in ports.
To make it easier to use I have set up an alias for it:
alias patchtool='/usr/ports/Tools/scripts/patchtool.py '
(yes, I use /bins/sh as my shell.)
HTH


----------



## roddierod (Dec 26, 2008)

@tingo:
thank you very much this makes things so much easier, especially with the number of patches I have to make for this port.

@amdmi3@:
I tried using the post-patch code you suggested, but I could not get that to work for me.


----------



## tingo (Dec 31, 2008)

Also check out porttools (ports-mgmt/porttools), the 'port test' command is very helpful when creating a port. I just learned about porttools myself yesterday.


----------



## crsd (Jan 1, 2009)

there's also 'makepatch' target, which checks ${WRKSRC} for *.orig files and creates diffs in /files/ accordingly


----------

