From eb55f9b9b5df5678df0b30f4a0af9f35fcbc4be4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Oct 2017 14:40:39 +0200 Subject: Switch to using options instead of arguments in build batch files --- build-mingw.bat | 77 +++++++++++++++++++++++++++++++----------- build-msvc.bat | 103 +++++++++++++++++++++++++++++++++++++++----------------- build.sh | 2 +- 3 files changed, 132 insertions(+), 50 deletions(-) diff --git a/build-mingw.bat b/build-mingw.bat index 11dbb62..ddb8a5d 100644 --- a/build-mingw.bat +++ b/build-mingw.bat @@ -9,18 +9,20 @@ goto start :usage echo. -echo Usage: %0 [/?] [^] ^ [^] [^] +echo Usage: %0 [/?] [^] ^ echo Options: -echo --timeout ^ Network operations timeout in seconds. -echo --make ^ Bootstrap using GNU make instead of batch file. +echo --install-dir ^ Alternative installation directory. +echo --repo ^ Alternative package repository location. +echo --trust ^ Repository certificate fingerprint to trust. +echo --timeout ^ Network operations timeout in seconds. +echo --make ^ Bootstrap using GNU make instead of batch file. echo. echo By default the batch file will install into C:\build2. It also expects echo to find the base utilities in the bin\ subdirectory of the installation echo directory (C:\build2\bin\ by default). echo. -echo The ^ argument can be used to specify the repository certificate -echo fingerprint to trust. Two special values are also recognized: 'yes' -echo (trust everything) and 'no' (trust nothing). +echo The --trust option recognizes two special values: 'yes' (trust everything) +echo and 'no' (trust nothing). echo. echo The --make option can be used to bootstrap using GNU make. The first echo --make value should specify the make executable optionally followed by @@ -51,6 +53,8 @@ set "cdir=build2-toolchain-%cver%" rem Parse options. rem +set "idir=C:\build2" +set "trust=" set "timeout=" set "make=" @@ -59,6 +63,39 @@ if "_%~1_" == "_/?_" goto usage if "_%~1_" == "_-h_" goto usage if "_%~1_" == "_--help_" goto usage +if "_%~1_" == "_--install-dir_" ( + if "_%~2_" == "__" ( + echo error: installation directory expected after --install-dir + goto error + ) + set "idir=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--trust_" ( + if "_%~2_" == "__" ( + echo error: certificate fingerprint expected after --trust + goto error + ) + set "trust=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--repo_" ( + if "_%~2_" == "__" ( + echo error: repository location expected after --repo + goto error + ) + set "BUILD2_REPO=%~2" + shift + shift + goto options +) + if "_%~1_" == "_--timeout_" ( if "_%~2_" == "__" ( echo error: value in seconds expected after --timeout @@ -85,9 +122,6 @@ if "_%~1_" == "_--_" shift rem Validate options and arguments. rem -if not "_%timeout%_" == "__" ( - set "timeout=--fetch-timeout %timeout%" -) rem Compiler. rem @@ -98,30 +132,35 @@ if "_%1_" == "__" ( set "cxx=%1" ) -rem Installation directory. +rem @@ Temporarily retained for backwards compatibility. rem -if "_%2_" == "__" ( - set "idir=C:\build2" -) else ( +if not "_%2_" == "__" ( set "idir=%2" ) +if not "_%3_" == "__" ( + set "trust=%3" +) rem Certificate to trust. rem -if "_%3_" == "__" ( - set "trust=" -) else ( - if "_%3_" == "_yes_" ( +if not "_%trust%_" == "__" ( + if "_%trust%_" == "_yes_" ( set "trust=--trust-yes" ) else ( - if "_%3_" == "_no_" ( + if "_%trust%_" == "_no_" ( set "trust=--trust-no" ) else ( - set "trust=--trust %3" + set "trust=--trust %trust%" ) ) ) +rem Network timeout. +rem +if not "_%timeout%_" == "__" ( + set "timeout=--fetch-timeout %timeout%" +) + if not exist %idir%\bin\ ( echo error: %idir%\bin\ does not exist goto error diff --git a/build-msvc.bat b/build-msvc.bat index 477950d..0602422 100644 --- a/build-msvc.bat +++ b/build-msvc.bat @@ -9,21 +9,19 @@ goto start :usage echo. -echo Usage: %0 [/?] [^] [^] [^] +echo Usage: %0 [/?] [^] [^] echo Options: -echo --timeout ^ Network operations timeout in seconds. +echo --install-dir ^ Alternative installation directory. +echo --repo ^ Alternative package repository location. +echo --trust ^ Repository certificate fingerprint to trust. +echo --timeout ^ Network operations timeout in seconds. echo. -echo By default the batch file will install into C:\build2. It also expects -echo to find the base utilities in the bin\ subdirectory of the installation -echo directory (C:\build2\bin\ by default). +echo By default the batch file will use cl.exe as the C++ compiler and install +echo into C:\build2. It also expects to find the base utilities in the bin\ +echo subdirectory of the installation directory (C:\build2\bin\ by default). echo. -echo The ^ argument can be used to specify the repository certificate -echo fingerprint to trust. Two special values are also recognized: 'yes' -echo (trust everything) and 'no' (trust nothing). -echo. -echo Example usage: -echo. -echo %0 D:\build2 +echo The --trust option recognizes two special values: 'yes' (trust everything) +echo and 'no' (trust nothing). echo. echo See the BOOTSTRAP-MSVC file for details. echo. @@ -48,6 +46,8 @@ set "cdir=build2-toolchain-%cver%" rem Parse options. rem +set "idir=C:\build2" +set "trust=" set "timeout=" :options @@ -55,6 +55,39 @@ if "_%~1_" == "_/?_" goto usage if "_%~1_" == "_-h_" goto usage if "_%~1_" == "_--help_" goto usage +if "_%~1_" == "_--install-dir_" ( + if "_%~2_" == "__" ( + echo error: installation directory expected after --install-dir + goto error + ) + set "idir=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--trust_" ( + if "_%~2_" == "__" ( + echo error: certificate fingerprint expected after --trust + goto error + ) + set "trust=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--repo_" ( + if "_%~2_" == "__" ( + echo error: repository location expected after --repo + goto error + ) + set "BUILD2_REPO=%~2" + shift + shift + goto options +) + if "_%~1_" == "_--timeout_" ( if "_%~2_" == "__" ( echo error: value in seconds expected after --timeout @@ -65,38 +98,48 @@ if "_%~1_" == "_--timeout_" ( shift goto options ) + if "_%~1_" == "_--_" shift rem Validate options and arguments. rem -if not "_%timeout%_" == "__" ( - set "timeout=--fetch-timeout %timeout%" -) -rem Installation directory. +rem @@ Temporarily retained for backwards compatibility. rem -if "_%1_" == "__" ( - set "idir=C:\build2" -) else ( +if not "_%1_" == "__" ( set "idir=%1" ) +if not "_%2_" == "__" ( + set "trust=%2" +) +rem Compiler. +rem +rem if "_%1_" == "__" ( + set "cxx=cl" +rem ) else ( +rem set "cxx=%1" +rem ) rem Certificate to trust. rem -if "_%2_" == "__" ( - set "trust=" -) else ( - if "_%2_" == "_yes_" ( +if not "_%trust%_" == "__" ( + if "_%trust%_" == "_yes_" ( set "trust=--trust-yes" ) else ( - if "_%2_" == "_no_" ( + if "_%trust%_" == "_no_" ( set "trust=--trust-no" ) else ( - set "trust=--trust %2" + set "trust=--trust %trust%" ) ) ) +rem Network timeout. +rem +if not "_%timeout%_" == "__" ( + set "timeout=--fetch-timeout %timeout%" +) + if not exist %idir%\bin\ ( echo error: %idir%\bin\ does not exist goto error @@ -121,7 +164,7 @@ rem @rem Verify the compiler works. @rem -cl +%cxx% @if errorlevel 1 goto error @rem Bootstrap. @@ -130,13 +173,13 @@ cd build2 @rem Execute in a separate cmd.exe to preserve the echo mode. @rem -cmd /C bootstrap-msvc.bat cl +cmd /C bootstrap-msvc.bat %cxx% @if errorlevel 1 goto error build2\b-boot --version @if errorlevel 1 goto error -build2\b-boot config.cxx=cl config.bin.lib=static +build2\b-boot config.cxx=%cxx% config.bin.lib=static @if errorlevel 1 goto error move /y build2\b.exe build2\b-boot.exe @@ -150,7 +193,7 @@ build2\b-boot --version cd .. build2\build2\b-boot configure^ - config.cxx=cl^ + config.cxx=%cxx%^ config.bin.suffix=-stage^ config.install.root=%idir%^ config.install.data_root=root\stage @@ -186,7 +229,7 @@ cd %cdir% bpkg-stage create^ cc^ - config.cxx=cl^ + config.cxx=%cxx%^ "config.cc.coptions=/O2 /Oi"^ config.install.root=%idir% @if errorlevel 1 goto error diff --git a/build.sh b/build.sh index 97e9403..93ad113 100755 --- a/build.sh +++ b/build.sh @@ -54,7 +54,7 @@ while test $# -ne 0; do diag " --install-dir Alternative installation directory." diag " --sudo Optional sudo program to use." diag " --repo Alternative package repository location." - diag " --trust Certificate fingerprint to trust." + diag " --trust Repository certificate fingerprint to trust." diag " --timeout Network operations timeout in seconds." diag " --make Bootstrap using GNU make instead of script." diag -- cgit v1.1