Difference between revisions of "Patching"

From NetHackWiki
Jump to navigation Jump to search
(todo)
(patching on Linux)
Line 1: Line 1:
 
Here is a short guide on '''patching''' your NetHack sources, assuming you have already managed to [[compiling|compile]] your copy.
 
Here is a short guide on '''patching''' your NetHack sources, assuming you have already managed to [[compiling|compile]] your copy.
 
{{todo|include a short note on patching on unix-derived systems (and also perhaps for OSX}}
 
  
 
==On Windows==
 
==On Windows==
Line 66: Line 64:
 
  MENUCOLOR=" cursed "=red
 
  MENUCOLOR=" cursed "=red
 
  MENUCOLOR=" unholy "=red
 
  MENUCOLOR=" unholy "=red
 +
 +
==Linux==
 +
 +
In general the command for patching is:
 +
patch -pnum < my.patch
 +
 +
"-pnum" Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch.
 +
 +
For example, supposing the file name in the patch file was:
 +
 +
/u/howard/src/blurfl/blurfl.c
 +
 +
*setting -p0 gives the entire file name unmodified. Meaning:
 +
 +
/u/howard/src/blurfl/blurfl.c
 +
 +
*-p1 removes the leading slash:
 +
 +
u/howard/src/blurfl/blurfl.c
 +
 +
*-p4 gives the truncated:
 +
 +
blurfl/blurfl.c
 +
 +
*and not specifying -p at all just gives you
 +
 +
blurfl.c
 +
 +
===Example===
 +
 +
For the Jedi patch[http://www.benjamin-schieder.de/downloads/slashem/slashem_jedi_0.5.patch]. You'll need these sources[http://sourceforge.net/projects/slashem/files/slashem-source/0.0.7E7F1/se007e7f1.tar.gz/download]. Uncompress the sources.
 +
 +
The patch expect to find the "slashem-0.0.7E7F1-orig" directory.
 +
 +
*You can either enter the "slashem-0.0.7E7F1" directory and run the command:
 +
patch -p2 < slashem_jedi_0.5.patch
 +
 +
 +
*Or rename the "slashem-0.0.7E7F1" folder in to "slashem-0.0.7E7F1-orig" and then run:
 +
patch -p0 < slashem_jedi_0.5.patch
 +
 +
If done correctly, it will not complain. After that, you can compile it the usual way.
 +
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 08:15, 22 June 2015

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

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.

  • 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).
  • 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. In this example, we'll be using the menucolors-patch available at http://bilious.alt.org/~paxed/nethack/nh343-menucolor.diff We'll assume the file is saved in c:\nh343\ as nh343-menucolor.diff

  • 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/

  • Some patches require extra configuration steps before compiling. For menucolors, you need to edit c:\nh343\include\config.h 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 c:\nh343\README.menucolor

  • Compile NetHack, by running install.bat (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:

  • Edit src\Makefile.gcc and add -lpcre to WINPLIBS. There's two definitions of WINPLIBS, one is for TTY, the other for graphical GUI.
  • Uncomment the MENU_COLOR, MENU_COLOR_REGEX and MENU_COLOR_REGEX_POSIX defines in include\config.h.
  • Unpack the PCRE development package and copy libpcre.dll.a to c:\mingw\lib\ and pcre.h, pcreposix.h and regex.h to c:\mingw\include\
  • Run install.bat to compile NetHack.
  • Unpack the PCRE binary package and copy pcre3.dll into the directory where NetHack binary is. (c:\nh343\binary\)
OPTIONS=menucolors
MENUCOLOR=" blessed "=green
MENUCOLOR=" holy "=green
MENUCOLOR=" cursed "=red
MENUCOLOR=" unholy "=red

Linux

In general the command for patching is:

patch -pnum < my.patch

"-pnum" Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch.

For example, supposing the file name in the patch file was:

/u/howard/src/blurfl/blurfl.c
  • setting -p0 gives the entire file name unmodified. Meaning:
/u/howard/src/blurfl/blurfl.c
  • -p1 removes the leading slash:
u/howard/src/blurfl/blurfl.c
  • -p4 gives the truncated:
blurfl/blurfl.c
  • and not specifying -p at all just gives you
blurfl.c

Example

For the Jedi patch[1]. You'll need these sources[2]. Uncompress the sources.

The patch expect to find the "slashem-0.0.7E7F1-orig" directory.

  • You can either enter the "slashem-0.0.7E7F1" directory and run the command:
patch -p2 < slashem_jedi_0.5.patch


  • Or rename the "slashem-0.0.7E7F1" folder in to "slashem-0.0.7E7F1-orig" and then run:
patch -p0 < slashem_jedi_0.5.patch

If done correctly, it will not complain. After that, you can compile it the usual way.