xref: /curl/buildconf.bat (revision aba98d2f)
1@echo off
2rem ***************************************************************************
3rem *                                  _   _ ____  _
4rem *  Project                     ___| | | |  _ \| |
5rem *                             / __| | | | |_) | |
6rem *                            | (__| |_| |  _ <| |___
7rem *                             \___|\___/|_| \_\_____|
8rem *
9rem * Copyright (C) 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.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 * SPDX-License-Identifier: curl
23rem *
24rem ***************************************************************************
25
26rem NOTES
27rem
28rem This batch file must be used to set up a git tree to build on systems where
29rem there is no autotools support (i.e. DOS and Windows).
30rem
31
32:begin
33  rem Set our variables
34  if "%OS%" == "Windows_NT" setlocal
35  set MODE=GENERATE
36
37  rem Switch to this batch file's directory
38  cd /d "%~0\.." 1>NUL 2>&1
39
40  rem Check we are running from a curl git repository
41  if not exist GIT-INFO.md goto norepo
42
43:parseArgs
44  if "%~1" == "" goto start
45
46  if /i "%~1" == "-clean" (
47    set MODE=CLEAN
48  ) else if /i "%~1" == "-?" (
49    goto syntax
50  ) else if /i "%~1" == "-h" (
51    goto syntax
52  ) else if /i "%~1" == "-help" (
53    goto syntax
54  ) else (
55    goto unknown
56  )
57
58  shift & goto parseArgs
59
60:start
61  if "%MODE%" == "GENERATE" (
62    echo.
63    echo Generating prerequisite files
64
65    call :generate
66    if errorlevel 3 goto nogenhugehelp
67    if errorlevel 2 goto nogenmakefile
68    if errorlevel 1 goto warning
69
70  ) else (
71    echo.
72    echo Removing prerequisite files
73
74    call :clean
75    if errorlevel 2 goto nocleanhugehelp
76    if errorlevel 1 goto nocleanmakefile
77  )
78
79  goto success
80
81rem Main generate function.
82rem
83rem Returns:
84rem
85rem 0 - success
86rem 1 - success with simplified tool_hugehelp.c
87rem 2 - failed to generate Makefile
88rem 3 - failed to generate tool_hugehelp.c
89rem
90:generate
91  if "%OS%" == "Windows_NT" setlocal
92  set BASIC_HUGEHELP=0
93
94  rem Create Makefile
95  echo * %CD%\Makefile
96  if exist Makefile.dist (
97    copy /Y Makefile.dist Makefile 1>NUL 2>&1
98    if errorlevel 1 (
99      if "%OS%" == "Windows_NT" endlocal
100      exit /B 2
101    )
102  )
103
104  rem Create tool_hugehelp.c
105  echo * %CD%\src\tool_hugehelp.c
106  call :genHugeHelp
107  if errorlevel 2 (
108    if "%OS%" == "Windows_NT" endlocal
109    exit /B 3
110  )
111  if errorlevel 1 (
112    set BASIC_HUGEHELP=1
113  )
114  cmd /c exit 0
115
116  if "%BASIC_HUGEHELP%" == "1" (
117    if "%OS%" == "Windows_NT" endlocal
118    exit /B 1
119  )
120
121  if "%OS%" == "Windows_NT" endlocal
122  exit /B 0
123
124rem Main clean function.
125rem
126rem Returns:
127rem
128rem 0 - success
129rem 1 - failed to clean Makefile
130rem 2 - failed to clean tool_hugehelp.c
131rem
132:clean
133  rem Remove Makefile
134  echo * %CD%\Makefile
135  if exist Makefile (
136    del Makefile 2>NUL
137    if exist Makefile (
138      exit /B 1
139    )
140  )
141
142  rem Remove tool_hugehelp.c
143  echo * %CD%\src\tool_hugehelp.c
144  if exist src\tool_hugehelp.c (
145    del src\tool_hugehelp.c 2>NUL
146    if exist src\tool_hugehelp.c (
147      exit /B 2
148    )
149  )
150
151  exit /B
152
153rem Function to generate src\tool_hugehelp.c
154rem
155rem Returns:
156rem
157rem 0 - full tool_hugehelp.c generated
158rem 1 - simplified tool_hugehelp.c
159rem 2 - failure
160rem
161:genHugeHelp
162  if "%OS%" == "Windows_NT" setlocal
163  set LC_ALL=C
164  set BASIC=1
165
166  if exist src\tool_hugehelp.c.cvs (
167    copy /Y src\tool_hugehelp.c.cvs src\tool_hugehelp.c 1>NUL 2>&1
168  ) else (
169    echo #include "tool_setup.h"> src\tool_hugehelp.c
170    echo #include "tool_hugehelp.h">> src\tool_hugehelp.c
171    echo.>> src\tool_hugehelp.c
172    echo void hugehelp(void^)>> src\tool_hugehelp.c
173    echo {>> src\tool_hugehelp.c
174    echo #ifdef USE_MANUAL>> src\tool_hugehelp.c
175    echo   fputs("Built-in manual not included\n", stdout^);>> src\tool_hugehelp.c
176    echo #endif>> src\tool_hugehelp.c
177    echo }>> src\tool_hugehelp.c
178  )
179
180  findstr "/C:void hugehelp(void)" src\tool_hugehelp.c 1>NUL 2>&1
181  if errorlevel 1 (
182    if "%OS%" == "Windows_NT" endlocal
183    exit /B 2
184  )
185
186  if "%BASIC%" == "1" (
187    if "%OS%" == "Windows_NT" endlocal
188    exit /B 1
189  )
190
191  if "%OS%" == "Windows_NT" endlocal
192  exit /B 0
193
194rem Function to clean-up local variables under DOS, Windows 3.x and
195rem Windows 9x as setlocal isn't available until Windows NT
196rem
197:dosCleanup
198  set MODE=
199  set BASIC_HUGEHELP=
200  set LC_ALL
201  set BASIC=
202
203  exit /B
204
205:syntax
206  rem Display the help
207  echo.
208  echo Usage: buildconf [-clean]
209  echo.
210  echo -clean    - Removes the files
211  goto error
212
213:unknown
214  echo.
215  echo Error: Unknown argument '%1'
216  goto error
217
218:norepo
219  echo.
220  echo Error: This batch file should only be used with a curl git repository
221  goto error
222
223:nogenmakefile
224  echo.
225  echo Error: Unable to generate Makefile
226  goto error
227
228:nogenhugehelp
229  echo.
230  echo Error: Unable to generate src\tool_hugehelp.c
231  goto error
232
233:nocleanmakefile
234  echo.
235  echo Error: Unable to clean Makefile
236  goto error
237
238:nocleanhugehelp
239  echo.
240  echo Error: Unable to clean src\tool_hugehelp.c
241  goto error
242
243:warning
244  echo.
245  echo Warning: The curl manual could not be integrated in the source. This means when
246  echo you build curl the manual will not be available (curl --manual^). Integration of
247  echo the manual is not required and a summary of the options will still be available
248  echo (curl --help^). To integrate the manual build with configure or cmake.
249  goto success
250
251:error
252  if "%OS%" == "Windows_NT" (
253    endlocal
254  ) else (
255    call :dosCleanup
256  )
257  exit /B 1
258
259:success
260  if "%OS%" == "Windows_NT" (
261    endlocal
262  ) else (
263    call :dosCleanup
264  )
265  exit /B 0
266