Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Mar 2010 13:01:30 -0700
From:      Charlie Kester <corky1951@comcast.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: Elegant way to hack port source
Message-ID:  <20100319200130.GE265@comcast.net>
In-Reply-To: <20100319170159.GB71392@slackbox.erewhon.net>
References:  <a14066a01003190935t4bbef41esc44c60a5b00e6144@mail.gmail.com> <20100319170159.GB71392@slackbox.erewhon.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri 19 Mar 2010 at 10:01:59 PDT Roland Smith wrote:
>On Fri, Mar 19, 2010 at 12:35:30PM -0400, Alejandro Imass wrote:
>> Hi,
>>
>> I need to modify a file from a port before building. Specifically, the
>> sane-backends pnm.c driver has a bug and the folks at the original
>> project has not fixed for a while. I need to modify pnm.c in the work
>> directory before compiling. What is an elegant way of doing this? If I
>> make and then modify, the main make file does not see the change made
>> in the file and will not recompile. And since there is no actual
>> makefile in the work subdirectory I can't compile there either!
>>
>> There must be a FreeBSD way of dealing with modifying a port source
>> before compiling. Please advise.
>
>Add the patch to the files/ directory of the port. The patch should be
>relative to the main source directory of the port, e.g. work/foo-x.y for the
>foo port. Use a name for the patch that doesn't exist yet.
>
>After creating the patch, use chflags to set the uschg and uunlnk flags for
>your patch. This way, if the port is updated, your patch cannot be
>removed. But you might need to update it.

If the port already patches the file(s) in question, run 'make patch'
with the port makefile first, so you don't lose that work.

Then cd to the working directory and make your additional changes.  

If you need to change a file that wasn't already patched by the port,
first save a copy of it using 'cp foo{,.orig}'.  Then edit the copy
without the .orig suffix.

When you're done with those, use 'diff -u foo{.orig,}' to generate an
updated patchfile.

The convention is to name the patchfile 'patch-foo' (substituting the
actual name of the source file for 'foo').  But if the existing patch
uses some other pattern, use that instead.

So, if you're updating or creating a patch to foo.c which is in the
toplevel working directory for port bar, and you're in work/bar-x.y, 
you would use something like the following: 

	diff -u foo.c{.orig,} > ../../files/patch-foo.c

Now run 'make clean' with the port makefile.  From here on, 'make build'
or 'make install' will apply your new patches along with any
pre-existing ones.

Whenever I modify a port like this, I usually make a copy of it under
root's home directory and install it from there.  That way, I can keep
my copy of the portstree in complete synch with the official one, and
there's no need to worry about updates quashing my changes.  It also
provides a quick-and-dirty way to see which ports I've modified.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100319200130.GE265>