bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] Building on mingw


From: Martin Panter
Subject: [bug-patch] Building on mingw
Date: Sun, 17 May 2009 06:20:51 +0000

I've just successfully built the alpha release from

ftp://alpha.gnu.org/gnu/patch/patch-2.5.9-109-g70df4e4.tar.gz

but there were a few issues to sort out. At least the first few of
these I think you might want to fix in the code.

1. The gnulib getopt stuff seemed to be missing getopt_int.h. I seem
to have fixed this by copying the file straight from gnulib.

2. Also in the gnulib stuff, the xstrndup function needs strndup, but
I don't think this is present on Windows. I just made the code use
strdup and truncate the string, but perhaps you can get a better
strndup from gnulib?

3. The makefile seemed to want getopt.h to exist in the current
directory. If I supplied GETOPT_H=gl/lib/getopt.h it fixed the
problem.

4. You can't assign stderr into stdout! I guess it works with the gnu
C library but apparently not with other C libraries. I just removed
the assignment to get it to compile, because I'm not interested in
patched output going to stdout for the moment. But I guess the proper
fix would be to set a variable somewhere to either stdout or stderr,
and change all the message printouts to use it rather than blindly use
stdout.

5. The "rename" function in Mingw, which uses an MS C runtime library,
doesn't work if the destination file already exists, so I added
"remove (target)" calls before it. This is a special Win32 only
workaround though. Perhaps it would be appropriate to use the "rename"
stuff out of the gnulib?

I also made some changes (in patch-seekable.diff attached) to avoid
problems with reading LF newline files in Windows text mode (CRLF). My
change always copies the patch file into a regular seekable binary
file if the "binary" option is enabled but HAVE_SETMODE_DOS is set.
(Personally I would prefer to have the "binary" option turned on by
default to avoid surprise line ending changes.)

As a side effect I think this change will make things like patching
from a FIFO work (with "-i" option). I checked on Ubuntu Linux and
this currently fails:

address@hidden:~$ patch --version
patch 2.5.9
. . .
address@hidden:~$ mkfifo fifo
address@hidden:~$ cp diff fifo &
[1] 17604
address@hidden:~$ patch -p0 --dry-run -i fifo
patch: **** fseek : Illegal seek

It seems to be working for me well now. In "binary" mode, the diff
file has to have the correct line endings (personally

Here are roughly the steps I went through to build it on Windows:

=== 2.5.9-109-g70df4e4

wget ftp://alpha.gnu.org/gnu/patch/patch-2.5.9-109-g70df4e4.tar.gz -O - |
tar xz
cd patch-2.5.9-109-g70df4e4
wget --content-disposition -P gl/lib \
    
"http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=lib/getopt_int.h;hb=9d17a13747f2286970948f17d8e22a81326ae023";
patch -p0 <<DIFF
--- gl/lib/xstrndup.c   2009-05-16 10:14:26 +0000
+++ gl/lib/xstrndup.c   2009-05-16 10:14:24 +0000
@@ -29,8 +29,9 @@
 char *
 xstrndup (const char *string, size_t n)
 {
-  char *s = strndup (string, n);
+  char *s = strdup (string);
   if (! s)
     xalloc_die ();
+  s[n] = 0;
   return s;
 }
--- src/patch.c 2009-05-16 09:44:46 +0000
+++ src/patch.c 2009-05-16 09:44:44 +0000
@@ -1348,7 +1348,6 @@
   else
     {
       outstate->ofp = stdout;
-      stdout = stderr;
     }

   outstate->after_newline = true;
--- src/util.c  2009-05-16 12:53:22 +0000
+++ src/util.c  2009-05-16 12:53:18 +0000
@@ -232,6 +232,8 @@
          if (debug & 4)
            say ("Renaming file %s to %s\n",
                 quotearg_n (0, to), quotearg_n (1, bakname));
+       
+         remove (bakname);
          while (rename (to, bakname) != 0)
            {
              if (errno == try_makedirs_errno)
@@ -282,6 +284,7 @@
        say ("Renaming file %s to %s\n",
             quotearg_n (0, from), quotearg_n (1, to));

+      remove (to);
       if (rename (from, to) != 0)
        {
          bool to_dir_known_to_exist = false;
DIFF
patch -p1 < ../patch-seekable.diff
./configure
make GETOPT_H=gl/lib/getopt.h
cp src/patch.exe "$BIN"
strip "$BIN/patch.exe"

Attachment: patch-seekable.diff.txt
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]