An idiots guide to building Blender /W Patch please?

Eventually we all get to this point I guess where we just get tired of waiting for other people to provide a fresh Blender build with our desired patch for our specific OS and start building Blender on our own.

Now there are plenty of tutorials on how to build Blender from trunk in easy step-by-step guides and yes, that part is easy. However I have not found ONE SINGLE tutorial/guide/helpful tip on how to build Blender with a patch. The closest thing I have found is "Use ‘patch -p0 < patch_file.patch’ ", to the über-experienced super developer this might be so totally obvious that it’s not even worth mentioning but to the total newbie this says absolutely nothing at all.

Apparently all you have to do in Windows is to right-click the root svn directory and use “Apply patch” with tortoise svn. On Linux it doesn’t seem to be so simple. Where do I write it? Where do I apply the patch? When do I apply it, before or after “make”?

So, first thing’s first. I’m trying to build Blender on Linux. I’ve followed this guide and successfully built Blender both from latest svn and from an older source using Cmake. However this is where I am stuck. After some mucking around I figured that I should put the patch file in the root cmake directory and use "patch -p0 < ‘patch_file.patch’ " in the terminal from the root directory before I use “make”?

The errors I’ve encountered from doing that have ranged from

can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: release/scripts/startup/bl_ui/properties_data_lamp.py
|===================================================================
|--- release/scripts/startup/bl_ui/properties_data_lamp.py	(revision 57511)
|+++ release/scripts/startup/bl_ui/properties_data_lamp.py	(working copy)
--------------------------
File to patch:

to

svn: E155007: '/Desktop/BlenderTestBuild' is not a working copy

I’ve tried patching it using “patch -p0 < patch.patch”, “patch -i patch.patch” and “svn patch patch.patch” and I suppose they are different commands for different file types (.patch or .diff) but there’s no clear indication on what command to use for which filetype. I’ve tried to patch several different patches using both the latest revision of Blender and old releases. I managed to get one patch to patch the files one time (It said successfully patched a bunch of files) but then the “make” command failed to build Blender and since then I haven’t been able to patch it again, even using the same steps for the same patch from the same source in the same directory.

After 15 hours of trial and error I now give up and ask here. What am I doing wrong?

From what i have done using foo-bar command… patch or diff is a text file containing numbered edited code lines and there is a clue somewhere to what file it has these. ‘-’ is delete line; “+” - add this instead.
I got source file into text editor numbered… and used foo-bar (copy-paste). For sure takes less than 15 hrs when automation fails miserably because of source code being shifted by 1 or two lines (more than Fuzz asumes?).

If you apply patch to exact tree as patch created, no problem. But obviously you apply it to modified sourve tree (other version, other patch applyed before, some local changes you have done and maybe forgot, etc). This is very hard case. Some “smart” merging tools (meld, git auto merge, many other) pretend to use sophisticated algorithm and trying apply patch even if few lines changed. But there will be always cases when it fail, as you need real human who know what that changes mean.

So, you just must to know what that patch doing and apply it by hands revisiting every line. YOu MUST be a coder and know program to apply patch, no magic.

Thanks guys, I opened up the .patch file to see if I could modify the files manually and then I realized what I did wrong when I couldn’t find the files and folders it told me to modify. The problem was that I initially thought you should apply the patch in the “build” folder AFTER using cmake to build the files. I thought that this copied over the source code as well but obviously it doesn’t. You have to apply the patch on the source code before using cmake (which makes much more sense)

I still haven’t got Blender to build correctly after applying the patch but at least I can apply the patch now, thanks again :slight_smile:

Alright I’m back again with another question. I’ve since become quite adept at building Blender with patches that I can churn them out in a couple of minutes, however there’s one thing I still haven’t figured out.

How do I build Blender with static libraries so I can share my builds with other people? I’ve gone into the install_deps.sh file and enabled ALL_STATIC, I have re-downloaded all necessary libs and then tried to build Blender with cmake but every time I try to enable with_static_libs I get more errors than the terminal can display and Blender fails to build correctly. It builds fine if I just don’t enable static_libs in Cmake.