From 5caacdf286eaaa95bf11d272d83ba808d9c44b69 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 28 Oct 2020 10:15:25 +0300 Subject: Install exact package versions and make bpkg and bdep optional in build scripts --- .gitignore | 6 + build-clang.bat | 398 ------------------------------------------ build-clang.bat.in | 461 ++++++++++++++++++++++++++++++++++++++++++++++++ build-mingw.bat | 408 ------------------------------------------- build-mingw.bat.in | 471 +++++++++++++++++++++++++++++++++++++++++++++++++ build-msvc.bat | 372 --------------------------------------- build-msvc.bat.in | 435 ++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 446 ----------------------------------------------- build.sh.in | 501 +++++++++++++++++++++++++++++++++++++++++++++++++++++ buildfile | 57 +++++- 10 files changed, 1930 insertions(+), 1625 deletions(-) delete mode 100644 build-clang.bat create mode 100644 build-clang.bat.in delete mode 100644 build-mingw.bat create mode 100644 build-mingw.bat.in delete mode 100644 build-msvc.bat create mode 100644 build-msvc.bat.in delete mode 100755 build.sh create mode 100644 build.sh.in diff --git a/.gitignore b/.gitignore index 68e3c03..a18d885 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ INSTALL UPGRADE BOOTSTRAP-* !BOOTSTRAP-*.cli + +# Building output. +# +*.d +build.sh +build-*.bat diff --git a/build-clang.bat b/build-clang.bat deleted file mode 100644 index 172c81c..0000000 --- a/build-clang.bat +++ /dev/null @@ -1,398 +0,0 @@ -@echo off - -rem file : build-clang.bat -rem license : MIT; see accompanying LICENSE file - -setlocal EnableDelayedExpansion -goto start - -:usage -echo. -echo Usage: %0 [/?] [^] [^] -echo Options: -echo --local Don't build from packages, only from local source. -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 --verbose ^ Diagnostics verbosity level between 0 and 6. -echo. -echo By default the batch file will use clang++.exe as the C++ compiler and -echo install into C:\build2. It also expects to find the base utilities in the -echo bin\ subdirectory of the installation directory ^(C:\build2\bin\ by -echo default^). -echo. -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 -echo additional make options, for example: -echo. -echo %0 --make mingw32-make --make -j8 -echo. -echo See the BOOTSTRAP-WINDOWS-CLANG file for details. -echo. -goto end - -:start - -set "owd=%CD%" - -rem Package repository URL (or path). -rem -if "_%BUILD2_REPO%_" == "__" ( - set "BUILD2_REPO=https://stage.build2.org/1" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/queue/alpha" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/alpha" -) - -rem The bpkg configuration directory. -rem -set "cver=0.14-a.0" -set "cdir=build2-toolchain-%cver%" - -rem Parse options. -rem -set "local=" -set "idir=C:\build2" -set "trust=" -set "timeout=" -set "make=" -set "verbose=" - -:options -if "_%~1_" == "_/?_" goto usage -if "_%~1_" == "_-h_" goto usage -if "_%~1_" == "_--help_" goto usage - -if "_%~1_" == "_--local_" ( - set "local=true" - shift - goto options -) - -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 - goto error - ) - set "timeout=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--make_" ( - if "_%~2_" == "__" ( - echo error: argument expected after --make - goto error - ) - set "make=%make% %~2" - shift - shift - goto options -) - -if "_%~1_" == "_--verbose_" ( - if "_%~2_" == "__" ( - echo error: diagnostics level between 0 and 6 expected after --verbose - goto error - ) - set "verbose=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--_" shift - -rem Validate options and arguments. -rem - -rem Compiler. -rem -if "_%1_" == "__" ( - set "cxx=clang++" -) else ( - set "cxx=%1" -) - -rem Convert a relative path to an absolute. -rem -for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" - -rem Certificate to trust. -rem -if not "_%trust%_" == "__" ( - if "_%trust%_" == "_yes_" ( - set "trust=--trust-yes" - ) else ( - if "_%trust%_" == "_no_" ( - set "trust=--trust-no" - ) else ( - set "trust=--trust %trust%" - ) - ) -) - -rem Network timeout. -rem -if not "_%timeout%_" == "__" ( - set "timeout=--fetch-timeout %timeout%" -) - -rem Diagnostics verbosity. -rem -if not "_%verbose%_" == "__" ( - set "verbose=--verbose %verbose%" -) - -if not exist %idir%\bin\ ( - echo error: %idir%\bin\ does not exist - goto error -) - -if exist build\config.build ( - echo error: current directory already configured, start with clean source - goto error -) - -if "_%local%_" == "__" ( - if exist ..\%cdir%\ ( - echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it - goto error - ) -) - -set "PATH=%idir%\bin;%PATH%" - -rem Show the steps we are performing. -rem -@echo on - -@rem Verify the compiler works. -@rem -%cxx% --version -@if errorlevel 1 goto error - -@rem Suppress loading of default options files. -@rem -set "BUILD2_DEF_OPT=0" -set "BPKG_DEF_OPT=0" -set "BDEP_DEF_OPT=0" - -@rem Bootstrap. -@rem -cd build2 - -@if "_%make%_" == "__" ( - goto batchfile -) else ( - goto makefile -) - -:batchfile -@rem Execute in a separate cmd.exe to preserve the echo mode. -@rem -cmd /C bootstrap-clang.bat %cxx% -@if errorlevel 1 goto error -@goto endfile - -:makefile -%make% -f bootstrap.gmake CXX=%cxx% -@if errorlevel 1 goto error -@goto endfile - -:endfile -build2\b-boot --version -@if errorlevel 1 goto error - -build2\b-boot %verbose% config.cxx=%cxx% config.cc.coptions=-m64 config.bin.lib=static build2\exe{b} -@if errorlevel 1 goto error - -move /y build2\b.exe build2\b-boot.exe -@if errorlevel 1 goto error - -build2\b-boot --version -@if errorlevel 1 goto error - -cd .. - -@rem Local installation early return. -@rem -@if "_%local%_" == "__" goto stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - "config.cc.coptions=-m64 -O2"^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ bdep\ -@if errorlevel 1 goto error - -where b -@if errorlevel 1 goto error - -where bpkg -@if errorlevel 1 goto error - -where bdep -@if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %owd% -echo. - -goto end - -@rem Build and stage the build system and the package manager. -@rem -:stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - config.cc.coptions=-m64^ - config.bin.lib=shared^ - config.bin.suffix=-stage^ - config.install.root=%idir%^ - config.install.data_root=root\stage -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ -@if errorlevel 1 goto error - -where b-stage -@if errorlevel 1 goto error - -where bpkg-stage -@if errorlevel 1 goto error - -b-stage --version -@if errorlevel 1 goto error - -bpkg-stage --version -@if errorlevel 1 goto error - -@rem Build the entire toolchain from packages. -@rem -cd .. - -md %cdir% -@if errorlevel 1 goto error - -cd %cdir% - -@rem Save full path for later. -@rem -@set "cdir=%CD%" - -bpkg-stage %verbose% create^ - cc^ - config.cxx=%cxx%^ - "config.cc.coptions=-m64 -O2"^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -bpkg-stage %verbose% add %BUILD2_REPO% -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% %trust% fetch -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% build --for install --yes --plan= build2 bpkg bdep -@if errorlevel 1 goto error - -bpkg-stage %verbose% install build2 bpkg bdep -@if errorlevel 1 goto error - -where b -@if errorlevel 1 goto error - -where bpkg -@if errorlevel 1 goto error - -where bdep -@if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@rem Clean up stage. -@rem -cd %owd% -b %verbose% uninstall: build2/ bpkg/ -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %cdir% -echo. - -goto end - -:error -@echo off -cd %owd% -endlocal -exit /b 1 - -:end -endlocal diff --git a/build-clang.bat.in b/build-clang.bat.in new file mode 100644 index 0000000..1a69072 --- /dev/null +++ b/build-clang.bat.in @@ -0,0 +1,461 @@ +@echo off + +rem file : build-clang.bat.in +rem license : MIT; see accompanying LICENSE file + +setlocal EnableDelayedExpansion +goto start + +:usage +echo. +echo Usage: %0 [/?] [^] [^] +echo Options: +echo --local Don't build from packages, only from local source. +echo --no-bpkg Don't install bpkg nor bdep (requires --local). +echo --no-bdep Don't install bdep. +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 --verbose ^ Diagnostics verbosity level between 0 and 6. +echo. +echo By default the batch file will use clang++.exe as the C++ compiler and +echo install into C:\build2. It also expects to find the base utilities in the +echo bin\ subdirectory of the installation directory ^(C:\build2\bin\ by +echo default^). +echo. +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 +echo additional make options, for example: +echo. +echo %0 --make mingw32-make --make -j8 +echo. +echo See the BOOTSTRAP-WINDOWS-CLANG file for details. +echo. +goto end + +:start + +set "owd=%CD%" + +rem Package repository URL (or path). +rem +if "_%BUILD2_REPO%_" == "__" ( + set "BUILD2_REPO=@BUILD2_REPO@" +) + +rem Package versions. +rem +set "build2_ver=@BUILD2_VERSION@" +set "bpkg_ver=@BPKG_VERSION@" +set "bdep_ver=@BDEP_VERSION@" + +rem The bpkg configuration directory. +rem +set "cver=@CONFIG_VER@" +set "cdir=build2-toolchain-%cver%" + +rem Parse options. +rem +set "local=" +set "bpkg=true" +set "bdep=true" +set "idir=C:\build2" +set "trust=" +set "timeout=" +set "make=" +set "verbose=" + +:options +if "_%~1_" == "_/?_" goto usage +if "_%~1_" == "_-h_" goto usage +if "_%~1_" == "_--help_" goto usage + +if "_%~1_" == "_--local_" ( + set "local=true" + shift + goto options +) + +if "_%~1_" == "_--no-bpkg_" ( + set "bpkg=" + shift + goto options +) + +if "_%~1_" == "_--no-bdep_" ( + set "bdep=" + shift + goto options +) + +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 + goto error + ) + set "timeout=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--make_" ( + if "_%~2_" == "__" ( + echo error: argument expected after --make + goto error + ) + set "make=%make% %~2" + shift + shift + goto options +) + +if "_%~1_" == "_--verbose_" ( + if "_%~2_" == "__" ( + echo error: diagnostics level between 0 and 6 expected after --verbose + goto error + ) + set "verbose=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--_" shift + +rem Validate options and arguments. +rem + +rem Compiler. +rem +if "_%1_" == "__" ( + set "cxx=clang++" +) else ( + set "cxx=%1" +) + +rem If --no-bpkg is specified, then we require --local to also be specified +rem since it won't be possible to build things from packages without bpkg. +rem Also imply --no-bdep in this case, since bdep is pretty much useless +rem without bpkg. +rem +if "_%bpkg%_" == "__" ( + if "_%local%_" == "__" ( + echo error: --no-bpkg can only be used for local installation + echo info: additionally specify --local + goto error + ) + + set "bdep=" +) + +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + +rem Certificate to trust. +rem +if not "_%trust%_" == "__" ( + if "_%trust%_" == "_yes_" ( + set "trust=--trust-yes" + ) else ( + if "_%trust%_" == "_no_" ( + set "trust=--trust-no" + ) else ( + set "trust=--trust %trust%" + ) + ) +) + +rem Network timeout. +rem +if not "_%timeout%_" == "__" ( + set "timeout=--fetch-timeout %timeout%" +) + +rem Diagnostics verbosity. +rem +if not "_%verbose%_" == "__" ( + set "verbose=--verbose %verbose%" +) + +if not exist %idir%\bin\ ( + echo error: %idir%\bin\ does not exist + goto error +) + +if exist build\config.build ( + echo error: current directory already configured, start with clean source + goto error +) + +if "_%local%_" == "__" ( + if exist ..\%cdir%\ ( + echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it + goto error + ) +) + +set "PATH=%idir%\bin;%PATH%" + +rem Show the steps we are performing. +rem +@echo on + +@rem Verify the compiler works. +@rem +%cxx% --version +@if errorlevel 1 goto error + +@rem Suppress loading of default options files. +@rem +set "BUILD2_DEF_OPT=0" +set "BPKG_DEF_OPT=0" +set "BDEP_DEF_OPT=0" + +@rem Bootstrap. +@rem +cd build2 + +@if "_%make%_" == "__" ( + goto batchfile +) else ( + goto makefile +) + +:batchfile +@rem Execute in a separate cmd.exe to preserve the echo mode. +@rem +cmd /C bootstrap-clang.bat %cxx% +@if errorlevel 1 goto error +@goto endfile + +:makefile +%make% -f bootstrap.gmake CXX=%cxx% +@if errorlevel 1 goto error +@goto endfile + +:endfile +build2\b-boot --version +@if errorlevel 1 goto error + +build2\b-boot %verbose% config.cxx=%cxx% config.cc.coptions=-m64 config.bin.lib=static build2\exe{b} +@if errorlevel 1 goto error + +move /y build2\b.exe build2\b-boot.exe +@if errorlevel 1 goto error + +build2\b-boot --version +@if errorlevel 1 goto error + +cd .. + +@rem Local installation early return. +@rem +@if "_%local%_" == "__" goto stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + "config.cc.coptions=-m64 -O2"^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +@set "projects=build2/" + +@if "_%bpkg%_" == "_true_" ( + set "projects=%projects% bpkg/" +) + +@if "_%bdep%_" == "_true_" ( + set "projects=%projects% bdep/" +) + +build2\build2\b-boot %verbose% install: %projects% +@if errorlevel 1 goto error + +where b +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +@if "_%bpkg%_" == "__" goto bpkg_vle + +where bpkg +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +:bpkg_vle + +@if "_%bdep%_" == "__" goto bdep_vle + +where bdep +@if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vle + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %owd% +echo. + +goto end + +@rem Build and stage the build system and the package manager. +@rem +:stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + config.cc.coptions=-m64^ + config.bin.lib=shared^ + config.bin.suffix=-stage^ + config.install.root=%idir%^ + config.install.data_root=root\stage +@if errorlevel 1 goto error + +build2\build2\b-boot %verbose% install: build2\ bpkg\ +@if errorlevel 1 goto error + +where b-stage +@if errorlevel 1 goto error + +b-stage --version +@if errorlevel 1 goto error + +where bpkg-stage +@if errorlevel 1 goto error + +bpkg-stage --version +@if errorlevel 1 goto error + +@rem Build the entire toolchain from packages. +@rem +cd .. + +md %cdir% +@if errorlevel 1 goto error + +cd %cdir% + +@rem Save full path for later. +@rem +@set "cdir=%CD%" + +bpkg-stage %verbose% create^ + cc^ + config.cxx=%cxx%^ + "config.cc.coptions=-m64 -O2"^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +bpkg-stage %verbose% add %BUILD2_REPO% +@if errorlevel 1 goto error + +bpkg-stage %verbose% %timeout% %trust% fetch +@if errorlevel 1 goto error + +@set "packages=build2/%build2_ver% bpkg/%bpkg_ver%" + +@if "_%bdep%_" == "_true_" ( + set "packages=%packages% bdep/%bdep_ver%" +) + +bpkg-stage %verbose% %timeout% build --for install --yes --plan= %packages% +@if errorlevel 1 goto error + +bpkg-stage %verbose% install --all +@if errorlevel 1 goto error + +where b +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +where bpkg +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +@if "_%bdep%_" == "__" goto bdep_vpe + +where bdep +@if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vpe + +@rem Clean up stage. +@rem +cd %owd% +b %verbose% uninstall: build2/ bpkg/ +@if errorlevel 1 goto error + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %cdir% +echo. + +goto end + +:error +@echo off +cd %owd% +endlocal +exit /b 1 + +:end +endlocal diff --git a/build-mingw.bat b/build-mingw.bat deleted file mode 100644 index 067d517..0000000 --- a/build-mingw.bat +++ /dev/null @@ -1,408 +0,0 @@ -@echo off - -rem file : build-mingw.bat -rem license : MIT; see accompanying LICENSE file - -setlocal EnableDelayedExpansion -goto start - -:usage -echo. -echo Usage: %0 [/?] [^] ^ -echo Options: -echo --local Don't build from packages, only from local source. -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 --verbose ^ Diagnostics verbosity level between 0 and 6. -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 --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 -echo additional make options, for example: -echo. -echo %0 --make mingw32-make --make -j8 g++ -echo. -echo See the BOOTSTRAP-WINDOWS-MINGW file for details. -echo. -goto end - -:start - -set "owd=%CD%" - -rem Package repository URL (or path). -rem -if "_%BUILD2_REPO%_" == "__" ( - set "BUILD2_REPO=https://stage.build2.org/1" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/queue/alpha" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/alpha" -) - -rem The bpkg configuration directory. -rem -set "cver=0.14-a.0" -set "cdir=build2-toolchain-%cver%" - -rem Parse options. -rem -set "local=" -set "idir=C:\build2" -set "trust=" -set "timeout=" -set "make=" -set "verbose=" - -:options -if "_%~1_" == "_/?_" goto usage -if "_%~1_" == "_-h_" goto usage -if "_%~1_" == "_--help_" goto usage - -if "_%~1_" == "_--local_" ( - set "local=true" - shift - goto options -) - -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 - goto error - ) - set "timeout=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--make_" ( - if "_%~2_" == "__" ( - echo error: argument expected after --make - goto error - ) - set "make=%make% %~2" - shift - shift - goto options -) - -if "_%~1_" == "_--verbose_" ( - if "_%~2_" == "__" ( - echo error: diagnostics level between 0 and 6 expected after --verbose - goto error - ) - set "verbose=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--_" shift - -rem Validate options and arguments. -rem - -rem Compiler. -rem -if "_%1_" == "__" ( - echo error: compiler executable expected, run %0 /? for details - goto error -) else ( - set "cxx=%1" -) - -rem @@ Temporarily retained for backwards compatibility. -rem -if not "_%2_" == "__" ( - set "idir=%2" -) -if not "_%3_" == "__" ( - set "trust=%3" -) - -rem Convert a relative path to an absolute. -rem -for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" - -rem Certificate to trust. -rem -if not "_%trust%_" == "__" ( - if "_%trust%_" == "_yes_" ( - set "trust=--trust-yes" - ) else ( - if "_%trust%_" == "_no_" ( - set "trust=--trust-no" - ) else ( - set "trust=--trust %trust%" - ) - ) -) - -rem Network timeout. -rem -if not "_%timeout%_" == "__" ( - set "timeout=--fetch-timeout %timeout%" -) - -rem Diagnostics verbosity. -rem -if not "_%verbose%_" == "__" ( - set "verbose=--verbose %verbose%" -) - -if not exist %idir%\bin\ ( - echo error: %idir%\bin\ does not exist - goto error -) - -if exist build\config.build ( - echo error: current directory already configured, start with clean source - goto error -) - -if "_%local%_" == "__" ( - if exist ..\%cdir%\ ( - echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it - goto error - ) -) - -set "PATH=%idir%\bin;%PATH%" - -rem Show the steps we are performing. -rem -@echo on - -@rem Verify the compiler works. -@rem -%cxx% --version -@if errorlevel 1 goto error - -@rem Suppress loading of default options files. -@rem -set "BUILD2_DEF_OPT=0" -set "BPKG_DEF_OPT=0" -set "BDEP_DEF_OPT=0" - -@rem Bootstrap. -@rem -cd build2 - -@if "_%make%_" == "__" ( - goto batchfile -) else ( - goto makefile -) - -:batchfile -@rem Execute in a separate cmd.exe to preserve the echo mode. -@rem -cmd /C bootstrap-mingw.bat %cxx% -static -@if errorlevel 1 goto error -@goto endfile - -:makefile -%make% -f bootstrap.gmake CXX=%cxx% LDFLAGS=-static -@if errorlevel 1 goto error -@goto endfile - -:endfile -build2\b-boot --version -@if errorlevel 1 goto error - -build2\b-boot %verbose% config.cxx=%cxx% config.bin.lib=static build2\exe{b} -@if errorlevel 1 goto error - -move /y build2\b.exe build2\b-boot.exe -@if errorlevel 1 goto error - -build2\b-boot --version -@if errorlevel 1 goto error - -cd .. - -@rem Local installation early return. -@rem -@if "_%local%_" == "__" goto stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - config.cc.coptions=-O3^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ bdep\ -@if errorlevel 1 goto error - -where b -@if errorlevel 1 goto error - -where bpkg -@if errorlevel 1 goto error - -where bdep -@if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %owd% -echo. - -goto end - -@rem Build and stage the build system and the package manager. -@rem -:stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - config.bin.lib=shared^ - config.bin.suffix=-stage^ - config.install.root=%idir%^ - config.install.data_root=root\stage -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ -@if errorlevel 1 goto error - -@rem The where command is not available on XP without the resource kit. -@rem -where b-stage -@rem @if errorlevel 1 goto error - -where bpkg-stage -@rem @if errorlevel 1 goto error - -b-stage --version -@if errorlevel 1 goto error - -bpkg-stage --version -@if errorlevel 1 goto error - -@rem Build the entire toolchain from packages. -@rem -cd .. - -md %cdir% -@if errorlevel 1 goto error - -cd %cdir% - -@rem Save full path for later. -@rem -@set "cdir=%CD%" - -bpkg-stage %verbose% create^ - cc^ - config.cxx=%cxx%^ - config.cc.coptions=-O3^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -bpkg-stage %verbose% add %BUILD2_REPO% -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% %trust% fetch -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% build --for install --yes --plan= build2 bpkg bdep -@if errorlevel 1 goto error - -bpkg-stage %verbose% install build2 bpkg bdep -@if errorlevel 1 goto error - -where b -@rem @if errorlevel 1 goto error - -where bpkg -@rem @if errorlevel 1 goto error - -where bdep -@rem @if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@rem Clean up stage. -@rem -cd %owd% -b %verbose% uninstall: build2\ bpkg\ -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %cdir% -echo. - -goto end - -:error -@echo off -cd %owd% -endlocal -exit /b 1 - -:end -endlocal diff --git a/build-mingw.bat.in b/build-mingw.bat.in new file mode 100644 index 0000000..caf3a51 --- /dev/null +++ b/build-mingw.bat.in @@ -0,0 +1,471 @@ +@echo off + +rem file : build-mingw.bat.in +rem license : MIT; see accompanying LICENSE file + +setlocal EnableDelayedExpansion +goto start + +:usage +echo. +echo Usage: %0 [/?] [^] ^ +echo Options: +echo --local Don't build from packages, only from local source. +echo --no-bpkg Don't install bpkg nor bdep (requires --local). +echo --no-bdep Don't install bdep. +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 --verbose ^ Diagnostics verbosity level between 0 and 6. +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 --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 +echo additional make options, for example: +echo. +echo %0 --make mingw32-make --make -j8 g++ +echo. +echo See the BOOTSTRAP-WINDOWS-MINGW file for details. +echo. +goto end + +:start + +set "owd=%CD%" + +rem Package repository URL (or path). +rem +if "_%BUILD2_REPO%_" == "__" ( + set "BUILD2_REPO=@BUILD2_REPO@" +) + +rem Package versions. +rem +set "build2_ver=@BUILD2_VERSION@" +set "bpkg_ver=@BPKG_VERSION@" +set "bdep_ver=@BDEP_VERSION@" + +rem The bpkg configuration directory. +rem +set "cver=@CONFIG_VER@" +set "cdir=build2-toolchain-%cver%" + +rem Parse options. +rem +set "local=" +set "bpkg=true" +set "bdep=true" +set "idir=C:\build2" +set "trust=" +set "timeout=" +set "make=" +set "verbose=" + +:options +if "_%~1_" == "_/?_" goto usage +if "_%~1_" == "_-h_" goto usage +if "_%~1_" == "_--help_" goto usage + +if "_%~1_" == "_--local_" ( + set "local=true" + shift + goto options +) + +if "_%~1_" == "_--no-bpkg_" ( + set "bpkg=" + shift + goto options +) + +if "_%~1_" == "_--no-bdep_" ( + set "bdep=" + shift + goto options +) + +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 + goto error + ) + set "timeout=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--make_" ( + if "_%~2_" == "__" ( + echo error: argument expected after --make + goto error + ) + set "make=%make% %~2" + shift + shift + goto options +) + +if "_%~1_" == "_--verbose_" ( + if "_%~2_" == "__" ( + echo error: diagnostics level between 0 and 6 expected after --verbose + goto error + ) + set "verbose=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--_" shift + +rem Validate options and arguments. +rem + +rem Compiler. +rem +if "_%1_" == "__" ( + echo error: compiler executable expected, run %0 /? for details + goto error +) else ( + set "cxx=%1" +) + +rem @@ Temporarily retained for backwards compatibility. +rem +if not "_%2_" == "__" ( + set "idir=%2" +) +if not "_%3_" == "__" ( + set "trust=%3" +) + +rem If --no-bpkg is specified, then we require --local to also be specified +rem since it won't be possible to build things from packages without bpkg. +rem Also imply --no-bdep in this case, since bdep is pretty much useless +rem without bpkg. +rem +if "_%bpkg%_" == "__" ( + if "_%local%_" == "__" ( + echo error: --no-bpkg can only be used for local installation + echo info: additionally specify --local + goto error + ) + + set "bdep=" +) + +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + +rem Certificate to trust. +rem +if not "_%trust%_" == "__" ( + if "_%trust%_" == "_yes_" ( + set "trust=--trust-yes" + ) else ( + if "_%trust%_" == "_no_" ( + set "trust=--trust-no" + ) else ( + set "trust=--trust %trust%" + ) + ) +) + +rem Network timeout. +rem +if not "_%timeout%_" == "__" ( + set "timeout=--fetch-timeout %timeout%" +) + +rem Diagnostics verbosity. +rem +if not "_%verbose%_" == "__" ( + set "verbose=--verbose %verbose%" +) + +if not exist %idir%\bin\ ( + echo error: %idir%\bin\ does not exist + goto error +) + +if exist build\config.build ( + echo error: current directory already configured, start with clean source + goto error +) + +if "_%local%_" == "__" ( + if exist ..\%cdir%\ ( + echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it + goto error + ) +) + +set "PATH=%idir%\bin;%PATH%" + +rem Show the steps we are performing. +rem +@echo on + +@rem Verify the compiler works. +@rem +%cxx% --version +@if errorlevel 1 goto error + +@rem Suppress loading of default options files. +@rem +set "BUILD2_DEF_OPT=0" +set "BPKG_DEF_OPT=0" +set "BDEP_DEF_OPT=0" + +@rem Bootstrap. +@rem +cd build2 + +@if "_%make%_" == "__" ( + goto batchfile +) else ( + goto makefile +) + +:batchfile +@rem Execute in a separate cmd.exe to preserve the echo mode. +@rem +cmd /C bootstrap-mingw.bat %cxx% -static +@if errorlevel 1 goto error +@goto endfile + +:makefile +%make% -f bootstrap.gmake CXX=%cxx% LDFLAGS=-static +@if errorlevel 1 goto error +@goto endfile + +:endfile +build2\b-boot --version +@if errorlevel 1 goto error + +build2\b-boot %verbose% config.cxx=%cxx% config.bin.lib=static build2\exe{b} +@if errorlevel 1 goto error + +move /y build2\b.exe build2\b-boot.exe +@if errorlevel 1 goto error + +build2\b-boot --version +@if errorlevel 1 goto error + +cd .. + +@rem Local installation early return. +@rem +@if "_%local%_" == "__" goto stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + config.cc.coptions=-O3^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +@set "projects=build2/" + +@if "_%bpkg%_" == "_true_" ( + set "projects=%projects% bpkg/" +) + +@if "_%bdep%_" == "_true_" ( + set "projects=%projects% bdep/" +) + +build2\build2\b-boot %verbose% install: %projects% +@if errorlevel 1 goto error + +@rem The where command is not available on XP without the resource kit. +@rem +where b +rem @if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +@if "_%bpkg%_" == "__" goto bpkg_vle + +where bpkg +rem @if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +:bpkg_vle + +@if "_%bdep%_" == "__" goto bdep_vle + +where bdep +rem @if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vle + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %owd% +echo. + +goto end + +@rem Build and stage the build system and the package manager. +@rem +:stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + config.bin.lib=shared^ + config.bin.suffix=-stage^ + config.install.root=%idir%^ + config.install.data_root=root\stage +@if errorlevel 1 goto error + +build2\build2\b-boot %verbose% install: build2\ bpkg\ +@if errorlevel 1 goto error + +where b-stage +@rem @if errorlevel 1 goto error + +b-stage --version +@if errorlevel 1 goto error + +where bpkg-stage +@rem @if errorlevel 1 goto error + +bpkg-stage --version +@if errorlevel 1 goto error + +@rem Build the entire toolchain from packages. +@rem +cd .. + +md %cdir% +@if errorlevel 1 goto error + +cd %cdir% + +@rem Save full path for later. +@rem +@set "cdir=%CD%" + +bpkg-stage %verbose% create^ + cc^ + config.cxx=%cxx%^ + config.cc.coptions=-O3^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +bpkg-stage %verbose% add %BUILD2_REPO% +@if errorlevel 1 goto error + +bpkg-stage %verbose% %timeout% %trust% fetch +@if errorlevel 1 goto error + +@set "packages=build2/%build2_ver% bpkg/%bpkg_ver%" + +@if "_%bdep%_" == "_true_" ( + set "packages=%packages% bdep/%bdep_ver%" +) + +bpkg-stage %verbose% %timeout% build --for install --yes --plan= %packages% +@if errorlevel 1 goto error + +bpkg-stage %verbose% install --all +@if errorlevel 1 goto error + +where b +@rem @if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +where bpkg +@rem @if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +@if "_%bdep%_" == "__" goto bdep_vpe + +where bdep +@rem @if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vpe + +@rem Clean up stage. +@rem +cd %owd% +b %verbose% uninstall: build2\ bpkg\ +@if errorlevel 1 goto error + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %cdir% +echo. + +goto end + +:error +@echo off +cd %owd% +endlocal +exit /b 1 + +:end +endlocal diff --git a/build-msvc.bat b/build-msvc.bat deleted file mode 100644 index 1060e25..0000000 --- a/build-msvc.bat +++ /dev/null @@ -1,372 +0,0 @@ -@echo off - -rem file : build-msvc.bat -rem license : MIT; see accompanying LICENSE file - -setlocal EnableDelayedExpansion -goto start - -:usage -echo. -rem echo Usage: %0 [/?] [^] [^] -echo Usage: %0 [/?] [^] -echo Options: -echo --local Don't build from packages, only from local source. -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 --verbose ^ Diagnostics verbosity level between 0 and 6. -echo. -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 --trust option recognizes two special values: 'yes' ^(trust everything^) -echo and 'no' (trust nothing). -echo. -echo See the BOOTSTRAP-WINDOWS-MSVC file for details. -echo. -goto end - -:start - -set "owd=%CD%" - -rem Package repository URL (or path). -rem -if "_%BUILD2_REPO%_" == "__" ( - set "BUILD2_REPO=https://stage.build2.org/1" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/queue/alpha" -rem set "BUILD2_REPO=https://pkg.cppget.org/1/alpha" -) - -rem The bpkg configuration directory. -rem -set "cver=0.14-a.0" -set "cdir=build2-toolchain-%cver%" - -rem Parse options. -rem -set "local=" -set "idir=C:\build2" -set "trust=" -set "timeout=" -set "verbose=" - -:options -if "_%~1_" == "_/?_" goto usage -if "_%~1_" == "_-h_" goto usage -if "_%~1_" == "_--help_" goto usage - -if "_%~1_" == "_--local_" ( - set "local=true" - shift - goto options -) - -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 - goto error - ) - set "timeout=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--verbose_" ( - if "_%~2_" == "__" ( - echo error: diagnostics level between 0 and 6 expected after --verbose - goto error - ) - set "verbose=%~2" - shift - shift - goto options -) - -if "_%~1_" == "_--_" shift - -rem Validate options and arguments. -rem - -rem @@ Temporarily retained for backwards compatibility. -rem -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 Convert a relative path to an absolute. -rem -for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" - -rem Certificate to trust. -rem -if not "_%trust%_" == "__" ( - if "_%trust%_" == "_yes_" ( - set "trust=--trust-yes" - ) else ( - if "_%trust%_" == "_no_" ( - set "trust=--trust-no" - ) else ( - set "trust=--trust %trust%" - ) - ) -) - -rem Network timeout. -rem -if not "_%timeout%_" == "__" ( - set "timeout=--fetch-timeout %timeout%" -) - -rem Diagnostics verbosity. -rem -if not "_%verbose%_" == "__" ( - set "verbose=--verbose %verbose%" -) - -if not exist %idir%\bin\ ( - echo error: %idir%\bin\ does not exist - goto error -) - -if exist build\config.build ( - echo error: current directory already configured, start with clean source - goto error -) - -if "_%local%_" == "__" ( - if exist ..\%cdir%\ ( - echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it - goto error - ) -) - -set "PATH=%idir%\bin;%PATH%" - -rem Show the steps we are performing. -rem -@echo on - -@rem Verify the compiler works. -@rem -%cxx% -@if errorlevel 1 goto error - -@rem Suppress loading of default options files. -@rem -set "BUILD2_DEF_OPT=0" -set "BPKG_DEF_OPT=0" -set "BDEP_DEF_OPT=0" - -@rem Bootstrap. -@rem -cd build2 - -@rem Execute in a separate cmd.exe to preserve the echo mode. -@rem -cmd /C bootstrap-msvc.bat %cxx% -@if errorlevel 1 goto error - -build2\b-boot --version -@if errorlevel 1 goto error - -build2\b-boot %verbose% config.cxx=%cxx% config.bin.lib=static build2\exe{b} -@if errorlevel 1 goto error - -move /y build2\b.exe build2\b-boot.exe -@if errorlevel 1 goto error - -build2\b-boot --version -@if errorlevel 1 goto error - -cd .. - -@rem Local installation early return. -@rem -@if "_%local%_" == "__" goto stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - config.cc.coptions=/O2^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ bdep\ -@if errorlevel 1 goto error - -where b -@if errorlevel 1 goto error - -where bpkg -@if errorlevel 1 goto error - -where bdep -@if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %owd% -echo. - -goto end - -@rem Build and stage the build system and the package manager. -@rem -:stage - -build2\build2\b-boot %verbose% configure^ - config.cxx=%cxx%^ - config.bin.lib=shared^ - config.bin.suffix=-stage^ - config.install.root=%idir%^ - config.install.data_root=root\stage -@if errorlevel 1 goto error - -build2\build2\b-boot %verbose% install: build2\ bpkg\ -@if errorlevel 1 goto error - -where b-stage -@if errorlevel 1 goto error - -where bpkg-stage -@if errorlevel 1 goto error - -b-stage --version -@if errorlevel 1 goto error - -bpkg-stage --version -@if errorlevel 1 goto error - -@rem Build the entire toolchain from packages. -@rem -cd .. - -md %cdir% -@if errorlevel 1 goto error - -cd %cdir% - -@rem Save full path for later. -@rem -@set "cdir=%CD%" - -bpkg-stage %verbose% create^ - cc^ - config.cxx=%cxx%^ - config.cc.coptions=/O2^ - config.bin.lib=shared^ - config.install.root=%idir% -@if errorlevel 1 goto error - -bpkg-stage %verbose% add %BUILD2_REPO% -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% %trust% fetch -@if errorlevel 1 goto error - -bpkg-stage %verbose% %timeout% build --for install --yes --plan= build2 bpkg bdep -@if errorlevel 1 goto error - -bpkg-stage %verbose% install build2 bpkg bdep -@if errorlevel 1 goto error - -where b -@if errorlevel 1 goto error - -where bpkg -@if errorlevel 1 goto error - -where bdep -@if errorlevel 1 goto error - -b --version -@if errorlevel 1 goto error - -bpkg --version -@if errorlevel 1 goto error - -bdep --version -@if errorlevel 1 goto error - -@rem Clean up stage. -@rem -cd %owd% -b %verbose% uninstall: build2/ bpkg/ -@if errorlevel 1 goto error - -@echo off - -echo. -echo Toolchain installation: %idir%\bin -echo Build configuration: %cdir% -echo. - -goto end - -:error -@echo off -cd %owd% -endlocal -exit /b 1 - -:end -endlocal diff --git a/build-msvc.bat.in b/build-msvc.bat.in new file mode 100644 index 0000000..f94e2c2 --- /dev/null +++ b/build-msvc.bat.in @@ -0,0 +1,435 @@ +@echo off + +rem file : build-msvc.bat.in +rem license : MIT; see accompanying LICENSE file + +setlocal EnableDelayedExpansion +goto start + +:usage +echo. +rem echo Usage: %0 [/?] [^] [^] +echo Usage: %0 [/?] [^] +echo Options: +echo --local Don't build from packages, only from local source. +echo --no-bpkg Don't install bpkg nor bdep (requires --local). +echo --no-bdep Don't install bdep. +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 --verbose ^ Diagnostics verbosity level between 0 and 6. +echo. +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 --trust option recognizes two special values: 'yes' ^(trust everything^) +echo and 'no' (trust nothing). +echo. +echo See the BOOTSTRAP-WINDOWS-MSVC file for details. +echo. +goto end + +:start + +set "owd=%CD%" + +rem Package repository URL (or path). +rem +if "_%BUILD2_REPO%_" == "__" ( + set "BUILD2_REPO=@BUILD2_REPO@" +) + +rem Package versions. +rem +set "build2_ver=@BUILD2_VERSION@" +set "bpkg_ver=@BPKG_VERSION@" +set "bdep_ver=@BDEP_VERSION@" + +rem The bpkg configuration directory. +rem +set "cver=@CONFIG_VER@" +set "cdir=build2-toolchain-%cver%" + +rem Parse options. +rem +set "local=" +set "bpkg=true" +set "bdep=true" +set "idir=C:\build2" +set "trust=" +set "timeout=" +set "verbose=" + +:options +if "_%~1_" == "_/?_" goto usage +if "_%~1_" == "_-h_" goto usage +if "_%~1_" == "_--help_" goto usage + +if "_%~1_" == "_--local_" ( + set "local=true" + shift + goto options +) + +if "_%~1_" == "_--no-bpkg_" ( + set "bpkg=" + shift + goto options +) + +if "_%~1_" == "_--no-bdep_" ( + set "bdep=" + shift + goto options +) + +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 + goto error + ) + set "timeout=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--verbose_" ( + if "_%~2_" == "__" ( + echo error: diagnostics level between 0 and 6 expected after --verbose + goto error + ) + set "verbose=%~2" + shift + shift + goto options +) + +if "_%~1_" == "_--_" shift + +rem Validate options and arguments. +rem + +rem @@ Temporarily retained for backwards compatibility. +rem +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 If --no-bpkg is specified, then we require --local to also be specified +rem since it won't be possible to build things from packages without bpkg. +rem Also imply --no-bdep in this case, since bdep is pretty much useless +rem without bpkg. +rem +if "_%bpkg%_" == "__" ( + if "_%local%_" == "__" ( + echo error: --no-bpkg can only be used for local installation + echo info: additionally specify --local + goto error + ) + + set "bdep=" +) + +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + +rem Certificate to trust. +rem +if not "_%trust%_" == "__" ( + if "_%trust%_" == "_yes_" ( + set "trust=--trust-yes" + ) else ( + if "_%trust%_" == "_no_" ( + set "trust=--trust-no" + ) else ( + set "trust=--trust %trust%" + ) + ) +) + +rem Network timeout. +rem +if not "_%timeout%_" == "__" ( + set "timeout=--fetch-timeout %timeout%" +) + +rem Diagnostics verbosity. +rem +if not "_%verbose%_" == "__" ( + set "verbose=--verbose %verbose%" +) + +if not exist %idir%\bin\ ( + echo error: %idir%\bin\ does not exist + goto error +) + +if exist build\config.build ( + echo error: current directory already configured, start with clean source + goto error +) + +if "_%local%_" == "__" ( + if exist ..\%cdir%\ ( + echo error: ..\%cdir%\ bpkg configuration directory already exists, remove it + goto error + ) +) + +set "PATH=%idir%\bin;%PATH%" + +rem Show the steps we are performing. +rem +@echo on + +@rem Verify the compiler works. +@rem +%cxx% +@if errorlevel 1 goto error + +@rem Suppress loading of default options files. +@rem +set "BUILD2_DEF_OPT=0" +set "BPKG_DEF_OPT=0" +set "BDEP_DEF_OPT=0" + +@rem Bootstrap. +@rem +cd build2 + +@rem Execute in a separate cmd.exe to preserve the echo mode. +@rem +cmd /C bootstrap-msvc.bat %cxx% +@if errorlevel 1 goto error + +build2\b-boot --version +@if errorlevel 1 goto error + +build2\b-boot %verbose% config.cxx=%cxx% config.bin.lib=static build2\exe{b} +@if errorlevel 1 goto error + +move /y build2\b.exe build2\b-boot.exe +@if errorlevel 1 goto error + +build2\b-boot --version +@if errorlevel 1 goto error + +cd .. + +@rem Local installation early return. +@rem +@if "_%local%_" == "__" goto stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + config.cc.coptions=/O2^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +@set "projects=build2/" + +@if "_%bpkg%_" == "_true_" ( + set "projects=%projects% bpkg/" +) + +@if "_%bdep%_" == "_true_" ( + set "projects=%projects% bdep/" +) + +build2\build2\b-boot %verbose% install: %projects% +@if errorlevel 1 goto error + +where b +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +@if "_%bpkg%_" == "__" goto bpkg_vle + +where bpkg +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +:bpkg_vle + +@if "_%bdep%_" == "__" goto bdep_vle + +where bdep +@if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vle + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %owd% +echo. + +goto end + +@rem Build and stage the build system and the package manager. +@rem +:stage + +build2\build2\b-boot %verbose% configure^ + config.cxx=%cxx%^ + config.bin.lib=shared^ + config.bin.suffix=-stage^ + config.install.root=%idir%^ + config.install.data_root=root\stage +@if errorlevel 1 goto error + +build2\build2\b-boot %verbose% install: build2\ bpkg\ +@if errorlevel 1 goto error + +where b-stage +@if errorlevel 1 goto error + +b-stage --version +@if errorlevel 1 goto error + +where bpkg-stage +@if errorlevel 1 goto error + +bpkg-stage --version +@if errorlevel 1 goto error + +@rem Build the entire toolchain from packages. +@rem +cd .. + +md %cdir% +@if errorlevel 1 goto error + +cd %cdir% + +@rem Save full path for later. +@rem +@set "cdir=%CD%" + +bpkg-stage %verbose% create^ + cc^ + config.cxx=%cxx%^ + config.cc.coptions=/O2^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +bpkg-stage %verbose% add %BUILD2_REPO% +@if errorlevel 1 goto error + +bpkg-stage %verbose% %timeout% %trust% fetch +@if errorlevel 1 goto error + +@set "packages=build2/%build2_ver% bpkg/%bpkg_ver%" + +@if "_%bdep%_" == "_true_" ( + set "packages=%packages% bdep/%bdep_ver%" +) + +bpkg-stage %verbose% %timeout% build --for install --yes --plan= %packages% +@if errorlevel 1 goto error + +bpkg-stage %verbose% install --all +@if errorlevel 1 goto error + +where b +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +where bpkg +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +@if "_%bdep%_" == "__" goto bdep_vpe + +where bdep +@if errorlevel 1 goto error + +bdep --version +@if errorlevel 1 goto error + +:bdep_vpe + +@rem Clean up stage. +@rem +cd %owd% +b %verbose% uninstall: build2/ bpkg/ +@if errorlevel 1 goto error + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Build configuration: %cdir% +echo. + +goto end + +:error +@echo off +cd %owd% +endlocal +exit /b 1 + +:end +endlocal diff --git a/build.sh b/build.sh deleted file mode 100755 index 58d944a..0000000 --- a/build.sh +++ /dev/null @@ -1,446 +0,0 @@ -#!/bin/sh - -# file : build.sh -# license : MIT; see accompanying LICENSE file - -usage="Usage: $0 [-h|--help] [] []" - -# Package repository URL (or path). -# -if test -z "$BUILD2_REPO"; then - BUILD2_REPO="https://stage.build2.org/1" -# BUILD2_REPO="https://pkg.cppget.org/1/queue/alpha" -# BUILD2_REPO="https://pkg.cppget.org/1/alpha" -fi - -# The bpkg configuration directory. -# -cver="0.14-a.0" -cdir="build2-toolchain-$cver" - -diag () -{ - echo "$*" 1>&2 -} - -# Note that this function will execute a command with arguments that contain -# spaces but it will not print them as quoted (and neither does set -x). -# -run () -{ - diag "+ $@" - "$@" - if test "$?" -ne "0"; then - exit 1 - fi -} - -owd="$(pwd)" - -local= -private= -idir= -jobs= -sudo= -trust= -timeout= -make= -make_options= -verbose= - -cxx= - -while test $# -ne 0; do - case "$1" in - -h|--help) - diag - diag "$usage" - diag "Options:" - diag " --local Don't build from packages, only from local source." - diag " --install-dir Alternative installation directory." - diag " --sudo Optional sudo program to use (pass false to disable)." - diag " --private Install shared libraries into private subdirectory." - diag " --jobs|-j Number of jobs to perform in parallel." - diag " --repo Alternative package repository location." - diag " --trust Repository certificate fingerprint to trust." - diag " --timeout Network operations timeout in seconds." - diag " --make Bootstrap using GNU make instead of script." - diag " --verbose Diagnostics verbosity level between 0 and 6." - diag - diag "By default the script will install into /usr/local with private" - diag "library subdirectories and using sudo(1). To enable private" - diag "subdirectories and/or use sudo for a custom installation location," - diag "you need to specify --private and/or --sudo explicitly, for example:" - diag - diag "$0 --install-dir /opt/build2 --sudo sudo g++" - diag - diag "If --jobs|-j is unspecified, then the bootstrap step is performed" - diag "serially with the rest of the process using the number of available" - diag "hardware threads." - diag - diag "The --trust option recognizes two special values: 'yes' (trust" - diag "everything) and 'no' (trust nothing)." - diag - diag "The --make option can be used to bootstrap using GNU make. The" - diag "first --make value should specify the make executable optionally" - diag "followed by additional make options, for example:" - diag - diag "$0 --make make --make -j8 g++" - diag - diag "If --jobs|-j is specified, then its value is passed to make before" - diag "any additional options." - diag - diag "If specified, override the default (-O3) compile" - diag "options (config.cc.coptions) in the bpkg configuration used to build" - diag "and install the final toolchain. For example, to build with the debug" - diag "information (and without optimization):" - diag - diag "$0 g++ -g" - diag - diag "See the BOOTSTRAP-UNIX file for details." - diag - exit 0 - ;; - --local) - local=true - shift - ;; - --private) - private=config.install.private=build2 - shift - ;; - --install-dir) - shift - if test $# -eq 0; then - diag "error: installation directory expected after --install-dir" - diag "$usage" - exit 1 - fi - idir="$1" - shift - ;; - -j|--jobs) - shift - if test $# -eq 0; then - diag "error: number of jobs expected after --jobs|-j" - diag "$usage" - exit 1 - fi - jobs="-j $1" - shift - ;; - --sudo) - shift - if test $# -eq 0; then - diag "error: sudo program expected after --sudo" - diag "$usage" - exit 1 - fi - sudo="$1" - shift - ;; - --repo) - shift - if test $# -eq 0; then - diag "error: repository location expected after --repo" - diag "$usage" - exit 1 - fi - BUILD2_REPO="$1" - shift - ;; - --trust) - shift - if test $# -eq 0; then - diag "error: certificate fingerprint expected after --trust" - diag "$usage" - exit 1 - fi - trust="$1" - shift - ;; - --timeout) - shift - if test $# -eq 0; then - diag "error: value in seconds expected after --timeout" - diag "$usage" - exit 1 - fi - timeout="$1" - shift - ;; - --make) - shift - if test $# -eq 0; then - diag "error: argument expected after --make" - diag "$usage" - exit 1 - fi - if test -z "$make"; then - make="$1" - else - make_options="$make_options $1" - fi - shift - ;; - --verbose) - shift - if test $# -eq 0; then - diag "error: diagnostics level between 0 and 6 expected after --verbose" - diag "$usage" - exit 1 - fi - verbose="$1" - shift - ;; - *) - cxx="$1" - shift - break - ;; - esac -done - -if test -z "$cxx"; then - diag "error: compiler executable expected" - diag "$usage" - exit 1 -fi - -# Place default into the $@ array. -# -if test $# -eq 0; then - set -- -O3 -fi - -# Merge jobs and make_options into make. -# -if test -n "$make"; then - if test -n "$jobs"; then - make="$make $jobs" - fi - - if test -n "$make_options"; then - make="$make$make_options" # Already has leading space. - fi -fi - -# If the installation directory is unspecified, then assume it is /usr/local. -# Otherwise, if it is a relative path, then convert it to an absolute path, -# unless the realpath program is not present on the system or doesn't -# recognize any of the options we pass, in which case fail, advising to -# specify an absolute installation directory. -# -if test -z "$idir"; then - idir=/usr/local - private=config.install.private=build2 - - # Only use default sudo for the default installation directory and only if - # it wasn't specified by the user. - # - if test -z "$sudo"; then - sudo="sudo" - fi -elif test -n "$(echo "$idir" | sed -n 's#^[^/].*$#true#p')"; then - - if ! command -v realpath >/dev/null 2>&1; then - diag "error: unable to execute realpath: command not found" - diag " info: specify absolute installation directory path" - exit 1 - fi - - # Don't resolve symlinks and allow non-existent path components. - # - if ! idir="$(realpath -s -m "$idir" 2>/dev/null)"; then - diag "error: realpath does not recognize -s -m" - diag " info: specify absolute installation directory path" - exit 1 - fi -fi - -if test "$sudo" = false; then - sudo= -fi - -if test -f build/config.build; then - diag "error: current directory already configured, start with clean source" - exit 1 -fi - -if test -z "$local" -a -d "../$cdir"; then - diag "error: ../$cdir/ bpkg configuration directory already exists, remove it" - exit 1 -fi - -# Add $idir/bin to PATH in case it is not already there. -# -PATH="$idir/bin:$PATH" -export PATH - -sys="$(build2/config.guess | sed -n 's/^[^-]*-[^-]*-\(.*\)$/\1/p')" - -case "$sys" in - mingw32 | mingw64 | msys | msys2 | cygwin) - conf_rpath="[null]" - conf_rpath_stage="[null]" - conf_sudo="[null]" - ;; - *) - if test -n "$private"; then - conf_rpath="$idir/lib/build2" - else - conf_rpath="$idir/lib" - fi - - conf_rpath_stage="$idir/lib" - - if test -n "$sudo"; then - conf_sudo="$sudo" - else - conf_sudo="[null]" - fi - ;; -esac - -# We don't have arrays in POSIX shell but we should be ok as long as none of -# the option values contain spaces. Note also that the expansion must be -# unquoted. -# -bpkg_fetch_ops= -bpkg_build_ops= - -if test -n "$timeout"; then - bpkg_fetch_ops="--fetch-timeout $timeout" - bpkg_build_ops="--fetch-timeout $timeout" -fi - -if test "$trust" = "yes"; then - bpkg_fetch_ops="$bpkg_fetch_ops --trust-yes" -elif test "$trust" = "no"; then - bpkg_fetch_ops="$bpkg_fetch_ops --trust-no" -elif test -n "$trust"; then - bpkg_fetch_ops="$bpkg_fetch_ops --trust $trust" -fi - -if test -n "$verbose"; then - verbose="--verbose $verbose" -fi - -# Suppress loading of default options files. -# -BUILD2_DEF_OPT="0" -export BUILD2_DEF_OPT - -BPKG_DEF_OPT="0" -export BPKG_DEF_OPT - -BDEP_DEF_OPT="0" -export BDEP_DEF_OPT - -# Bootstrap, stage 1. -# -run cd build2 -if test -z "$make"; then - run ./bootstrap.sh "$cxx" -else - run $make -f ./bootstrap.gmake "CXX=$cxx" -fi -run build2/b-boot --version - -# Bootstrap, stage 2. -# -run build2/b-boot $verbose $jobs config.cxx="$cxx" config.bin.lib=static build2/exe{b} -mv build2/b build2/b-boot -run build2/b-boot --version - -run cd .. - -# Local installation early return. -# -if test "$local" = true; then - - run build2/build2/b-boot $verbose configure \ -config.cxx="$cxx" \ -config.cc.coptions="$*" \ -config.bin.lib=shared \ -config.bin.rpath="$conf_rpath" \ -config.install.root="$idir" \ -config.install.sudo="$conf_sudo" \ -$private - - run build2/build2/b-boot $verbose $jobs install: build2/ bpkg/ bdep/ - - run command -v b - run command -v bpkg - run command -v bdep - - run b --version - run bpkg --version - run bdep --version - - diag - diag "Toolchain installation: $idir/bin" - diag "Build configuration: $owd" - diag - - exit 0 -fi - -# Build and stage the build system and the package manager. -# -run build2/build2/b-boot $verbose configure \ -config.cxx="$cxx" \ -config.bin.lib=shared \ -config.bin.suffix=-stage \ -config.bin.rpath="$conf_rpath_stage" \ -config.install.root="$idir" \ -config.install.data_root=root/stage \ -config.install.sudo="$conf_sudo" - -run build2/build2/b-boot $verbose $jobs install: build2/ bpkg/ - -run command -v b-stage -run command -v bpkg-stage - -run b-stage --version -run bpkg-stage --version - -# Build the entire toolchain from packages. -# -run cd .. -run mkdir "$cdir" -run cd "$cdir" -cdir="$(pwd)" # Save full path for later. - -run bpkg-stage $verbose create \ -cc \ -config.cxx="$cxx" \ -config.cc.coptions="$*" \ -config.bin.lib=shared \ -config.bin.rpath="$conf_rpath" \ -config.install.root="$idir" \ -config.install.sudo="$conf_sudo" \ -$private - -run bpkg-stage $verbose add "$BUILD2_REPO" -run bpkg-stage $verbose $bpkg_fetch_ops fetch -run bpkg-stage $verbose $jobs $bpkg_build_ops build --for install --yes --plan= build2 bpkg bdep -run bpkg-stage $verbose $jobs install build2 bpkg bdep - -run command -v b -run command -v bpkg -run command -v bdep - -run b --version -run bpkg --version -run bdep --version - -# Clean up stage. -# -run cd "$owd" -run b $verbose $jobs uninstall: build2/ bpkg/ - -diag -diag "Toolchain installation: $idir/bin" -diag "Build configuration: $cdir" -diag diff --git a/build.sh.in b/build.sh.in new file mode 100644 index 0000000..d72b59b --- /dev/null +++ b/build.sh.in @@ -0,0 +1,501 @@ +#!/bin/sh + +# file : build.sh.in +# license : MIT; see accompanying LICENSE file + +usage="Usage: $0 [-h|--help] [] []" + +# Package repository URL (or path). +# +if test -z "$BUILD2_REPO"; then + BUILD2_REPO="@BUILD2_REPO@" +fi + +# Package versions. +# +build2_ver="@BUILD2_VERSION@" +bpkg_ver="@BPKG_VERSION@" +bdep_ver="@BDEP_VERSION@" + +# The bpkg configuration directory. +# +cver="@CONFIG_VER@" +cdir="build2-toolchain-$cver" + +diag () +{ + echo "$*" 1>&2 +} + +# Note that this function will execute a command with arguments that contain +# spaces but it will not print them as quoted (and neither does set -x). +# +run () +{ + diag "+ $@" + "$@" + if test "$?" -ne "0"; then + exit 1 + fi +} + +owd="$(pwd)" + +local= +bpkg=true +bdep=true +private= +idir= +jobs= +sudo= +trust= +timeout= +make= +make_options= +verbose= + +cxx= + +while test $# -ne 0; do + case "$1" in + -h|--help) + diag + diag "$usage" + diag "Options:" + diag " --local Don't build from packages, only from local source." + diag " --no-bpkg Don't install bpkg nor bdep (requires --local)." + diag " --no-bdep Don't install bdep." + diag " --install-dir Alternative installation directory." + diag " --sudo Optional sudo program to use (pass false to disable)." + diag " --private Install shared libraries into private subdirectory." + diag " --jobs|-j Number of jobs to perform in parallel." + diag " --repo Alternative package repository location." + diag " --trust Repository certificate fingerprint to trust." + diag " --timeout Network operations timeout in seconds." + diag " --make Bootstrap using GNU make instead of script." + diag " --verbose Diagnostics verbosity level between 0 and 6." + diag + diag "By default the script will install into /usr/local with private" + diag "library subdirectories and using sudo(1). To enable private" + diag "subdirectories and/or use sudo for a custom installation location," + diag "you need to specify --private and/or --sudo explicitly, for example:" + diag + diag "$0 --install-dir /opt/build2 --sudo sudo g++" + diag + diag "If --jobs|-j is unspecified, then the bootstrap step is performed" + diag "serially with the rest of the process using the number of available" + diag "hardware threads." + diag + diag "The --trust option recognizes two special values: 'yes' (trust" + diag "everything) and 'no' (trust nothing)." + diag + diag "The --make option can be used to bootstrap using GNU make. The" + diag "first --make value should specify the make executable optionally" + diag "followed by additional make options, for example:" + diag + diag "$0 --make make --make -j8 g++" + diag + diag "If --jobs|-j is specified, then its value is passed to make before" + diag "any additional options." + diag + diag "If specified, override the default (-O3) compile" + diag "options (config.cc.coptions) in the bpkg configuration used to build" + diag "and install the final toolchain. For example, to build with the debug" + diag "information (and without optimization):" + diag + diag "$0 g++ -g" + diag + diag "See the BOOTSTRAP-UNIX file for details." + diag + exit 0 + ;; + --local) + local=true + shift + ;; + --no-bpkg) + bpkg= + shift + ;; + --no-bdep) + bdep= + shift + ;; + --private) + private=config.install.private=build2 + shift + ;; + --install-dir) + shift + if test $# -eq 0; then + diag "error: installation directory expected after --install-dir" + diag "$usage" + exit 1 + fi + idir="$1" + shift + ;; + -j|--jobs) + shift + if test $# -eq 0; then + diag "error: number of jobs expected after --jobs|-j" + diag "$usage" + exit 1 + fi + jobs="-j $1" + shift + ;; + --sudo) + shift + if test $# -eq 0; then + diag "error: sudo program expected after --sudo" + diag "$usage" + exit 1 + fi + sudo="$1" + shift + ;; + --repo) + shift + if test $# -eq 0; then + diag "error: repository location expected after --repo" + diag "$usage" + exit 1 + fi + BUILD2_REPO="$1" + shift + ;; + --trust) + shift + if test $# -eq 0; then + diag "error: certificate fingerprint expected after --trust" + diag "$usage" + exit 1 + fi + trust="$1" + shift + ;; + --timeout) + shift + if test $# -eq 0; then + diag "error: value in seconds expected after --timeout" + diag "$usage" + exit 1 + fi + timeout="$1" + shift + ;; + --make) + shift + if test $# -eq 0; then + diag "error: argument expected after --make" + diag "$usage" + exit 1 + fi + if test -z "$make"; then + make="$1" + else + make_options="$make_options $1" + fi + shift + ;; + --verbose) + shift + if test $# -eq 0; then + diag "error: diagnostics level between 0 and 6 expected after --verbose" + diag "$usage" + exit 1 + fi + verbose="$1" + shift + ;; + *) + cxx="$1" + shift + break + ;; + esac +done + +if test -z "$cxx"; then + diag "error: compiler executable expected" + diag "$usage" + exit 1 +fi + +# Place default into the $@ array. +# +if test $# -eq 0; then + set -- -O3 +fi + +# Merge jobs and make_options into make. +# +if test -n "$make"; then + if test -n "$jobs"; then + make="$make $jobs" + fi + + if test -n "$make_options"; then + make="$make$make_options" # Already has leading space. + fi +fi + +# If --no-bpkg is specified, then we require --local to also be specified +# since it won't be possible to build things from packages without bpkg. Also +# imply --no-bdep in this case, since bdep is pretty much useless without +# bpkg. +# +if test -z "$bpkg"; then + if test -z "$local"; then + diag "error: --no-bpkg can only be used for local installation" + diag " info: additionally specify --local" + exit 1 + fi + + bdep= +fi + +# If the installation directory is unspecified, then assume it is /usr/local. +# Otherwise, if it is a relative path, then convert it to an absolute path, +# unless the realpath program is not present on the system or doesn't +# recognize any of the options we pass, in which case fail, advising to +# specify an absolute installation directory. +# +if test -z "$idir"; then + idir=/usr/local + private=config.install.private=build2 + + # Only use default sudo for the default installation directory and only if + # it wasn't specified by the user. + # + if test -z "$sudo"; then + sudo="sudo" + fi +elif test -n "$(echo "$idir" | sed -n 's#^[^/].*$#true#p')"; then + + if ! command -v realpath >/dev/null 2>&1; then + diag "error: unable to execute realpath: command not found" + diag " info: specify absolute installation directory path" + exit 1 + fi + + # Don't resolve symlinks and allow non-existent path components. + # + if ! idir="$(realpath -s -m "$idir" 2>/dev/null)"; then + diag "error: realpath does not recognize -s -m" + diag " info: specify absolute installation directory path" + exit 1 + fi +fi + +if test "$sudo" = false; then + sudo= +fi + +if test -f build/config.build; then + diag "error: current directory already configured, start with clean source" + exit 1 +fi + +if test -z "$local" -a -d "../$cdir"; then + diag "error: ../$cdir/ bpkg configuration directory already exists, remove it" + exit 1 +fi + +# Add $idir/bin to PATH in case it is not already there. +# +PATH="$idir/bin:$PATH" +export PATH + +sys="$(build2/config.guess | sed -n 's/^[^-]*-[^-]*-\(.*\)$/\1/p')" + +case "$sys" in + mingw32 | mingw64 | msys | msys2 | cygwin) + conf_rpath="[null]" + conf_rpath_stage="[null]" + conf_sudo="[null]" + ;; + *) + if test -n "$private"; then + conf_rpath="$idir/lib/build2" + else + conf_rpath="$idir/lib" + fi + + conf_rpath_stage="$idir/lib" + + if test -n "$sudo"; then + conf_sudo="$sudo" + else + conf_sudo="[null]" + fi + ;; +esac + +# We don't have arrays in POSIX shell but we should be ok as long as none of +# the option values contain spaces. Note also that the expansion must be +# unquoted. +# +bpkg_fetch_ops= +bpkg_build_ops= + +if test -n "$timeout"; then + bpkg_fetch_ops="--fetch-timeout $timeout" + bpkg_build_ops="--fetch-timeout $timeout" +fi + +if test "$trust" = "yes"; then + bpkg_fetch_ops="$bpkg_fetch_ops --trust-yes" +elif test "$trust" = "no"; then + bpkg_fetch_ops="$bpkg_fetch_ops --trust-no" +elif test -n "$trust"; then + bpkg_fetch_ops="$bpkg_fetch_ops --trust $trust" +fi + +if test -n "$verbose"; then + verbose="--verbose $verbose" +fi + +# Suppress loading of default options files. +# +BUILD2_DEF_OPT="0" +export BUILD2_DEF_OPT + +BPKG_DEF_OPT="0" +export BPKG_DEF_OPT + +BDEP_DEF_OPT="0" +export BDEP_DEF_OPT + +# Bootstrap, stage 1. +# +run cd build2 +if test -z "$make"; then + run ./bootstrap.sh "$cxx" +else + run $make -f ./bootstrap.gmake "CXX=$cxx" +fi +run build2/b-boot --version + +# Bootstrap, stage 2. +# +run build2/b-boot $verbose $jobs config.cxx="$cxx" config.bin.lib=static build2/exe{b} +mv build2/b build2/b-boot +run build2/b-boot --version + +run cd .. + +# Local installation early return. +# +if test "$local" = true; then + + run build2/build2/b-boot $verbose configure \ +config.cxx="$cxx" \ +config.cc.coptions="$*" \ +config.bin.lib=shared \ +config.bin.rpath="$conf_rpath" \ +config.install.root="$idir" \ +config.install.sudo="$conf_sudo" \ +$private + + projects="build2/" + + if test "$bpkg" = true; then + projects="$projects bpkg/" + fi + + if test "$bdep" = true; then + projects="$projects bdep/" + fi + + run build2/build2/b-boot $verbose $jobs install: $projects + + run command -v b + run b --version + + if test "$bpkg" = true; then + run command -v bpkg + run bpkg --version + fi + + if test "$bdep" = true; then + run command -v bdep + run bdep --version + fi + + diag + diag "Toolchain installation: $idir/bin" + diag "Build configuration: $owd" + diag + + exit 0 +fi + +# Build and stage the build system and the package manager. +# +run build2/build2/b-boot $verbose configure \ +config.cxx="$cxx" \ +config.bin.lib=shared \ +config.bin.suffix=-stage \ +config.bin.rpath="$conf_rpath_stage" \ +config.install.root="$idir" \ +config.install.data_root=root/stage \ +config.install.sudo="$conf_sudo" + +run build2/build2/b-boot $verbose $jobs install: build2/ bpkg/ + +run command -v b-stage +run b-stage --version + +run command -v bpkg-stage +run bpkg-stage --version + +# Build the entire toolchain from packages. +# +run cd .. +run mkdir "$cdir" +run cd "$cdir" +cdir="$(pwd)" # Save full path for later. + +run bpkg-stage $verbose create \ +cc \ +config.cxx="$cxx" \ +config.cc.coptions="$*" \ +config.bin.lib=shared \ +config.bin.rpath="$conf_rpath" \ +config.install.root="$idir" \ +config.install.sudo="$conf_sudo" \ +$private + +packages="build2/$build2_ver bpkg/$bpkg_ver" + +if test "$bdep" = true; then + packages="$packages bdep/$bdep_ver" +fi + +run bpkg-stage $verbose add "$BUILD2_REPO" +run bpkg-stage $verbose $bpkg_fetch_ops fetch +run bpkg-stage $verbose $jobs $bpkg_build_ops build --for install --yes --plan= $packages +run bpkg-stage $verbose $jobs install --all + +run command -v b +run b --version + +run command -v bpkg +run bpkg --version + +if test "$bdep" = true; then + run command -v bdep + run bdep --version +fi + +# Clean up stage. +# +run cd "$owd" +run b $verbose $jobs uninstall: build2/ bpkg/ + +diag +diag "Toolchain installation: $idir/bin" +diag "Build configuration: $cdir" +diag diff --git a/buildfile b/buildfile index 602069a..0fd5e81 100644 --- a/buildfile +++ b/buildfile @@ -1,6 +1,12 @@ # file : buildfile # license : MIT; see accompanying LICENSE file +# Package repository URL (or path). +# +build2_repo="https://stage.build2.org/1" +# build2_repo="https://pkg.cppget.org/1/queue/alpha" +# build2_repo="https://pkg.cppget.org/1/alpha" + # Note that the project directories order is important (prerequisites go # first). # @@ -21,9 +27,58 @@ BOOTSTRAP-WINDOWS-MINGW doc{$i README} \ legal{LICENSE AUTHORS} \ cli{$i} \ - file{build.sh build-*} \ manifest +# Obtain the build2, bpkg, bdep, and toolchain versions. +# +bp = $recall($build.path) +pt = '^version: (.+)$' + +ver = $process.run_regex($bp 'info:' $src_root/, "$pt", '\1') +build2_ver = $process.run_regex($bp 'info:' $src_root/build2/, "$pt", '\1') +bpkg_ver = $process.run_regex($bp 'info:' $src_root/bpkg/, "$pt", '\1') +bdep_ver = $process.run_regex($bp 'info:' $src_root/bdep/, "$pt", '\1') + +# Generate install scripts from templates and include them into the +# distribution. +# +# @@ Redo as ad hoc rule. +# +for s: exe{build.sh} file{build-msvc.bat build-clang.bat build-mingw.bat} +{ + ./: $s: file{$name($s).$extension($s).in} + { + dist = true + } + {{ + diag sed $< + + t = $path($>) + p = $path($<) + + # Note: the same code as in the etc/version script. + # + sed -e 's/([^.]+)\..*/\1/' <<<"$ver" | set mj + sed -e 's/[^.]+\.([^.]+)\..*/\1/' <<<"$ver" | set mn + sed -n -e 's/[^.]+\.[^.]+\.[^.-]+-([ab]).*/\1/p' <<<"$ver" | set ab + sed -n -e 's/[^.]+\.[^.]+\.[^.-]+-[ab]\.([^.+]+).*/\1/p' <<<"$ver" | set pr + + # Version for configuration directory. + # + cver = "$mj.$mn" + + if ("$ab" != '') + cver = "$cver-$ab.$pr" + end + + sed -e 's%@BUILD2_REPO@%'$build2_repo'%' $p >$t + sed -e 's/@CONFIG_VER@/'$cver'/' -i $t + sed -e 's/@BUILD2_VERSION@/'$build2_ver'/' -i $t + sed -e 's/@BPKG_VERSION@/'$bpkg_ver'/' -i $t + sed -e 's/@BDEP_VERSION@/'$bdep_ver'/' -i $t + }} +} + # Don't install the BOOTSTRAP/INSTALL files. But UPGRADE could be useful. # doc{INSTALL}@./: install = false -- cgit v1.1