From 3fee23e48aa8cd02cfb57f2d8d82d1898bbbb51a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 20 Aug 2016 11:58:09 +0200 Subject: Add build scripts --- build-mingw.bat | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ build-msvc.bat | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++ buildfile | 3 +- 4 files changed, 513 insertions(+), 1 deletion(-) create mode 100644 build-mingw.bat create mode 100644 build-msvc.bat create mode 100755 build.sh diff --git a/build-mingw.bat b/build-mingw.bat new file mode 100644 index 0000000..36572b4 --- /dev/null +++ b/build-mingw.bat @@ -0,0 +1,177 @@ +@echo off + +rem file : build-mingw.bat +rem copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +rem license : MIT; see accompanying LICENSE file + +setlocal EnableDelayedExpansion +goto start + +:usage +echo. +echo Usage: %0 [/?] ^ [^] +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 Example usage: +echo. +echo %0 C:\mingw\bin\g++ D:\build2 +echo. +echo See the INSTALL file for details. +echo. +goto end + +:start + +set "owd=%CD%" + +if "_%1_" == "_/?_" goto usage + +rem Compiler. +rem +if "_%1_" == "__" ( + echo error: compiler executable expected, run %0 /? for details + goto error +) else ( + set "cxx=%1" +) + +rem Installation directory. +rem +if "_%2_" == "__" ( + set "idir=C:\build2" +) else ( + set "idir=%2" +) + +if not exist %idir%\bin\ ( + echo error: %idir%\bin\ does not exist + goto error +) + +if exist build\config.build ( + echo current directory already configured, start with clean source + goto error +) + +if exist ..\build2-toolchain\ ( + echo ..\build2-toolchain\ bpkg configuration directory already exists + goto error +) + +set "sdir=%idir%\stage" +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 Bootstrap. +@rem +cd build2 + +@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 + +build2\b-boot --version +@if errorlevel 1 goto error + +build2\b-boot config.cxx=%cxx% config.bin.lib=static +@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 + +@rem Build and stage the toolchain. +@rem +cd .. + +build2\build2\b-boot configure^ + config.cxx=%cxx%^ + config.bin.lib=shared^ + config.bin.suffix=-stage^ + config.install.root=%sdir%^ + config.install.exec_root=%idir% +@if errorlevel 1 goto error + +build2\build2\b-boot install +@if errorlevel 1 goto error + +b-stage --version +@if errorlevel 1 goto error + +bpkg-stage --version +@if errorlevel 1 goto error + +@rem Rebuild via package manager. +@rem +cd .. + +md build2-toolchain +@if errorlevel 1 goto error + +cd build2-toolchain +@set "cdir=%CD%" + +bpkg-stage create^ + cc^ + config.cxx=%cxx%^ + config.cc.coptions=-O3^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +@rem @@ TMP: queue +bpkg-stage add https://pkg.cppget.org/1/queue +@if errorlevel 1 goto error + +bpkg-stage fetch +@if errorlevel 1 goto error + +bpkg-stage build --yes build2 bpkg +@if errorlevel 1 goto error + +bpkg-stage install build2 bpkg +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +@rem Clean up stage. +@rem +cd %owd% +b uninstall +@if errorlevel 1 goto error + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Upgrade 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 new file mode 100644 index 0000000..88eebe7 --- /dev/null +++ b/build-msvc.bat @@ -0,0 +1,168 @@ +@echo off + +rem file : build-msvc.bat +rem copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +rem license : MIT; see accompanying LICENSE file + +setlocal EnableDelayedExpansion +goto start + +:usage +echo. +echo Usage: %0 [/?] [^] +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 Example usage: +echo. +echo %0 D:\build2 +echo. +echo See the INSTALL file for details. +echo. +goto end + +:start + +set "owd=%CD%" + +if "_%1_" == "_/?_" goto usage + +rem Installation directory. +rem +if "_%1_" == "__" ( + set "idir=C:\build2" +) else ( + set "idir=%1" +) + +if not exist %idir%\bin\ ( + echo error: %idir%\bin\ does not exist + goto error +) + +if exist build\config.build ( + echo current directory already configured, start with clean source + goto error +) + +if exist ..\build2-toolchain\ ( + echo ..\build2-toolchain\ bpkg configuration directory already exists + goto error +) + +set "sdir=%idir%\stage" +set "PATH=%idir%\bin;%PATH%" + +rem Show the steps we are performing. +rem +@echo on + +@rem Verify the compiler works. +@rem +cl +@if errorlevel 1 goto error + +@rem Bootstrap. +@rem +cd build2 + +@rem Execute in a separate cmd.exe to preserve the echo mode. +@rem +cmd /C bootstrap-msvc.bat cl +@if errorlevel 1 goto error + +build2\b-boot --version +@if errorlevel 1 goto error + +build2\b-boot config.cxx=cl config.bin.lib=static +@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 + +@rem Build and stage the toolchain. +@rem +cd .. + +build2\build2\b-boot configure^ + config.cxx=cl^ + config.bin.lib=shared^ + config.bin.suffix=-stage^ + config.install.root=%sdir%^ + config.install.exec_root=%idir% +@if errorlevel 1 goto error + +build2\build2\b-boot install +@if errorlevel 1 goto error + +b-stage --version +@if errorlevel 1 goto error + +bpkg-stage --version +@if errorlevel 1 goto error + +@rem Rebuild via package manager. +@rem +cd .. + +md build2-toolchain +@if errorlevel 1 goto error + +cd build2-toolchain +@set "cdir=%CD%" + +bpkg-stage create^ + cc^ + config.cxx=cl^ + "config.cc.coptions=/O2 /Oi"^ + config.bin.lib=shared^ + config.install.root=%idir% +@if errorlevel 1 goto error + +@rem @@ TMP: queue +bpkg-stage add https://pkg.cppget.org/1/queue +@if errorlevel 1 goto error + +bpkg-stage fetch +@if errorlevel 1 goto error + +bpkg-stage build --yes build2 bpkg +@if errorlevel 1 goto error + +bpkg-stage install build2 bpkg +@if errorlevel 1 goto error + +b --version +@if errorlevel 1 goto error + +bpkg --version +@if errorlevel 1 goto error + +@rem Clean up stage. +@rem +cd %owd% +b uninstall +@if errorlevel 1 goto error + +@echo off + +echo. +echo Toolchain installation: %idir%\bin +echo Upgrade configuration: %cdir% +echo. + +goto end + +:error +@echo off +cd %owd% +endlocal +exit /b 1 + +:end +endlocal diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..df5b1e5 --- /dev/null +++ b/build.sh @@ -0,0 +1,166 @@ +#!/bin/sh + +# file : build.sh +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# @@ Should we add sys:sqlite by default? Or add option? +# @@ Need to note that script will ask for repository verification. +# @@ Perhaps a fingerprint to pass to fetch? Once repo is signed? +# @@ Option for alternative bpkg config dir? + +usage="Usage: $0 [-h] [--install-dir ] [--sudo ] " + +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)" + +cxx= +idir="/usr/local" +sudo="sudo" + +while test $# -ne 0; do + case $1 in + -h|--help) + diag + diag "$usage" + diag + diag "By default the script will install into /usr/local using sudo. To" + diag "instruct the script not to use a sudo program, pass empty value to" + diag "the --sudo option, for example:" + diag + diag "$0 --install-dir /tmp/build2 --sudo '' g++" + diag + diag "See the INSTALL file for details." + diag + exit 0 + ;; + --install-dir) + shift + if test $# -eq 0; then + diag "error: installation directory expected after --install-dir" + diag "$usage" + exit 1 + fi + idir="$1" + shift + ;; + --sudo) + shift + if test $# -eq 0; then + diag "error: sudo program expected after --sudo" + diag "$usage" + exit 1 + fi + sudo="$1" + shift + ;; + *) + cxx="$1" + break + ;; + esac +done + +if test -z "$cxx"; then + diag "error: compiler executable expected" + diag "$usage" + exit 1 +fi + +if test -f build/config.build; then + diag "current directory already configured, start with clean source" + exit 1 +fi + +if test -d ../build2-toolchain; then + diag "../build2-toolchain/ bpkg configuration directory already exists" + exit 1 +fi + +# Add $idir/bin to PATH in case it is not already there. +# +PATH="$idir/bin:$PATH" +export PATH + +sdir="$idir/stage" + +# Bootstrap, stage 1. +# +run cd build2 +run ./bootstrap.sh "$cxx" +run build2/b-boot --version + +# Bootstrap, stage 2. +# +run build2/b-boot config.cxx="$cxx" config.bin.lib=static +mv build2/b build2/b-boot +run build2/b-boot --version + +# Stage. +# +run cd .. + +run build2/build2/b-boot configure \ +config.cxx="$cxx" \ +config.bin.lib=shared \ +config.bin.suffix=-stage \ +config.bin.rpath="$idir/lib" \ +config.install.data_root="$sdir" \ +config.install.exec_root="$idir" \ +config.install.sudo="$sudo" + +run build2/build2/b-boot install + +run b-stage --version +run bpkg-stage --version + +# Install. +# +run cd .. +run mkdir build2-toolchain +run cd build2-toolchain +cdir="$(pwd)" + +run bpkg-stage create \ +cc \ +config.cxx="$cxx" \ +config.cc.coptions=-O3 \ +config.bin.lib=shared \ +config.bin.rpath="$idir/lib" \ +config.install.root="$idir" \ +config.install.sudo="$sudo" + +#@@ TMP: queue +run bpkg-stage add https://pkg.cppget.org/1/queue +run bpkg-stage fetch +run bpkg-stage build --yes build2 bpkg +run bpkg-stage install build2 bpkg + +run b --version +run bpkg --version + +# Clean up. +# +run cd "$owd" +run b uninstall + +diag +diag "Toolchain installation: $idir/bin" +diag "Upgrade configuration: $cdir" +diag diff --git a/buildfile b/buildfile index 13c59c5..e6cd320 100644 --- a/buildfile +++ b/buildfile @@ -3,7 +3,8 @@ # license : MIT; see accompanying LICENSE file d = libbutl/ build2/ libsqlite3/ libodb/ libodb-sqlite/ libbpkg/ bpkg/ doc/ -./: $d doc{INSTALL README version} file{INSTALL.cli} +./: $d doc{INSTALL README version} file{INSTALL.cli} \ +file{build.sh build-msvc.bat build-mingw.bat} include $d doc{INSTALL*}: install = false -- cgit v1.1