【背景】
折腾:
【记录】尝试为了Buildroot编译期间涉及到的m4-1.4.16的fpending在Cygwin下的问题去制作diff和patch补丁包
期间,希望用diff生成的patch文件的最开始可以添加对应的注释内容,就像之前看到的:
D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\buildroot-2013.05\package\m4\m4-1.4.16-no-gets.patch
中的这样的效果:
Since the 2.16 release of the glibc, 'gets' is not any more defined in the gnulib. No m4 version synchronized with gnulib since [1] has been released yet. This patch avoids the following error occurs when building m4 <=1.4.16 on host using a glibc >=2.16: make[4]: Entering directory `/opt/buildroot/output/build/host-m4-1.4.16/lib' /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT gl_avltree_oset.o -MD -MP -MF .deps/gl_avltree_oset.Tpo -c -o gl_avltree_oset.o gl_avltree_oset.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT c-ctype.o -MD -MP -MF .deps/c-ctype.Tpo -c -o c-ctype.o c-ctype.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT c-stack.o -MD -MP -MF .deps/c-stack.Tpo -c -o c-stack.o c-stack.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT clean-temp.o -MD -MP -MF .deps/clean-temp.Tpo -c -o clean-temp.o clean-temp.c mv -f .deps/c-ctype.Tpo .deps/c-ctype.Po /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT close-hook.o -MD -MP -MF .deps/close-hook.Tpo -c -o close-hook.o close-hook.c In file included from clean-temp.h:22:0, from clean-temp.c:23: ./stdio.h:477:20: error 'gets' undeclared here (not in a function) make[4]: *** [clean-temp.o] Error 1 References: [1] http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=66712c23388e93e5c518ebc8515140fa0c807348 [2] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/m4/files/m4-1.4.16-no-gets.patch?diff_format=h&revision=1.1&view=markup Signed-off-by: Samuel Martin <[email protected]> --- 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__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#endif #if @GNULIB_FOPEN@ # if @REPLACE_FOPEN@
【折腾过程】
1.觉得,给diff生成的patch中添加注释,应该是其参数中可以添加的。
结果针对diff的参数:
找了半天,也没找到有关加注释的参数。
2.后来找了半天,看到:
中的解释:
The format starts with the same two-line header as the context format, except that the original file is preceded by “---“ and the new file is preceded by “+++“. Following this are one or more change hunks that contain the line differences in the file. The unchanged, contextual lines are preceded by a space character, addition lines are preceded by a plus sign, and deletion lines are preceded by a minus sign. |
以及:
中的:
If the recipient is supposed to use the -pN option, do not send output that looks like this: diff -Naur v2.0.29/prog/README prog/README — v2.0.29/prog/README Mon Mar 10 15:13:12 1997 +++ prog/README Mon Mar 17 14:58:22 1997 because the two file names have different numbers of slashes, and different versions of patch interpret the file names differently. To avoid confusion, send output that looks like this instead: diff -Naur v2.0.29/prog/README v2.0.30/prog/README — v2.0.29/prog/README Mon Mar 10 15:13:12 1997 +++ v2.0.30/prog/README Mon Mar 17 14:58:22 1997 |
才意识到:
貌似,此处patch文件中的内容,在三个短横线:
—
之前的内容,都算是注释,即,之前看到的,第一行的:
diff -Naur v2.0.29/prog/README prog/README |
其实也是注释,也是patch语法中,所不识别,当做注释处理的。
3.所以:
貌似没有工具和(diff的)参数,可以给生成的patch添加注释的
如果想要实现开头的效果,则:
自己去手动,照葫芦画瓢,在patch最开始的部分,加上对应的内容即可。
即,从:
diff -purN -X - 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 2011-03-02 00:39:29.000000000 +0800 +++ host-m4-1.4.16/lib/stdio.in.h 2013-08-28 16:53:28.693212500 +0800 @@ -162,7 +162,11 @@ _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"); +#endif +#endif #if @GNULIB_FOPEN@ # if @REPLACE_FOPEN@
改为:
Since the 2.16 release of the glibc, 'gets' is not any more defined in the gnulib. No m4 version synchronized with gnulib since [1] has been released yet. This patch avoids the following error occurs when building m4 <=1.4.16 on host using a glibc >=2.16: make[4]: Entering directory `/opt/buildroot/output/build/host-m4-1.4.16/lib' /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT gl_avltree_oset.o -MD -MP -MF .deps/gl_avltree_oset.Tpo -c -o gl_avltree_oset.o gl_avltree_oset.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT c-ctype.o -MD -MP -MF .deps/c-ctype.Tpo -c -o c-ctype.o c-ctype.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT c-stack.o -MD -MP -MF .deps/c-stack.Tpo -c -o c-stack.o c-stack.c /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT clean-temp.o -MD -MP -MF .deps/clean-temp.Tpo -c -o clean-temp.o clean-temp.c mv -f .deps/c-ctype.Tpo .deps/c-ctype.Po /opt/buildroot/output/host/usr/bin/ccache /usr/bin/gcc -std=gnu99 -I. -O2 -I/opt/buildroot/output/host/include -I/opt/buildroot/output/host/usr/include -MT close-hook.o -MD -MP -MF .deps/close-hook.Tpo -c -o close-hook.o close-hook.c In file included from clean-temp.h:22:0, from clean-temp.c:23: ./stdio.h:477:20: error 'gets' undeclared here (not in a function) make[4]: *** [clean-temp.o] Error 1 References: [1] http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=66712c23388e93e5c518ebc8515140fa0c807348 [2] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/m4/files/m4-1.4.16-no-gets.patch?diff_format=h&revision=1.1&view=markup Signed-off-by: Samuel Martin <[email protected]> --- diff -purN -X - 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 2011-03-02 00:39:29.000000000 +0800 +++ host-m4-1.4.16/lib/stdio.in.h 2013-08-28 16:53:28.693212500 +0800 @@ -162,7 +162,11 @@ _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"); +#endif +#endif #if @GNULIB_FOPEN@ # if @REPLACE_FOPEN@
好像就可以了。
【总结】
至此,没有找到有工具和特殊diff的参数,可以给生成的patch文件加注释的。
好像只需要手动去给patch文件,最开始部分,一般都是—之前的行,加上自己所需要的注释即可。
即,从:
diff -purN -xxx xxx --- xxxx +++ xxxx
改为:
add anything you want ... ... diff -purN -xxx xxx --- xxxx +++ xxxx
即可。
转载请注明:在路上 » 【基本解决】给diff生成的patch文件添加注释