113498266Sopenharmony_ci@echo off
213498266Sopenharmony_cirem ***************************************************************************
313498266Sopenharmony_cirem *                                  _   _ ____  _
413498266Sopenharmony_cirem *  Project                     ___| | | |  _ \| |
513498266Sopenharmony_cirem *                             / __| | | | |_) | |
613498266Sopenharmony_cirem *                            | (__| |_| |  _ <| |___
713498266Sopenharmony_cirem *                             \___|\___/|_| \_\_____|
813498266Sopenharmony_cirem *
913498266Sopenharmony_cirem * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
1013498266Sopenharmony_cirem *
1113498266Sopenharmony_cirem * This software is licensed as described in the file COPYING, which
1213498266Sopenharmony_cirem * you should have received as part of this distribution. The terms
1313498266Sopenharmony_cirem * are also available at https://curl.se/docs/copyright.html.
1413498266Sopenharmony_cirem *
1513498266Sopenharmony_cirem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1613498266Sopenharmony_cirem * copies of the Software, and permit persons to whom the Software is
1713498266Sopenharmony_cirem * furnished to do so, under the terms of the COPYING file.
1813498266Sopenharmony_cirem *
1913498266Sopenharmony_cirem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2013498266Sopenharmony_cirem * KIND, either express or implied.
2113498266Sopenharmony_cirem *
2213498266Sopenharmony_cirem * SPDX-License-Identifier: curl
2313498266Sopenharmony_cirem *
2413498266Sopenharmony_cirem ***************************************************************************
2513498266Sopenharmony_ci
2613498266Sopenharmony_cirem NOTES
2713498266Sopenharmony_cirem
2813498266Sopenharmony_cirem This batch file must be used to set up a git tree to build on systems where
2913498266Sopenharmony_cirem there is no autotools support (i.e. DOS and Windows).
3013498266Sopenharmony_cirem
3113498266Sopenharmony_ci
3213498266Sopenharmony_ci:begin
3313498266Sopenharmony_ci  rem Set our variables
3413498266Sopenharmony_ci  if "%OS%" == "Windows_NT" setlocal
3513498266Sopenharmony_ci  set MODE=GENERATE
3613498266Sopenharmony_ci
3713498266Sopenharmony_ci  rem Switch to this batch file's directory
3813498266Sopenharmony_ci  cd /d "%~0\.." 1>NUL 2>&1
3913498266Sopenharmony_ci
4013498266Sopenharmony_ci  rem Check we are running from a curl git repository
4113498266Sopenharmony_ci  if not exist GIT-INFO goto norepo
4213498266Sopenharmony_ci
4313498266Sopenharmony_ci  rem Detect programs. HAVE_<PROGNAME>
4413498266Sopenharmony_ci  rem When not found the variable is set undefined. The undefined pattern
4513498266Sopenharmony_ci  rem allows for statements like "if not defined HAVE_PERL (command)"
4613498266Sopenharmony_ci  groff --version <NUL 1>NUL 2>&1
4713498266Sopenharmony_ci  if errorlevel 1 (set HAVE_GROFF=) else (set HAVE_GROFF=Y)
4813498266Sopenharmony_ci  nroff --version <NUL 1>NUL 2>&1
4913498266Sopenharmony_ci  if errorlevel 1 (set HAVE_NROFF=) else (set HAVE_NROFF=Y)
5013498266Sopenharmony_ci  perl --version <NUL 1>NUL 2>&1
5113498266Sopenharmony_ci  if errorlevel 1 (set HAVE_PERL=) else (set HAVE_PERL=Y)
5213498266Sopenharmony_ci  gzip --version <NUL 1>NUL 2>&1
5313498266Sopenharmony_ci  if errorlevel 1 (set HAVE_GZIP=) else (set HAVE_GZIP=Y)
5413498266Sopenharmony_ci
5513498266Sopenharmony_ci:parseArgs
5613498266Sopenharmony_ci  if "%~1" == "" goto start
5713498266Sopenharmony_ci
5813498266Sopenharmony_ci  if /i "%~1" == "-clean" (
5913498266Sopenharmony_ci    set MODE=CLEAN
6013498266Sopenharmony_ci  ) else if /i "%~1" == "-?" (
6113498266Sopenharmony_ci    goto syntax
6213498266Sopenharmony_ci  ) else if /i "%~1" == "-h" (
6313498266Sopenharmony_ci    goto syntax
6413498266Sopenharmony_ci  ) else if /i "%~1" == "-help" (
6513498266Sopenharmony_ci    goto syntax
6613498266Sopenharmony_ci  ) else (
6713498266Sopenharmony_ci    goto unknown
6813498266Sopenharmony_ci  )
6913498266Sopenharmony_ci
7013498266Sopenharmony_ci  shift & goto parseArgs
7113498266Sopenharmony_ci
7213498266Sopenharmony_ci:start
7313498266Sopenharmony_ci  if "%MODE%" == "GENERATE" (
7413498266Sopenharmony_ci    echo.
7513498266Sopenharmony_ci    echo Generating prerequisite files
7613498266Sopenharmony_ci
7713498266Sopenharmony_ci    call :generate
7813498266Sopenharmony_ci    if errorlevel 3 goto nogenhugehelp
7913498266Sopenharmony_ci    if errorlevel 2 goto nogenmakefile
8013498266Sopenharmony_ci    if errorlevel 1 goto warning
8113498266Sopenharmony_ci
8213498266Sopenharmony_ci  ) else (
8313498266Sopenharmony_ci    echo.
8413498266Sopenharmony_ci    echo Removing prerequisite files
8513498266Sopenharmony_ci
8613498266Sopenharmony_ci    call :clean
8713498266Sopenharmony_ci    if errorlevel 2 goto nocleanhugehelp
8813498266Sopenharmony_ci    if errorlevel 1 goto nocleanmakefile
8913498266Sopenharmony_ci  )
9013498266Sopenharmony_ci
9113498266Sopenharmony_ci  goto success
9213498266Sopenharmony_ci
9313498266Sopenharmony_cirem Main generate function.
9413498266Sopenharmony_cirem
9513498266Sopenharmony_cirem Returns:
9613498266Sopenharmony_cirem
9713498266Sopenharmony_cirem 0 - success
9813498266Sopenharmony_cirem 1 - success with simplified tool_hugehelp.c
9913498266Sopenharmony_cirem 2 - failed to generate Makefile
10013498266Sopenharmony_cirem 3 - failed to generate tool_hugehelp.c
10113498266Sopenharmony_cirem
10213498266Sopenharmony_ci:generate
10313498266Sopenharmony_ci  if "%OS%" == "Windows_NT" setlocal
10413498266Sopenharmony_ci  set BASIC_HUGEHELP=0
10513498266Sopenharmony_ci
10613498266Sopenharmony_ci  rem Create Makefile
10713498266Sopenharmony_ci  echo * %CD%\Makefile
10813498266Sopenharmony_ci  if exist Makefile.dist (
10913498266Sopenharmony_ci    copy /Y Makefile.dist Makefile 1>NUL 2>&1
11013498266Sopenharmony_ci    if errorlevel 1 (
11113498266Sopenharmony_ci      if "%OS%" == "Windows_NT" endlocal
11213498266Sopenharmony_ci      exit /B 2
11313498266Sopenharmony_ci    )
11413498266Sopenharmony_ci  )
11513498266Sopenharmony_ci
11613498266Sopenharmony_ci  rem Create tool_hugehelp.c
11713498266Sopenharmony_ci  echo * %CD%\src\tool_hugehelp.c
11813498266Sopenharmony_ci  call :genHugeHelp
11913498266Sopenharmony_ci  if errorlevel 2 (
12013498266Sopenharmony_ci    if "%OS%" == "Windows_NT" endlocal
12113498266Sopenharmony_ci    exit /B 3
12213498266Sopenharmony_ci  )
12313498266Sopenharmony_ci  if errorlevel 1 (
12413498266Sopenharmony_ci    set BASIC_HUGEHELP=1
12513498266Sopenharmony_ci  )
12613498266Sopenharmony_ci  cmd /c exit 0
12713498266Sopenharmony_ci
12813498266Sopenharmony_ci  rem Setup c-ares git tree
12913498266Sopenharmony_ci  if exist ares\buildconf.bat (
13013498266Sopenharmony_ci    echo.
13113498266Sopenharmony_ci    echo Configuring c-ares build environment
13213498266Sopenharmony_ci    cd ares
13313498266Sopenharmony_ci    call buildconf.bat
13413498266Sopenharmony_ci    cd ..
13513498266Sopenharmony_ci  )
13613498266Sopenharmony_ci
13713498266Sopenharmony_ci  if "%BASIC_HUGEHELP%" == "1" (
13813498266Sopenharmony_ci    if "%OS%" == "Windows_NT" endlocal
13913498266Sopenharmony_ci    exit /B 1
14013498266Sopenharmony_ci  )
14113498266Sopenharmony_ci
14213498266Sopenharmony_ci  if "%OS%" == "Windows_NT" endlocal
14313498266Sopenharmony_ci  exit /B 0
14413498266Sopenharmony_ci
14513498266Sopenharmony_cirem Main clean function.
14613498266Sopenharmony_cirem
14713498266Sopenharmony_cirem Returns:
14813498266Sopenharmony_cirem
14913498266Sopenharmony_cirem 0 - success
15013498266Sopenharmony_cirem 1 - failed to clean Makefile
15113498266Sopenharmony_cirem 2 - failed to clean tool_hugehelp.c
15213498266Sopenharmony_cirem
15313498266Sopenharmony_ci:clean
15413498266Sopenharmony_ci  rem Remove Makefile
15513498266Sopenharmony_ci  echo * %CD%\Makefile
15613498266Sopenharmony_ci  if exist Makefile (
15713498266Sopenharmony_ci    del Makefile 2>NUL
15813498266Sopenharmony_ci    if exist Makefile (
15913498266Sopenharmony_ci      exit /B 1
16013498266Sopenharmony_ci    )
16113498266Sopenharmony_ci  )
16213498266Sopenharmony_ci
16313498266Sopenharmony_ci  rem Remove tool_hugehelp.c
16413498266Sopenharmony_ci  echo * %CD%\src\tool_hugehelp.c
16513498266Sopenharmony_ci  if exist src\tool_hugehelp.c (
16613498266Sopenharmony_ci    del src\tool_hugehelp.c 2>NUL
16713498266Sopenharmony_ci    if exist src\tool_hugehelp.c (
16813498266Sopenharmony_ci      exit /B 2
16913498266Sopenharmony_ci    )
17013498266Sopenharmony_ci  )
17113498266Sopenharmony_ci
17213498266Sopenharmony_ci  exit /B
17313498266Sopenharmony_ci
17413498266Sopenharmony_cirem Function to generate src\tool_hugehelp.c
17513498266Sopenharmony_cirem
17613498266Sopenharmony_cirem Returns:
17713498266Sopenharmony_cirem
17813498266Sopenharmony_cirem 0 - full tool_hugehelp.c generated
17913498266Sopenharmony_cirem 1 - simplified tool_hugehelp.c
18013498266Sopenharmony_cirem 2 - failure
18113498266Sopenharmony_cirem
18213498266Sopenharmony_ci:genHugeHelp
18313498266Sopenharmony_ci  if "%OS%" == "Windows_NT" setlocal
18413498266Sopenharmony_ci  set LC_ALL=C
18513498266Sopenharmony_ci  set ROFFCMD=
18613498266Sopenharmony_ci  set BASIC=1
18713498266Sopenharmony_ci
18813498266Sopenharmony_ci  if defined HAVE_PERL (
18913498266Sopenharmony_ci    if defined HAVE_GROFF (
19013498266Sopenharmony_ci      set ROFFCMD=groff -mtty-char -Tascii -P-c -man
19113498266Sopenharmony_ci    ) else if defined HAVE_NROFF (
19213498266Sopenharmony_ci      set ROFFCMD=nroff -c -Tascii -man
19313498266Sopenharmony_ci    )
19413498266Sopenharmony_ci  )
19513498266Sopenharmony_ci
19613498266Sopenharmony_ci  if defined ROFFCMD (
19713498266Sopenharmony_ci    echo #include "tool_setup.h"> src\tool_hugehelp.c
19813498266Sopenharmony_ci    echo #include "tool_hugehelp.h">> src\tool_hugehelp.c
19913498266Sopenharmony_ci
20013498266Sopenharmony_ci    if defined HAVE_GZIP (
20113498266Sopenharmony_ci      echo #ifndef HAVE_LIBZ>> src\tool_hugehelp.c
20213498266Sopenharmony_ci    )
20313498266Sopenharmony_ci
20413498266Sopenharmony_ci    %ROFFCMD% docs\curl.1 2>NUL | perl src\mkhelp.pl docs\MANUAL >> src\tool_hugehelp.c
20513498266Sopenharmony_ci    if defined HAVE_GZIP (
20613498266Sopenharmony_ci      echo #else>> src\tool_hugehelp.c
20713498266Sopenharmony_ci      %ROFFCMD% docs\curl.1 2>NUL | perl src\mkhelp.pl -c docs\MANUAL >> src\tool_hugehelp.c
20813498266Sopenharmony_ci      echo #endif /^* HAVE_LIBZ ^*/>> src\tool_hugehelp.c
20913498266Sopenharmony_ci    )
21013498266Sopenharmony_ci
21113498266Sopenharmony_ci    set BASIC=0
21213498266Sopenharmony_ci  ) else (
21313498266Sopenharmony_ci    if exist src\tool_hugehelp.c.cvs (
21413498266Sopenharmony_ci      copy /Y src\tool_hugehelp.c.cvs src\tool_hugehelp.c 1>NUL 2>&1
21513498266Sopenharmony_ci    ) else (
21613498266Sopenharmony_ci      echo #include "tool_setup.h"> src\tool_hugehelp.c
21713498266Sopenharmony_ci      echo #include "tool_hugehelp.h">> src\tool_hugehelp.c
21813498266Sopenharmony_ci      echo.>> src\tool_hugehelp.c
21913498266Sopenharmony_ci      echo void hugehelp(void^)>> src\tool_hugehelp.c
22013498266Sopenharmony_ci      echo {>> src\tool_hugehelp.c
22113498266Sopenharmony_ci      echo #ifdef USE_MANUAL>> src\tool_hugehelp.c
22213498266Sopenharmony_ci      echo   fputs("Built-in manual not included\n", stdout^);>> src\tool_hugehelp.c
22313498266Sopenharmony_ci      echo #endif>> src\tool_hugehelp.c
22413498266Sopenharmony_ci      echo }>> src\tool_hugehelp.c
22513498266Sopenharmony_ci    )
22613498266Sopenharmony_ci  )
22713498266Sopenharmony_ci
22813498266Sopenharmony_ci  findstr "/C:void hugehelp(void)" src\tool_hugehelp.c 1>NUL 2>&1
22913498266Sopenharmony_ci  if errorlevel 1 (
23013498266Sopenharmony_ci    if "%OS%" == "Windows_NT" endlocal
23113498266Sopenharmony_ci    exit /B 2
23213498266Sopenharmony_ci  )
23313498266Sopenharmony_ci
23413498266Sopenharmony_ci  if "%BASIC%" == "1" (
23513498266Sopenharmony_ci    if "%OS%" == "Windows_NT" endlocal
23613498266Sopenharmony_ci    exit /B 1
23713498266Sopenharmony_ci  )
23813498266Sopenharmony_ci
23913498266Sopenharmony_ci  if "%OS%" == "Windows_NT" endlocal
24013498266Sopenharmony_ci  exit /B 0
24113498266Sopenharmony_ci
24213498266Sopenharmony_cirem Function to clean-up local variables under DOS, Windows 3.x and
24313498266Sopenharmony_cirem Windows 9x as setlocal isn't available until Windows NT
24413498266Sopenharmony_cirem
24513498266Sopenharmony_ci:dosCleanup
24613498266Sopenharmony_ci  set MODE=
24713498266Sopenharmony_ci  set HAVE_GROFF=
24813498266Sopenharmony_ci  set HAVE_NROFF=
24913498266Sopenharmony_ci  set HAVE_PERL=
25013498266Sopenharmony_ci  set HAVE_GZIP=
25113498266Sopenharmony_ci  set BASIC_HUGEHELP=
25213498266Sopenharmony_ci  set LC_ALL
25313498266Sopenharmony_ci  set ROFFCMD=
25413498266Sopenharmony_ci  set BASIC=
25513498266Sopenharmony_ci
25613498266Sopenharmony_ci  exit /B
25713498266Sopenharmony_ci
25813498266Sopenharmony_ci:syntax
25913498266Sopenharmony_ci  rem Display the help
26013498266Sopenharmony_ci  echo.
26113498266Sopenharmony_ci  echo Usage: buildconf [-clean]
26213498266Sopenharmony_ci  echo.
26313498266Sopenharmony_ci  echo -clean    - Removes the files
26413498266Sopenharmony_ci  goto error
26513498266Sopenharmony_ci
26613498266Sopenharmony_ci:unknown
26713498266Sopenharmony_ci  echo.
26813498266Sopenharmony_ci  echo Error: Unknown argument '%1'
26913498266Sopenharmony_ci  goto error
27013498266Sopenharmony_ci
27113498266Sopenharmony_ci:norepo
27213498266Sopenharmony_ci  echo.
27313498266Sopenharmony_ci  echo Error: This batch file should only be used with a curl git repository
27413498266Sopenharmony_ci  goto error
27513498266Sopenharmony_ci
27613498266Sopenharmony_ci:nogenmakefile
27713498266Sopenharmony_ci  echo.
27813498266Sopenharmony_ci  echo Error: Unable to generate Makefile
27913498266Sopenharmony_ci  goto error
28013498266Sopenharmony_ci
28113498266Sopenharmony_ci:nogenhugehelp
28213498266Sopenharmony_ci  echo.
28313498266Sopenharmony_ci  echo Error: Unable to generate src\tool_hugehelp.c
28413498266Sopenharmony_ci  goto error
28513498266Sopenharmony_ci
28613498266Sopenharmony_ci:nocleanmakefile
28713498266Sopenharmony_ci  echo.
28813498266Sopenharmony_ci  echo Error: Unable to clean Makefile
28913498266Sopenharmony_ci  goto error
29013498266Sopenharmony_ci
29113498266Sopenharmony_ci:nocleanhugehelp
29213498266Sopenharmony_ci  echo.
29313498266Sopenharmony_ci  echo Error: Unable to clean src\tool_hugehelp.c
29413498266Sopenharmony_ci  goto error
29513498266Sopenharmony_ci
29613498266Sopenharmony_ci:warning
29713498266Sopenharmony_ci  echo.
29813498266Sopenharmony_ci  echo Warning: The curl manual could not be integrated in the source. This means when
29913498266Sopenharmony_ci  echo you build curl the manual will not be available (curl --man^). Integration of
30013498266Sopenharmony_ci  echo the manual is not required and a summary of the options will still be available
30113498266Sopenharmony_ci  echo (curl --help^). To integrate the manual your PATH is required to have
30213498266Sopenharmony_ci  echo groff/nroff, perl and optionally gzip for compression.
30313498266Sopenharmony_ci  goto success
30413498266Sopenharmony_ci
30513498266Sopenharmony_ci:error
30613498266Sopenharmony_ci  if "%OS%" == "Windows_NT" (
30713498266Sopenharmony_ci    endlocal
30813498266Sopenharmony_ci  ) else (
30913498266Sopenharmony_ci    call :dosCleanup
31013498266Sopenharmony_ci  )
31113498266Sopenharmony_ci  exit /B 1
31213498266Sopenharmony_ci
31313498266Sopenharmony_ci:success
31413498266Sopenharmony_ci  if "%OS%" == "Windows_NT" (
31513498266Sopenharmony_ci    endlocal
31613498266Sopenharmony_ci  ) else (
31713498266Sopenharmony_ci    call :dosCleanup
31813498266Sopenharmony_ci  )
31913498266Sopenharmony_ci  exit /B 0
320