【记录】尝试为了Buildroot编译期间涉及到的m4-1.4.16的fpending在Cygwin下的问题去制作diff和patch补丁包

【背景】

折腾:

【已解决】Cygwin下make编译Buildroot期间编译m4-1.4.16出错:/usr/include/stdio_ext.h:47:1: note: previous definition of ‘__fpending’ was here

期间,cygwin下编译buildroot,发现问题好像是在于m4中有关fpending的问题。

然后也基本确定,别人:

Re: fpending in cygwin

所给出的patch,应该是可以解决问题的。

但是其,好像是,针对于1.7.11.7的m4的,而我此处是m4-1.4.16,所以,需要重新制作补丁包。

并且,由于改动的内容,涉及到configure之前的检测环境变量等问题,所以需要制作补丁包,否则直接改动相关的.h和.c文件,也就算了。

【折腾过程】

1.先找到现在的源码,是buildroot所已经下载好的m4-1.4.16.tar.bz2:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/dl
$ pwd
/home/CLi/develop/buildroot/buildroot-2013.05/dl

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/dl
$ ls -lha
total 3.6M
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 27 18:30 ./
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 28 12:42 ../
-rw-r--r--  1 CLi Domänen-Benutzer 260K Aug 11  2012 ccache-3.1.8.tar.bz2
-rw-r--r--  1 CLi Domänen-Benutzer 2.2M May  1 09:03 gmp-5.1.1.tar.bz2
-rw-r--r--  1 CLi Domänen-Benutzer 1.3M Mar  2  2011 m4-1.4.16.tar.bz2

2.解压出来一份,改名为.orig,再弄一份,留自己修改:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/dl
$ cd /home/CLi/develop/buildroot/

CLi@PC-CLI-1 ~/develop/buildroot
$ ls
buildroot-2013.05/  buildroot-2013.05.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot
$ mkdir diff_patch

CLi@PC-CLI-1 ~/develop/buildroot
$ cd diff_patch/

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ cp /home/CLi/develop/buildroot/buildroot-2013.05/dl/m4-1.4.16.tar.bz2 .

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls
m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls -lha
total 1.3M
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 28 13:20 ./
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 28 13:19 ../
-rw-r--r--  1 CLi Domänen-Benutzer 1.3M Aug 28 13:20 m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ tar xfj m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ mv m4-1.4.16
m4-1.4.16/         m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ mv m4-1.4.16/ m4-1.4.16.orig/

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ tar xfj m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls -lha
total 1.3M
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 28 13:20 ./
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Aug 28 13:19 ../
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Mar  2  2011 m4-1.4.16/
drwxr-xr-x+ 1 CLi Domänen-Benutzer    0 Mar  2  2011 m4-1.4.16.orig/
-rw-r--r--  1 CLi Domänen-Benutzer 1.3M Aug 28 13:20 m4-1.4.16.tar.bz2

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$

3.然后就可以去试着,参考:

Re: fpending in cygwin

去改动代码了。

4.先去修改

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\diff_patch\m4-1.4.16\ChangeLog

加上:

2013-08-28  Crifan Li <admin@crifan.com>

	maint: merge Paul Eggert's bugfix for v1.7.11.7 to current version
	* fpending: http://lists.gnu.org/archive/html/bug-gnulib/2013-08/msg00030.html

5.再去修改:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\diff_patch\m4-1.4.16\lib\fpending.h

为:

#include <stddef.h>
#include <stdio.h>
#if HAVE_STDIO_EXT_H
# include <stdio_ext.h>
#endif

#ifndef __fpending
size_t __fpending (FILE *);
#endif

其中,关于:

#ifndef HAVE_DECL___FPENDING
"this configure-time declaration test was not run"
#endif

的内容,参考之前的:

Re: [PATCH] maint.mk: new syntax check for HAVE_DECL checks

感觉是被m4的1.4.16之后的某个版本,更新后,去掉了。

所以此处也去掉。

 

6.再去修改:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\diff_patch\m4-1.4.16\m4\fpending.m4

改为:

AC_DEFUN([gl_FUNC_FPENDING],
[
  AC_CHECK_HEADERS_ONCE([stdio_ext.h])
  AC_CACHE_CHECK([for __fpending], [gl_cv_func___fpending],
    [
      AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <stdio.h>
             #if HAVE_STDIO_EXT_H
             # include <stdio_ext.h>
             #endif
           ]],
           [[return ! __fpending (stdin);]])],
        [gl_cv_func___fpending=yes],
        [gl_cv_func___fpending=no]
      )
    ]
  )
]

感觉中括号和圆括号,貌似都不是很匹配。。。。

先这么改着再说吧,看看是否有用。

7.然后,再去尝试制作patch:

参考:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\buildroot-2013.05\package\m4\m4-1.4.16-no-gets.patch

去用diff的purN三个参数,所以先去看看参数的含义:

【整理】Linux命令:diff用法和参数含义

 

8.然后就可以去试试,用diff制作patch了。

参考之前自己的帖子:

【diff和patch的使用】+【软件开发常用方法】

去执行:

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ diff -purN m4-1.4.16.orig/ m4-1.4.16/ > m4-1.4.16-fpending.patch

9.然后看看生成的patch文件内容,结果如下:

diff -purN m4-1.4.16.orig/ChangeLog m4-1.4.16/ChangeLog
--- m4-1.4.16.orig/ChangeLog	2011-03-02 02:39:40.000000000 +0800
+++ m4-1.4.16/ChangeLog	2013-08-28 13:25:09.128914000 +0800
@@ -1,3 +1,8 @@
+2013-08-28  Crifan Li <admin@crifan.com>
+
+	maint: merge Paul Eggert's bugfix for v1.7.11.7 to current version
+	* fpending: http://lists.gnu.org/archive/html/bug-gnulib/2013-08/msg00030.html
+
 2011-03-01  Eric Blake  <eblake@redhat.com>
 
 	Release Version 1.4.16.
diff -purN m4-1.4.16.orig/lib/fpending.h m4-1.4.16/lib/fpending.h
--- m4-1.4.16.orig/lib/fpending.h	2011-03-02 00:39:27.000000000 +0800
+++ m4-1.4.16/lib/fpending.h	2013-08-28 13:26:14.216914000 +0800
@@ -20,15 +20,10 @@
 
 #include <stddef.h>
 #include <stdio.h>
-
-#ifndef HAVE_DECL___FPENDING
-"this configure-time declaration test was not run"
+#if HAVE_STDIO_EXT_H
+# include <stdio_ext.h>
 #endif
 
-#if HAVE_DECL___FPENDING
-# if HAVE_STDIO_EXT_H
-#  include <stdio_ext.h>
-# endif
-#else
+#ifndef __fpending
 size_t __fpending (FILE *);
 #endif
diff -purN m4-1.4.16.orig/m4/fpending.m4 m4-1.4.16/m4/fpending.m4
--- m4-1.4.16.orig/m4/fpending.m4	2011-03-02 00:39:30.000000000 +0800
+++ m4-1.4.16/m4/fpending.m4	2013-08-28 13:38:21.583265900 +0800
@@ -16,68 +16,19 @@ dnl we have to grub around in the FILE s
 AC_DEFUN([gl_FUNC_FPENDING],
 [
   AC_CHECK_HEADERS_ONCE([stdio_ext.h])
-  AC_CHECK_FUNCS_ONCE([__fpending])
-  fp_headers='
-#     include <stdio.h>
-#     if HAVE_STDIO_EXT_H
-#      include <stdio_ext.h>
-#     endif
-'
-  AC_CHECK_DECLS([__fpending], , , $fp_headers)
-  if test $ac_cv_func___fpending = no; then
-    AC_CACHE_CHECK(
-              [how to determine the number of pending output bytes on a stream],
-                   ac_cv_sys_pending_output_n_bytes,
-      [
-        for ac_expr in                                                    \
-                                                                          \
-            '# glibc2'                                                    \
-            'fp->_IO_write_ptr - fp->_IO_write_base'                      \
-                                                                          \
-            '# traditional Unix'                                          \
-            'fp->_ptr - fp->_base'                                        \
-                                                                          \
-            '# BSD'                                                       \
-            'fp->_p - fp->_bf._base'                                      \
-                                                                          \
-            '# SCO, Unixware'                                             \
-            '(fp->__ptr ? fp->__ptr - fp->__base : 0)'                    \
-                                                                          \
-            '# QNX'                                                       \
-            '(fp->_Mode & 0x2000 /*_MWRITE*/ ? fp->_Next - fp->_Buf : 0)' \
-                                                                          \
-            '# old glibc?'                                                \
-            'fp->__bufp - fp->__buffer'                                   \
-                                                                          \
-            '# old glibc iostream?'                                       \
-            'fp->_pptr - fp->_pbase'                                      \
-                                                                          \
-            '# emx+gcc'                                                   \
-            'fp->_ptr - fp->_buffer'                                      \
-                                                                          \
-            '# VMS'                                                       \
-            '(*fp)->_ptr - (*fp)->_base'                                  \
-                                                                          \
-            '# e.g., DGUX R4.11; the info is not available'               \
-            1                                                             \
-            ; do
-
-          # Skip each embedded comment.
-          case "$ac_expr" in '#'*) continue;; esac
-
-          AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
-            [[FILE *fp = stdin; (void) ($ac_expr);]])],
-            [fp_done=yes]
-          )
-          test "$fp_done" = yes && break
-        done
-
-        ac_cv_sys_pending_output_n_bytes=$ac_expr
-      ]
-    )
-    AC_DEFINE_UNQUOTED([PENDING_OUTPUT_N_BYTES],
-      $ac_cv_sys_pending_output_n_bytes,
-      [the number of pending output bytes on stream `fp'])
-    AC_LIBOBJ([fpending])
-  fi
-])
+  AC_CACHE_CHECK([for __fpending], [gl_cv_func___fpending],
+    [
+      AC_LINK_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#include <stdio.h>
+             #if HAVE_STDIO_EXT_H
+             # include <stdio_ext.h>
+             #endif
+           ]],
+           [[return ! __fpending (stdin);]])],
+        [gl_cv_func___fpending=yes],
+        [gl_cv_func___fpending=no]
+      )
+    ]
+  )
+]

即使之后没解决此问题,也算是再次属性diff的用法了,哈哈。

10.然后,针对此patch文件,要回到:

【已解决】Cygwin下make编译Buildroot期间编译m4-1.4.16出错:/usr/include/stdio_ext.h:47:1: note: previous definition of ‘__fpending’ was here

看看,如何添加到Buildroot中的逻辑中去,使得其可以自动打上此patch。

11.又改了一个版本,然后再重新制作一个patch:

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ diff -purN m4-1.4.16.orig/ m4-1.4.16/ > m4-1.4.16-no-fpending-redefinition.patch

12.折腾:

【已解决】打补丁时出错:Patch failed!  Please fix m4-1.4.16-no-fpending-redefinition.patch!

期间,需要重新制作一个新patch,所以去:

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ mv m4-1.4.16/ host-m4-1.4.16/

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ mv m4-1.4.16.orig/ host-m4-1.4.16.orig/
mv: cannot move `m4-1.4.16.orig/' to `host-m4-1.4.16.orig/': Permission denied

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls -lha
total 1.3M
drwxr-xr-x+ 1 CLi            Domänen-Benutzer    0 Aug 28 16:03 ./
drwxr-xr-x+ 1 CLi            Domänen-Benutzer    0 Aug 28 13:19 ../
-rwxr-xr-x  1 Administrators Domänen-Benutzer 4.2K Aug 28 14:29 fpending.m4*
drwxr-xr-x+ 1 CLi            Domänen-Benutzer    0 Aug 28 13:51 host-m4-1.4.16/
drwxr-xr-x+ 1 CLi            Domänen-Benutzer    0 Mar  2  2011 m4-1.4.16.orig/
-rw-r--r--  1 CLi            Domänen-Benutzer 1.3M Aug 28 13:20 m4-1.4.16.tar.bz2
-rw-r--r--  1 CLi            Domänen-Benutzer 5.1K Aug 28 13:51 m4-1.4.16-fpending.patch
-rw-r--r--  1 CLi            Domänen-Benutzer 9.1K Aug 28 14:38 m4-1.4.16-no-fpending-redefinition.patch

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ ls m4-1.4.16.orig/
acinclude.m4  AUTHORS  bootstrap*  c-boxes.el  ChangeLog  configure*    COPYING  examples/    INSTALL  m4/       Makefile.am  NEWS    src/    THANKS
aclocal.m4    BACKLOG  build-aux/  cfg.mk      checks/    configure.ac  doc/     GNUmakefile  lib/     maint.mk  Makefile.in  README  tests/  TODO

很明显,竟然出现奇怪的权限错误。

然后发现,实际上是当前在win7下,正在打开此cygwin下面的路径:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\diff_patch\m4-1.4.16.orig\lib

所以,人家不允许你修改。

所以,win7下切换到:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\diff_patch

自然就可以了:

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ mv m4-1.4.16.orig/ host-m4-1.4.16.orig/

再去制作patch:

CLi@PC-CLI-1 ~/develop/buildroot/diff_patch
$ diff -purN host-m4-1.4.16.orig/ host-m4-1.4.16/ > m4-1.4.16-no-__fpending-redefine.patch

如图:

use diff can generate patch for old and new

13.折腾:

【已解决】patch打补丁时出错:patch: **** malformed patch at line

期间,需要制作:

带注释的,针对于

host-m4-1.4.16/lib/stdio.in.h

的改动的,新的patch文件:

其内容,是类似于:

---
diff -purN host-m4-1.4.16.orig/lib/stdio.in.h host-m4-1.4.16/lib/stdio.in.h
--- host-m4-1.4.16.orig/lib/stdio.in.h	2012-07-21 19:11:40.196541826 +0200
+++ host-m4-1.4.16/lib/stdio.in.h	2012-07-21 20:46:05.405850751 +0200
@@ -162,7 +162,9 @@ _GL_WARN_ON_USE (fflush, "fflush is not
    so any use of gets warrants an unconditional warning.  Assume it is
    always declared, since it is required by C89.  */
 #undef gets
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#if !((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#endif
 
 #if @GNULIB_FOPEN@
 # if @REPLACE_FOPEN@

的。

此处,由于之前已经针对host-m4-1.4.16有其他的文件改动了,所以,此处还面临一个问题:

如何只针对某些子文件(或文件夹)制作特定的patch:

【已解决】用diff制作patch时,如何只针对特定文件或文件夹

14.然后再去考虑,给diff打patch时,添加对应的注释:

【基本解决】给diff生成的patch文件添加注释

 

【总结】

至此,基本上,实现了,所有的,相关的,制作patch的过程,达到了目标,可以使得Buildroot可以继续正常编译了。

此处,针对于一般情况:

当然文件夹下,已有了对应的两个文件夹了:

  • host-m4-1.4.16:包含了你的新的改动的文件夹
  • host-m4-1.4.16.orig:包含原始的内容(从原始的tar解压的,没动过)

然后去制作patch文件的话,用:

diff -purN host-m4-1.4.16.orig/ host-m4-1.4.16/ > m4-1.4.16-no-__fpending-redefine.patch

即可生成对应的patch文件:

m4-1.4.16-no-__fpending-redefine.patch

了。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量