-
Notifications
You must be signed in to change notification settings - Fork 6
/
grep-3.11-build-patch-howto.txt
208 lines (166 loc) · 8.16 KB
/
grep-3.11-build-patch-howto.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
Instructions how to build native Gnu grep.exe with Microsoft Visual Studio (or Build Tools for Visual Studio) from CYGWIN shell.
While building, it is possible to save build log and create a patch - for compiling Gnu grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN.
This is how grep-3.11-build-VS22-x64.patch and grep-3.11-build-VS22-x86.patch were created.
First, build pcre2.a and pcre2posix.a libraries - see pcre2/pcre2-10.42-build.txt
Second, in the directory containing ./pcre2-pcre2-10.42, build Gnu Grep with PCRE support.
From CYGWIN shell:
1) get archive:
wget https://ftp.gnu.org/gnu/grep/grep-3.11.tar.xz
2) unpack archive:
tar xf grep-3.11.tar.xz
3) go to grep sources:
cd grep-3.11
4) fix sources for windows:
patch -Np1 -i grep-3.11-src.patch
(patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.11-src.patch)
5) now start dos prompt:
cmd.exe /c start cmd.exe
6) setup compiler:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64
(if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)")
--tip: to build 32-bit version of the Gnu Grep utility, specify "x86" instead of "amd64"
7) run bash from dos prompt (with environment prepared for compiling with Microsoft Build Tools for Visual Studio 2022):
bash
8) check that Gnu Make is installed in CYGWIN and it is working (Gnu Make is required for the build):
make --version
9) configure grep (assuming pcre2 library was built at ../pcre2-pcre2-10.42):
CFLAGS= CC=cl CPP="cl /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.42/src" PCRE_LIBS=../../pcre2-pcre2-10.42/pcre2.a ./configure --host=mingw64 --disable-dependency-tracking --disable-silent-rules --disable-nls pcre_cv_have_pcre2_compile=yes
--tip: when building 32-bit version of the Gnu Grep utility, add "/D_WIN32_WINNT=0x501" compiler switch:
CFLAGS= CC="cl /D_WIN32_WINNT=0x501" CPP="cl /D_WIN32_WINNT=0x501 /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.42/src" PCRE_LIBS=../../pcre2-pcre2-10.42/pcre2.a ./configure --host=mingw32 --disable-dependency-tracking --disable-silent-rules --disable-nls pcre_cv_have_pcre2_compile=yes
10) configure script is not fully functional to create correct Makefiles for Visual Studio - they are need to be fixed manually:
sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile
sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile
sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile
sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile
sed -i '/$(libgreputils_a_AR)/s/ lib/lib/' ./lib/Makefile
11) fix linker command:
sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE /OUT:$@%' ./src/Makefile
--tip: when building 32-bit version of the Gnu Grep utility, specify "/SUBSYSTEM:CONSOLE,5.01" linker switch:
sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE,5.01 /OUT:$@%' ./src/Makefile
12) add gen target:
echo 'gen:' >> ./Makefile
echo 'gen:' >> ./src/Makefile
echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile
echo 'gen-am:' >> ./Makefile
13) execute Makefile to generate grep headers:
make gen
14) fix generated headers:
a) header file lib/unistd.h is generated erroneously, fix it:
patch -Np1 -i grep-3.11-unistd.patch
(patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.11-unistd.patch)
b) fix build for the native Windows platform:
patch -Np1 -i grep-3.8-mbtowc-lock.patch
(patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-mbtowc-lock.patch)
15) do compile grep:
make > make.bat
16) check build result:
./src/grep.exe --version
(should print grep version, e.g.: (GNU grep) 3.11)
compilation should be ok, native (unoptimized) ./src/grep.exe should be created.
Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN.
1) create directory for unpatched grep:
mkdir ../orig
2) unpack grep:
tar xf ../grep-3.11.tar.xz -C ../orig/
3) diff current directory with original just unpacked grep-3.11.tar.xz in the '../orig' directory
diff -rql . ../orig/grep-3.11
4) remove unneeded built files in the current directory (object files, libs, etc...)
rm -rv \
./Makefile \
./stamp-h1 \
./src/*.obj \
./lib/*.obj \
./lib/glthread/*.obj \
./lib/glthread/.deps \
./lib/glthread/.dirstamp \
./lib/unistr/*.obj \
./lib/unistr/.deps \
./lib/unistr/.dirstamp \
./lib/uniwidth/*.obj \
./lib/uniwidth/.deps \
./lib/uniwidth/.dirstamp \
./lib/malloc/*.obj \
./lib/malloc/.deps \
./lib/malloc/.dirstamp \
./lib/libgreputils.a \
./src/grep.exe \
./src/egrep \
./src/fgrep \
./src/Makefile \
./lib/Makefile \
./doc/Makefile \
./tests/Makefile \
./gnulib-tests/Makefile \
./po/Makefile \
./po/Makefile.in \
./po/POTFILES \
./config.log \
./config.status
5) after this, diff should print:
diff -rql . ../orig/grep-3.11
Only in .: config.h
Only in ./lib: alloca.h
Only in ./lib: colorize.c
Only in ./lib: configmake.h
Only in ./lib: ctype.h
Only in ./lib: dirent.h
Only in ./lib: errno.h
Only in ./lib: error.h
Only in ./lib: fcntl.h
Only in ./lib: fnmatch.h
Files ./lib/fts.c and ../orig/grep-3.11/lib/fts.c differ
Only in ./lib: getopt-cdefs.h
Only in ./lib: getopt.h
Only in ./lib: inttypes.h
Only in ./lib: langinfo.h
Only in ./lib: limits.h
Only in ./lib: locale.h
Only in ./lib/malloc: dynarray-skeleton.gl.h
Only in ./lib/malloc: dynarray.gl.h
Files ./lib/mbtowc-lock.c and ../orig/grep-3.11/lib/mbtowc-lock.c differ
Files ./lib/mbtowc-lock.h and ../orig/grep-3.11/lib/mbtowc-lock.h differ
Only in ./lib: signal.h
Only in ./lib: sigsegv.h
Only in ./lib: stdckdint.h
Only in ./lib: stddef.h
Only in ./lib: stdint.h
Only in ./lib: stdio.h
Only in ./lib: stdlib.h
Only in ./lib: string.h
Only in ./lib: sys
Only in ./lib: time.h
Only in ./lib: unistd.h
Only in ./lib: unistr.h
Only in ./lib: unitypes.h
Only in ./lib: uniwidth.h
Only in ./lib: wchar.h
Only in ./lib: wctype.h
Only in .: make.bat
Files ./src/grep.c and ../orig/grep-3.11/src/grep.c differ
6) edit make.bat
cp make.bat make.bat.old
sed -i -n 's/^.* cl /cl /p;/^lib /p;/^link /p' make.bat
sed -i '/.nologo /s@/lib@\\lib@g' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.cygpath -w .@lib\\@' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.if test -f.*\./@lib\\@' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. -I/s@.cygpath -w .@src\\@' make.bat
sed -i 's@.; fi`@@;s@.`@@' make.bat
sed -i 's@malloc/@malloc\\@;s@glthread/@glthread\\@;s@unistr/@unistr\\@;s@uniwidth/@uniwidth\\@' make.bat
sed -i '/libgreputils_a/s@-Fo@&lib\\@' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@-Fo@&src\\@' make.bat
sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@\([^ ]\)/@\1\\@g' make.bat
sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib @/I. /I.\\lib @' make.bat
sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat
sed -i 's@/I..\\..\\@/I..\\@' make.bat
sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat
sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@[^ ]*.obj@.\\lib\\&@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat
sed -i '/^link/s@..\\lib\\libgreputils.a@*@g;/^link/s@\*.*\*@*@;/^link/s@\*@.\\libgreputils.a@' make.bat
sed -i '/^link/s@\.\./\.\./@..\\@;s@\([^ ]\)/@\1\\@g' make.bat
sed -i '/^link/s@ .OUT:@ /LTCG&@;/^link/s@ *$@@g;/^link/s@[^ ]*.obj@.\\src\\&@g' make.bat
sed -i 's@.*@& || exit /b 1@' make.bat
rm make.bat.old
7) finally, create a patch:
diff -Naur ../orig/grep-3.11 . > ../grep-3.11-build-VS22-x64.patch
--tip: for the 32-bit build, use different patch name:
diff -Naur ../orig/grep-3.11 . > ../grep-3.11-build-VS22-x86.patch