How to apply a .patch to source files

Moderator: Forum moderators

Post Reply
dogcat
Posts: 199
Joined: Fri Feb 18, 2022 11:14 pm
Has thanked: 32 times
Been thanked: 80 times

How to apply a .patch to source files

Post by dogcat »

How to apply a patch to source files. I recently kludged my way through this and found no information in the puppy forums about how to actually apply patches.
--
Sometimes libraries and or program sources need to be patched and recompiled to fix issues.
Patches will have the file extension .patch, for example your-patch-file.patch

The following procedure is how I accomplished applying a .patch file in Puppy Linux.

1. Download the source files that need patching. Make certain they are the correct files to patch or patching will fail. Usually there is an MD5, SHA1, or SHA256 associated with an archive that you can verify the source archive with.

2. Locate the .patch (usually downloaded from somewhere but can come as additional sources on a CD for drivers, etc.)

3. Extract (uncompress) the sources if they are an archive. You should now have a directory containing the source files.

4. Copy your .patch file into the directory with the source files to be patched.

5. Load the DEVX (the DEVX will usually need to be loaded because that is where the patch utility is located)

6. Using your file manager (ROX in Puppy Linux) navigate to the extracted source directory that should now also contain the .patch file.

7. Open a terminal window in that directory (using ROX or whatever file manager or method you normally use to do that. Opening the terminal in the directory is the easiest way I know of)

8. It is now time to patch. There are a lot of command line options for patch, this command is what I found that works for me. In the terminal window use the following patch command:

Code: Select all

patch -Np1 -i your-patch-file.patch

that will run the patch "your-patch-file.patch" against the proper files in the directory. Your actual .patch file name will be different.

P.S. After patching, make sure the patched files do not have a time in the future if you are compiling your patched files, that will prevent compiling loops.

Additional information about creating and applying .patch files here
https://omarine.org/blog/how-to-create-a-patch-file/

Please add to this thread any tips and tricks you have, or point out any mistakes I made in the instructions.

μακάριοι οἱ δεδιωγμένοι ἕνεκεν δικαιοσύνης, ὅτι αὐτῶν ἐστιν ἡ βασιλεία τῶν οὐρανῶν.

User avatar
April
Posts: 493
Joined: Tue Dec 29, 2020 9:06 pm
Has thanked: 57 times
Been thanked: 28 times

Re: How to apply a .patch to source files

Post by April »

Usually I have found the repository has applied the patch and a new download is available as a zip file ,well on Github anyway .
I've never had to apply a patch separately?
Guess I'd better try and see what happens.

The Australian State Governments have all enacted laws to steal your assets on your death. All legal paperwork is binned and all assets seized on one disgruntled child's complaint.Move them well before you die or go into a home.

Post Reply

Return to “Utility”