Difference between revisions of "Patching"

From NetHackWiki
Jump to navigation Jump to search
m (nowadays menucolors-patch support windows GUI version too.)
m (Add man page link)
 
(12 intermediate revisions by 9 users not shown)
Line 1: Line 1:
Here is a short guide on '''Patching''' your NetHack sources. Assuming you have already managed to [[compiling|compile]] your copy.
+
{{man|patch}}
 +
Here is a short guide on '''patching''' your NetHack sources, assuming you have already managed to [[compiling|compile]] your copy.
  
 
==On Windows==
 
==On Windows==
  
Please see the article on [[compiling]], the following assumes you have installed MinGW and NetHack's sources to the locations shown in that article.
+
This assumes you have a basic knowledge of [[compiling]] and similar.
  
*Download the patch binary zip package from http://gnuwin32.sourceforge.net/packages/patch.htm
+
*Download the patch binary zip package from http://gnuwin32.sourceforge.net/packages/patch.htm, and unpack that into the bin directory of MinGW, so that the patch.exe will be in the same directory as mingw32-make.exe (e.g. c:\mingw\bin).
 
 
*Unpack that into the same directory as MinGW, so that the patch.exe will be in the same place as mingw32-make.
 
  
 
*Find the diff-file you want to patch, and download it on to your computer, preferably in the NetHack sources root directory, <tt>c:\nh343</tt>.
 
*Find the diff-file you want to patch, and download it on to your computer, preferably in the NetHack sources root directory, <tt>c:\nh343</tt>.
Note that linux-style line endings will cause problems, you need to convert those into Windows-style ones! You can do this for example copypasting the contents of that file from a browser window into Notepad, and then saving the notepad file.
+
Note that linux-style line endings will cause problems, you need to convert those into Windows-style ones! You can do this for example copypasting the contents of that file from a browser window into Notepad, and then saving the notepad file. The following code assumes the patch is [[Menucolors]], so to use any other patch just replace <code>nh343-menucolor.diff</code> with the filename of the patch.
In this example, we'll be using the [[menucolors]]-patch available at http://bilious.homelinux.org/~paxed/nethack/nh343-menucolor.diff
 
We'll assume the file is saved in <tt>c:\nh343\</tt> as <tt>nh343-menucolor.diff</tt>
 
  
 
*Start <tt>cmd.exe</tt> and do the following:
 
*Start <tt>cmd.exe</tt> and do the following:
 
  cd c:\nh343
 
  cd c:\nh343
  path=c:\mingw\bin
+
  path=%path%;c:\mingw\bin
 
  patch -p1 < nh343-menucolor.diff
 
  patch -p1 < nh343-menucolor.diff
 +
  
 
The <tt>1</tt> after the <tt>-p</tt> might need to be changed to <tt>0</tt> or possibly <tt>2</tt> for other patches.
 
The <tt>1</tt> after the <tt>-p</tt> might need to be changed to <tt>0</tt> or possibly <tt>2</tt> for other patches.
  
note: On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given.  
+
note: On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given.
 
 
*Some patches require extra configuration steps before compiling. For [[menucolors]], you need to edit <tt>c:\nh343\include\config.h</tt> by changing the line
 
# define MENU_COLOR_REGEX
 
to
 
/* # define MENU_COLOR_REGEX */
 
This changes the menucolors, so it won't try to use regular expressions, because MinGW does not come with regex header files. Menucolors also comes with it's own short README file, which should be <tt>c:\nh343\README.menucolor</tt>
 
 
 
*Compile NetHack, by running <tt>install.bat</tt> (Assuming you created one when [[compiling]] the source) or manually.
 
 
 
*Add the following to your NetHack configuration file, so the menucolors actually does something:
 
OPTIONS=menucolors
 
MENUCOLOR="* blessed *"=green
 
MENUCOLOR="* holy *"=green
 
MENUCOLOR="* cursed *"=red
 
MENUCOLOR="* unholy *"=red
 
 
 
*Start NetHack. Now all blessed and holy items in your inventory should be shown in green, cursed and unholy in red.
 
 
 
=== Regexp on Windows ===
 
 
 
If you want to use regular expressions for menucolors:
 
  
*Download the binary and developer packages from http://gnuwin32.sourceforge.net/packages/pcre.htm
+
note: Newer version of windows require administrative privileges to run files named patch, which can break GNU patch, see here for a workaround: http://jameswynn.com/2010/03/gnu-patch-in-windows-7-or-vista/
  
*Edit <tt>src\Makefile.gcc</tt> and add <tt>-lpcre</tt> to WINPLIBS. There's two definitions of WINPLIBS, one is for TTY, the other for graphical GUI.
+
==Linux, and Unix in general==
  
*Uncomment the <tt>MENU_COLOR</tt>, <tt>MENU_COLOR_REGEX</tt> and <tt>MENU_COLOR_REGEX_POSIX</tt> defines in <tt>include\config.h</tt>.
+
The typical way to patch is to stand in the root directory of the nethack source tree, apply the patch:
 +
patch -p''num'' < ''my.patch''
 +
and then examine the warning or error messages, if any.
  
*Unpack the PCRE development package and copy <tt>libpcre.dll.a</tt> to <tt>c:\mingw\lib\</tt> and <tt>pcre.h</tt>, <tt>pcreposix.h</tt> and <tt>regex.h</tt> to <tt>c:\mingw\include\</tt>
+
"-p''num''" is used to strip path prefixes from the patch before trying to apply it.
 +
For example, if the patch contains lines on the form:
  
*Run <tt>install.bat</tt> to compile NetHack.
+
--- slashem-0.0.7E7F1-orig/dat/Jedi.des 1970-01-01 01:00:00.000000000 +0100
 +
+++ slashem-0.0.7E7F1/dat/Jedi.des      2005-07-20 14:55:01.434612456 +0200
  
*Unpack the PCRE binary package and copy <tt>pcre3.dll</tt> into the directory where NetHack binary is. (<tt>c:\nh343\binary\</tt>)
+
you should strip off one level. You should strip off two levels if the patch says:
  
*You can now use regular expressions for menucolors, for an example see http://alt.org/nethack/rcfiles/Eidolos.nethackrc or put the following in your configuration file:
+
--- a/slashem/dat/Jedi.des 1970-01-01 01:00:00.000000000 +0100
OPTIONS=menucolors
+
+++ b/slashem/dat/Jedi.des 2005-07-20 14:55:01.434612456 +0200
MENUCOLOR=" blessed "=green
 
MENUCOLOR=" holy "=green
 
MENUCOLOR=" cursed "=red
 
MENUCOLOR=" unholy "=red
 
  
 
[[Category:Development]]
 
[[Category:Development]]

Latest revision as of 04:20, 20 March 2020

Here is a short guide on patching your NetHack sources, assuming you have already managed to compile your copy.

On Windows

This assumes you have a basic knowledge of compiling and similar.

  • Find the diff-file you want to patch, and download it on to your computer, preferably in the NetHack sources root directory, c:\nh343.

Note that linux-style line endings will cause problems, you need to convert those into Windows-style ones! You can do this for example copypasting the contents of that file from a browser window into Notepad, and then saving the notepad file. The following code assumes the patch is Menucolors, so to use any other patch just replace nh343-menucolor.diff with the filename of the patch.

  • Start cmd.exe and do the following:
cd c:\nh343
path=%path%;c:\mingw\bin
patch -p1 < nh343-menucolor.diff


The 1 after the -p might need to be changed to 0 or possibly 2 for other patches.

note: On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given.

note: Newer version of windows require administrative privileges to run files named patch, which can break GNU patch, see here for a workaround: http://jameswynn.com/2010/03/gnu-patch-in-windows-7-or-vista/

Linux, and Unix in general

The typical way to patch is to stand in the root directory of the nethack source tree, apply the patch:

patch -pnum < my.patch

and then examine the warning or error messages, if any.

"-pnum" is used to strip path prefixes from the patch before trying to apply it. For example, if the patch contains lines on the form:

--- slashem-0.0.7E7F1-orig/dat/Jedi.des 1970-01-01 01:00:00.000000000 +0100
+++ slashem-0.0.7E7F1/dat/Jedi.des      2005-07-20 14:55:01.434612456 +0200

you should strip off one level. You should strip off two levels if the patch says:

--- a/slashem/dat/Jedi.des 1970-01-01 01:00:00.000000000 +0100
+++ b/slashem/dat/Jedi.des 2005-07-20 14:55:01.434612456 +0200