blob: ad3fba6bcf825b731e7f2596d9462cd1f68904fd [file] [log] [blame]
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001@echo off
Alex Deymo8f1a2142016-06-28 14:49:26 -07002rem ***************************************************************************
3rem * _ _ ____ _
4rem * Project ___| | | | _ \| |
5rem * / __| | | | |_) | |
6rem * | (__| |_| | _ <| |___
7rem * \___|\___/|_| \_\_____|
8rem *
9rem * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10rem *
11rem * This software is licensed as described in the file COPYING, which
12rem * you should have received as part of this distribution. The terms
13rem * are also available at https://curl.haxx.se/docs/copyright.html.
14rem *
15rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16rem * copies of the Software, and permit persons to whom the Software is
17rem * furnished to do so, under the terms of the COPYING file.
18rem *
19rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20rem * KIND, either express or implied.
21rem *
22rem ***************************************************************************
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070023
Alex Deymo8f1a2142016-06-28 14:49:26 -070024rem NOTES
25rem
26rem This batch file must be used to set up a git tree to build on systems where
27rem there is no autotools support (i.e. DOS and Windows).
28rem
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070029
Alex Deymo8f1a2142016-06-28 14:49:26 -070030:begin
31 rem Set our variables
32 if "%OS%" == "Windows_NT" setlocal
33 set MODE=GENERATE
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070034
Alex Deymo8f1a2142016-06-28 14:49:26 -070035 rem Switch to this batch file's directory
36 cd /d "%~0\.." 1>NUL 2>&1
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070037
Alex Deymo8f1a2142016-06-28 14:49:26 -070038 rem Check we are running from a curl git repository
39 if not exist GIT-INFO goto norepo
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070040
Alex Deymo8f1a2142016-06-28 14:49:26 -070041 rem Detect programs. HAVE_<PROGNAME>
42 rem When not found the variable is set undefined. The undefined pattern
43 rem allows for statements like "if not defined HAVE_PERL (command)"
44 groff --version <NUL 1>NUL 2>&1
45 if errorlevel 1 (set HAVE_GROFF=) else (set HAVE_GROFF=Y)
46 nroff --version <NUL 1>NUL 2>&1
47 if errorlevel 1 (set HAVE_NROFF=) else (set HAVE_NROFF=Y)
48 perl --version <NUL 1>NUL 2>&1
49 if errorlevel 1 (set HAVE_PERL=) else (set HAVE_PERL=Y)
50 gzip --version <NUL 1>NUL 2>&1
51 if errorlevel 1 (set HAVE_GZIP=) else (set HAVE_GZIP=Y)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070052
Alex Deymo8f1a2142016-06-28 14:49:26 -070053:parseArgs
54 if "%~1" == "" goto start
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070055
Alex Deymo8f1a2142016-06-28 14:49:26 -070056 if /i "%~1" == "-clean" (
57 set MODE=CLEAN
58 ) else if /i "%~1" == "-?" (
59 goto syntax
60 ) else if /i "%~1" == "-h" (
61 goto syntax
62 ) else if /i "%~1" == "-help" (
63 goto syntax
64 ) else (
65 goto unknown
66 )
67
68 shift & goto parseArgs
69
70:start
71 if "%MODE%" == "GENERATE" (
72 echo.
73 echo Generating prerequisite files
74
75 call :generate
76 if errorlevel 4 goto nogencurlbuild
77 if errorlevel 3 goto nogenhugehelp
78 if errorlevel 2 goto nogenmakefile
79 if errorlevel 1 goto warning
80
81 ) else (
82 echo.
83 echo Removing prerequisite files
84
85 call :clean
86 if errorlevel 3 goto nocleancurlbuild
87 if errorlevel 2 goto nocleanhugehelp
88 if errorlevel 1 goto nocleanmakefile
89 )
90
91 goto success
92
93rem Main generate function.
94rem
95rem Returns:
96rem
97rem 0 - success
98rem 1 - success with simplified tool_hugehelp.c
99rem 2 - failed to generate Makefile
100rem 3 - failed to generate tool_hugehelp.c
101rem 4 - failed to generate curlbuild.h
102rem
103:generate
104 if "%OS%" == "Windows_NT" setlocal
105 set BASIC_HUGEHELP=0
106
107 rem Create Makefile
108 echo * %CD%\Makefile
109 if exist Makefile.dist (
110 copy /Y Makefile.dist Makefile 1>NUL 2>&1
111 if errorlevel 1 (
112 if "%OS%" == "Windows_NT" endlocal
113 exit /B 2
114 )
115 )
116
117 rem Create tool_hugehelp.c
118 echo * %CD%\src\tool_hugehelp.c
119 call :genHugeHelp
120 if errorlevel 2 (
121 if "%OS%" == "Windows_NT" endlocal
122 exit /B 3
123 )
124 if errorlevel 1 (
125 set BASIC_HUGEHELP=1
126 )
127 cmd /c exit 0
128
129 rem Create curlbuild.h
130 echo * %CD%\include\curl\curlbuild.h
131 if exist include\curl\curlbuild.h.dist (
132 copy /Y include\curl\curlbuild.h.dist include\curl\curlbuild.h 1>NUL 2>&1
133 if errorlevel 1 (
134 if "%OS%" == "Windows_NT" endlocal
135 exit /B 4
136 )
137 )
138
139 rem Setup c-ares git tree
140 if exist ares\buildconf.bat (
141 echo.
142 echo Configuring c-ares build environment
143 cd ares
144 call buildconf.bat
145 cd ..
146 )
147
148 if "%BASIC_HUGEHELP%" == "1" (
149 if "%OS%" == "Windows_NT" endlocal
150 exit /B 1
151 )
152
153 if "%OS%" == "Windows_NT" endlocal
154 exit /B 0
155
156rem Main clean function.
157rem
158rem Returns:
159rem
160rem 0 - success
161rem 1 - failed to clean Makefile
162rem 2 - failed to clean tool_hugehelp.c
163rem 3 - failed to clean curlbuild.h
164rem
165:clean
166 rem Remove Makefile
167 echo * %CD%\Makefile
168 if exist Makefile (
169 del Makefile 2>NUL
170 if exist Makefile (
171 exit /B 1
172 )
173 )
174
175 rem Remove tool_hugehelp.c
176 echo * %CD%\src\tool_hugehelp.c
177 if exist src\tool_hugehelp.c (
178 del src\tool_hugehelp.c 2>NUL
179 if exist src\tool_hugehelp.c (
180 exit /B 2
181 )
182 )
183
184 rem Remove curlbuild.h
185 echo * %CD%\include\curl\curlbuild.h
186 if exist include\curl\curlbuild.h (
187 del include\curl\curlbuild.h 2>NUL
188 if exist include\curl\curlbuild.h (
189 exit /B 3
190 )
191 )
192
193 exit /B
194
195rem Function to generate src\tool_hugehelp.c
196rem
197rem Returns:
198rem
199rem 0 - full tool_hugehelp.c generated
200rem 1 - simplified tool_hugehelp.c
201rem 2 - failure
202rem
203:genHugeHelp
204 if "%OS%" == "Windows_NT" setlocal
205 set LC_ALL=C
206 set ROFFCMD=
207 set BASIC=1
208
209 if defined HAVE_PERL (
210 if defined HAVE_GROFF (
211 set ROFFCMD=groff -mtty-char -Tascii -P-c -man
212 ) else if defined HAVE_NROFF (
213 set ROFFCMD=nroff -c -Tascii -man
214 )
215 )
216
217 if defined ROFFCMD (
218 echo #include "tool_setup.h"> src\tool_hugehelp.c
219 echo #include "tool_hugehelp.h">> src\tool_hugehelp.c
220
221 if defined HAVE_GZIP (
222 echo #ifndef HAVE_LIBZ>> src\tool_hugehelp.c
223 )
224
225 %ROFFCMD% docs\curl.1 2>NUL | perl src\mkhelp.pl docs\MANUAL >> src\tool_hugehelp.c
226 if defined HAVE_GZIP (
227 echo #else>> src\tool_hugehelp.c
228 %ROFFCMD% docs\curl.1 2>NUL | perl src\mkhelp.pl -c docs\MANUAL >> src\tool_hugehelp.c
229 echo #endif /^* HAVE_LIBZ ^*/>> src\tool_hugehelp.c
230 )
231
232 set BASIC=0
233 ) else (
234 if exist src\tool_hugehelp.c.cvs (
235 copy /Y src\tool_hugehelp.c.cvs src\tool_hugehelp.c 1>NUL 2>&1
236 ) else (
237 echo #include "tool_setup.h"> src\tool_hugehelp.c
238 echo #include "tool_hugehelp.hd">> src\tool_hugehelp.c
239 echo.>> src\tool_hugehelp.c
240 echo void hugehelp(void^)>> src\tool_hugehelp.c
241 echo {>> src\tool_hugehelp.c
242 echo #ifdef USE_MANUAL>> src\tool_hugehelp.c
243 echo fputs("Built-in manual not included\n", stdout^);>> src\tool_hugehelp.c
244 echo #endif>> src\tool_hugehelp.c
245 echo }>> src\tool_hugehelp.c
246 )
247 )
248
249 findstr "/C:void hugehelp(void)" src\tool_hugehelp.c 1>NUL 2>&1
250 if errorlevel 1 (
251 if "%OS%" == "Windows_NT" endlocal
252 exit /B 2
253 )
254
255 if "%BASIC%" == "1" (
256 if "%OS%" == "Windows_NT" endlocal
257 exit /B 1
258 )
259
260 if "%OS%" == "Windows_NT" endlocal
261 exit /B 0
262
263rem Function to clean-up local variables under DOS, Windows 3.x and
264rem Windows 9x as setlocal isn't available until Windows NT
265rem
266:dosCleanup
267 set MODE=
268 set HAVE_GROFF=
269 set HAVE_NROFF=
270 set HAVE_PERL=
271 set HAVE_GZIP=
272 set BASIC_HUGEHELP=
273 set LC_ALL
274 set ROFFCMD=
275 set BASIC=
276
277 exit /B
278
279:syntax
280 rem Display the help
281 echo.
282 echo Usage: buildconf [-clean]
283 echo.
284 echo -clean - Removes the files
285 goto error
286
287:unknown
288 echo.
289 echo Error: Unknown argument '%1'
290 goto error
291
292:norepo
293 echo.
294 echo Error: This batch file should only be used with a curl git repository
295 goto error
296
297:nogenmakefile
298 echo.
299 echo Error: Unable to generate Makefile
300 goto error
301
302:nogenhugehelp
303 echo.
304 echo Error: Unable to generate src\tool_hugehelp.c
305 goto error
306
307:nogencurlbuild
308 echo.
309 echo Error: Unable to generate include\curl\curlbuild.h
310 goto error
311
312:nocleanmakefile
313 echo.
314 echo Error: Unable to clean Makefile
315 goto error
316
317:nocleanhugehelp
318 echo.
319 echo Error: Unable to clean src\tool_hugehelp.c
320 goto error
321
322:nocleancurlbuild
323 echo.
324 echo Error: Unable to clean include\curl\curlbuild.h
325 goto error
326
327:warning
328 echo.
329 echo Warning: The curl manual could not be integrated in the source. This means when
330 echo you build curl the manual will not be available (curl --man^). Integration of
331 echo the manual is not required and a summary of the options will still be available
332 echo (curl --help^). To integrate the manual your PATH is required to have
333 echo groff/nroff, perl and optionally gzip for compression.
334 goto success
335
336:error
337 if "%OS%" == "Windows_NT" (
338 endlocal
339 ) else (
340 call :dosCleanup
341 )
342 exit /B 1
343
344:success
345 if "%OS%" == "Windows_NT" (
346 endlocal
347 ) else (
348 call :dosCleanup
349 )
350 exit /B 0