diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-20 09:34:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-20 09:34:27 +0200 |
commit | bdabddcc90a5cc203a2821c8229e7238c32f5ba6 (patch) | |
tree | 1510fe27d7a6fe876c8df8e8e279f0d4c63bc7ae | |
parent | 4776ab7859e71bb6cec004a1aea05324ad33fd1d (diff) |
Improve bootstrap scripts
-rw-r--r-- | bootstrap-mingw.bat | 37 | ||||
-rw-r--r-- | bootstrap-msvc.bat | 65 | ||||
-rwxr-xr-x | bootstrap.sh | 86 |
3 files changed, 105 insertions, 83 deletions
diff --git a/bootstrap-mingw.bat b/bootstrap-mingw.bat index 63a2918..a7049bb 100644 --- a/bootstrap-mingw.bat +++ b/bootstrap-mingw.bat @@ -9,16 +9,15 @@ goto start :usage echo. -echo Usage: %0 [/?] [cxx [cxx-option...]] +echo Usage: %0 [/?] ^<cxx^> [^<cxx-option^>...] echo. echo The batch file expects to find the libbutl\ or libbutl-*\ directory -echo either in the current directory (build2 root) or one level up. +echo either in the current directory (build2 root) or one level up. The +echo result is saved as build2\b-boot.exe. echo. -echo Note that if any cxx-option arguments are specified, then they must -echo be preceded by the compiler executable (use g++ as the default). For -echo example: +echo Example usage: echo. -echo %0 g++ -O3 +echo %0 C:\mingw\bin\g++ -static echo. echo See the INSTALL file for details. echo. @@ -28,6 +27,15 @@ goto end if "_%1_" == "_/?_" goto usage +rem Compiler executable. +rem +if "_%1_" == "__" ( + echo error: compiler executable expected, run %0 /? for details + goto error +) else ( + set "cxx=%1" +) + rem See if there is libbutl or libbutl-* in the current directory and one rem directory up. Note that globbing returns paths in alphabetic order. rem @@ -64,17 +72,9 @@ set "src=%src% build2\test\*.cxx" set "src=%src% build2\install\*.cxx" set "src=%src% %libbutl%\butl\*.cxx" -rem Get the compiler executable. -rem -if "_%1_" == "__" ( - set "cxx=g++" -) else ( - set "cxx=%1" -) - rem Get the compile options. rem -set "ops=-std=c++1y -static" +set "ops=-std=c++1y" :ops_next shift if "_%1_" == "__" ( @@ -87,8 +87,11 @@ if "_%1_" == "__" ( rem Compile. rem -echo %cxx% -I%libbutl% -I. -DBUILD2_HOST_TRIPLET=\"i686-w64-mingw32\" %ops% -o build2\b-boot.exe %src% - %cxx% -I%libbutl% -I. -DBUILD2_HOST_TRIPLET=\"i686-w64-mingw32\" %ops% -o build2\b-boot.exe %src% +rem Note that echo does not override errorlevel. +rem +echo on +%cxx% -I%libbutl% -I. -DBUILD2_HOST_TRIPLET=\"i686-w64-mingw32\" %ops% -o build2\b-boot.exe %src% +@echo off if errorlevel 1 goto error goto end diff --git a/bootstrap-msvc.bat b/bootstrap-msvc.bat index 2ac3b68..fba7a2e 100644 --- a/bootstrap-msvc.bat +++ b/bootstrap-msvc.bat @@ -9,21 +9,20 @@ goto start :usage echo. -echo Usage: %0 [/?] [cl-exe [cl-option...]] +echo Usage: %0 [/?] ^<cxx^> [^<cxx-option^>...] echo. echo Normally this batch file is executed from one of the Visual Studio -echo command prompts. It assume that the VC compiler can be executed as -echo just cl.exe and that all the relevant environment variables (INCLUDE, -echo LIB) are set. +echo command prompts with cl.exe as the compiler executable (^<cxx^>). +echo It assumes that all the relevant compiler environment variables +echo (INCLUDE, LIB) are set. echo. echo The batch file expects to find the libbutl\ or libbutl-*\ directory -echo either in the current directory (build2 root) or one level up. +echo either in the current directory (build2 root) or one level up. The +echo result is saved as build2\b-boot.exe. echo. -echo Note that if any cl-option arguments are specified, then they must be -echo preceded by the VC compiler executable (use cl.exe as the default). -echo For example: +echo Example usage: echo. -echo %0 cl.exe /nologo +echo %0 cl echo. echo See the INSTALL file for details. echo. @@ -37,12 +36,37 @@ rem ) goto :eof +:compile + rem Note that echo does not override errorlevel. + rem + echo on + %cxx% /I%owd%\%libbutl% /I%owd% /DBUILD2_HOST_TRIPLET=\"i686-microsoft-win32-msvc\" %ops% /c /TP %* + @echo off + if errorlevel 1 goto error +goto :eof + +:link + echo on + %cxx% %ops% %* + @echo off + if errorlevel 1 goto error +goto :eof + :start set "owd=%CD%" if "_%1_" == "_/?_" goto usage +rem Compiler executable. +rem +if "_%1_" == "__" ( + echo error: compiler executable expected, run %0 /? for details + goto error +) else ( + set "cxx=%1" +) + rem See if there is libbutl or libbutl-* in the current directory and one rem directory up. Note that globbing returns paths in alphabetic order. rem @@ -79,14 +103,6 @@ set "src=%src% build2\test" set "src=%src% build2\install" set "src=%src% %libbutl%\butl" -rem Get the compiler executable. -rem -if "_%1_" == "__" ( - set "cxx=cl.exe" -) else ( - set "cxx=%1" -) - rem Get the compile options. rem set "ops=/nologo /EHsc /MT /MP" @@ -111,27 +127,20 @@ rem clash. And boy do they clash. rem set "obj=" for %%d in (%src%) do ( - echo. - echo compiling in %%d\ - echo. cd %%d - echo %cxx% /I%owd%\%libbutl% /I%owd% /DBUILD2_HOST_TRIPLET=\"i686-microsoft-win32-msvc\" %ops% /c /TP *.cxx - %cxx% /I%owd%\%libbutl% /I%owd% /DBUILD2_HOST_TRIPLET=\"i686-microsoft-win32-msvc\" %ops% /c /TP *.cxx - if errorlevel 1 goto error + call :compile *.cxx cd %owd% set "obj=!obj! %%d\*.obj" ) rem Link. rem -echo. -echo %cxx% %ops% /Fe: build2\b-boot.exe %obj% shell32.lib - %cxx% %ops% /Fe: build2\b-boot.exe %obj% shell32.lib -if errorlevel 1 goto error +call :link /Fe: build2\b-boot.exe %obj% shell32.lib -rem Clean up .obj. +rem Clean up. rem call :clean_obj %src% + goto end :error diff --git a/bootstrap.sh b/bootstrap.sh index 28da7f5..9493bea 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -4,74 +4,84 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -usage="Usage: $0 [-h] [--cxx <file>] [--libbutl <dir>] [--host <triplet>] [<options>]" +usage="Usage: $0 [-h] [--libbutl <dir>] [--host <triplet>] <cxx> [<cxx-option>...]" -cxx=g++ +diag () +{ + echo "$*" 1>&2 +} + +cxx= libbutl= host= while test $# -ne 0; do - case $1 in + case "$1" in -h|--help) - echo "$usage" 1>&2 - echo 1>&2 - echo "The script expects to find the libbutl/ or libbutl-*/ directory either" 1>&2 - echo "in the current directory (build2 root) or one level up." 1>&2 - echo 1>&2 - echo "See the INSTALL file for details." 1>&2 + diag + diag "$usage" + diag + diag "The script expects to find the libbutl/ or libbutl-*/ directory either" + diag "in the current directory (build2 root) or one level up. The result is" + diag "saved as build2/b-boot." + diag + diag "Example usage:" + diag + diag "$0 g++" + diag + diag "See the INSTALL file for details." + diag exit 0 ;; - --cxx) - shift - if test $# -eq 0; then - echo "error: c++ compiler executable expected after --cxx" 1>&2 - echo "$usage" 1>&2 - exit 1 - fi - cxx=$1 - shift - ;; --libbutl) shift if test $# -eq 0; then - echo "error: libbutl path expected after --libbutl" 1>&2 - echo "$usage" 1>&2 + diag "error: libbutl path expected after --libbutl" + diag "$usage" exit 1 fi if test ! -d "$1"; then - echo "error: libbutl directory '$1' does not exist" 1>&2 + diag "error: libbutl directory '$1' does not exist" exit 1 fi - libbutl=$1 + libbutl="$1" shift ;; --host) shift if test $# -eq 0; then - echo "error: host triplet expected after --host" 1>&2 - echo "$usage" 1>&2 + diag "error: host triplet expected after --host" + diag "$usage" exit 1 fi - host=$1 + host="$1" shift ;; *) + cxx="$1" + shift break ;; esac done +if test -z "$cxx"; then + diag "error: compiler executable expected" + diag "$usage" + exit 1 +fi + if test -z "$host"; then - if ! host=`./config.guess`; then - echo "error: unable to guess host triplet" 1>&2 + if ! host="$(./config.guess)"; then + diag "error: unable to guess host triplet" exit 1 fi else - if ! chost=`./config.sub $host`; then - echo "error: unable to canonicalize host triplet '$host'" 1>&2 + if ! chost="$(./config.sub "$host")"; then + diag "error: unable to canonicalize host triplet '$host'" exit 1 fi - host=$chost + host="$chost" fi # See if there is libbutl or libbutl-* in the current directory and @@ -79,9 +89,9 @@ fi # if test -z "$libbutl"; then if test -d libbutl; then - libbutl=libbutl + libbutl="libbutl" else - libbutl=`echo libbutl-*/` + libbutl="$(echo libbutl-*/)" if test ! -d "$libbutl"; then libbutl= fi @@ -90,9 +100,9 @@ fi if test -z "$libbutl"; then if test -d ../libbutl; then - libbutl=../libbutl + libbutl="../libbutl" else - libbutl=`echo ../libbutl-*/` + libbutl="$(echo ../libbutl-*/)" if test ! -d "$libbutl"; then libbutl= fi @@ -100,7 +110,7 @@ if test -z "$libbutl"; then fi if test -z "$libbutl"; then - echo "error: unable to find libbutl, use --libbutl to specify its location" 1>&2 + diag "error: unable to find libbutl, use --libbutl to specify its location" exit 1 fi @@ -116,5 +126,5 @@ src="$src build2/test/*.cxx" src="$src build2/install/*.cxx" src="$src $libbutl/butl/*.cxx" -echo $cxx -I$libbutl -I. '-DBUILD2_HOST_TRIPLET="'$host'"' -std=c++1y $* -o build2/b-boot $src -exec $cxx -I$libbutl -I. '-DBUILD2_HOST_TRIPLET="'$host'"' -std=c++1y $* -o build2/b-boot $src +set -x +"$cxx" -I"$libbutl" -I. '-DBUILD2_HOST_TRIPLET="'"$host"'"' -std=c++1y "$@" -o build2/b-boot $src |