From a18b73adad8a72c2ceb3782477f946b70ca6eeea Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 19 Aug 2022 23:50:54 +0300 Subject: Add compile and link options to build scripts --- build-clang.bat.in | 52 ++++++++++++++++++++++++++++++++++++++++------- build-mingw.bat.in | 53 +++++++++++++++++++++++++++++++++++++----------- build-msvc.bat.in | 59 ++++++++++++++++++++++++++++++++++++++++-------------- build.sh.in | 51 ++++++++++++++++++++++++++++++++++++---------- 4 files changed, 170 insertions(+), 45 deletions(-) diff --git a/build-clang.bat.in b/build-clang.bat.in index dadb1f7..c983aae 100644 --- a/build-clang.bat.in +++ b/build-clang.bat.in @@ -8,7 +8,7 @@ goto start :usage echo. -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^). @@ -263,15 +263,48 @@ if "_%~1_" == "_--verbose_" ( if "_%~1_" == "_--_" shift -rem Validate options and arguments. -rem - rem Compiler. rem if "_%1_" == "__" ( set "cxx=clang++" ) else ( - set "cxx=%1" + set "cxx=%~1" + shift +) + +rem Compile and link options. +rem +set "compile_ops=" +set "link_ops=" + +:compile_options +if not "_%1_" == "__" ( + if not "_%~1_" == "_--_" ( + set "compile_ops=%compile_ops% %~1" + shift + goto compile_options + ) else ( + shift + ) +) + +:link_options +if not "_%1_" == "__" ( + set "link_ops=%link_ops% %~1" + shift + goto link_options +) + +if not "_%compile_ops%_" == "__" ( + set coptions="config.cc.coptions=-m64%compile_ops%" +) else ( + set coptions="config.cc.coptions=-m64 -O2" +) + +if not "_%link_ops%_" == "__" ( + set loptions="config.cc.loptions=%link_ops:~1%" +) else ( + set "loptions=" ) rem Merge jobs and make_options into make. @@ -284,6 +317,9 @@ if not "_%make%_" == "__" ( if not "_%make_options%_" == "__" set "make=!make!%make_options%" ) +rem Validate options and arguments. +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 @@ -454,7 +490,8 @@ cd .. build2\build2\b-boot %verbose% configure^ config.config.hermetic=true^ config.cxx=%cxx%^ - "config.cc.coptions=-m64 -O2"^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% @@ -575,7 +612,8 @@ cd %cdir% cc^ config.config.hermetic=true^ config.cxx=%cxx%^ - "config.cc.coptions=-m64 -O2"^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% diff --git a/build-mingw.bat.in b/build-mingw.bat.in index 098f8d5..caff834 100644 --- a/build-mingw.bat.in +++ b/build-mingw.bat.in @@ -8,7 +8,7 @@ goto start :usage echo. -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^). @@ -262,25 +262,49 @@ if "_%~1_" == "_--verbose_" ( 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" + set "cxx=%~1" + shift ) -rem @@ Temporarily retained for backwards compatibility. +rem Compile and link options. rem -if not "_%2_" == "__" ( - set "idir=%2" +set "compile_ops=" +set "link_ops=" + +:compile_options +if not "_%1_" == "__" ( + if not "_%~1_" == "_--_" ( + set "compile_ops=%compile_ops% %~1" + shift + goto compile_options + ) else ( + shift + ) ) -if not "_%3_" == "__" ( - set "trust=%3" + +:link_options +if not "_%1_" == "__" ( + set "link_ops=%link_ops% %~1" + shift + goto link_options +) + +if not "_%compile_ops%_" == "__" ( + set coptions="config.cc.coptions=%compile_ops:~1%" +) else ( + set "coptions=config.cc.coptions=-O2" +) + +if not "_%link_ops%_" == "__" ( + set loptions="config.cc.loptions=%link_ops:~1%" +) else ( + set "loptions=" ) rem Merge jobs and make_options into make. @@ -293,6 +317,9 @@ if not "_%make%_" == "__" ( if not "_%make_options%_" == "__" set "make=!make!%make_options%" ) +rem Validate options and arguments. +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 @@ -463,7 +490,8 @@ cd .. build2\build2\b-boot %verbose% configure^ config.config.hermetic=true^ config.cxx=%cxx%^ - config.cc.coptions=-O2^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% @@ -585,7 +613,8 @@ cd %cdir% cc^ config.config.hermetic=true^ config.cxx=%cxx%^ - config.cc.coptions=-O2^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% diff --git a/build-msvc.bat.in b/build-msvc.bat.in index c009811..85503bb 100644 --- a/build-msvc.bat.in +++ b/build-msvc.bat.in @@ -8,8 +8,7 @@ goto start :usage echo. -rem echo Usage: %0 [/?] [^] [^] -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^). @@ -234,24 +233,52 @@ if "_%~1_" == "_--verbose_" ( if "_%~1_" == "_--_" shift -rem Validate options and arguments. +rem Compiler. rem +if "_%1_" == "__" ( + set "cxx=cl" +) else ( + set "cxx=%~1" + shift +) -rem @@ Temporarily retained for backwards compatibility. +rem Compile and link options. rem +set "compile_ops=" +set "link_ops=" + +:compile_options if not "_%1_" == "__" ( - set "idir=%1" + if not "_%~1_" == "_--_" ( + set "compile_ops=%compile_ops% %~1" + shift + goto compile_options + ) else ( + shift + ) ) -if not "_%2_" == "__" ( - set "trust=%2" + +:link_options +if not "_%1_" == "__" ( + set "link_ops=%link_ops% %~1" + shift + goto link_options ) -rem Compiler. + +if not "_%compile_ops%_" == "__" ( + set coptions="config.cc.coptions=%compile_ops:~1%" +) else ( + set "coptions=config.cc.coptions=/O2" +) + +if not "_%link_ops%_" == "__" ( + set loptions="config.cc.loptions=%link_ops:~1%" +) else ( + set "loptions=" +) + +rem Validate options and arguments. 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. @@ -419,7 +446,8 @@ cd .. build2\build2\b-boot %verbose% configure^ config.config.hermetic=true^ config.cxx=%cxx%^ - config.cc.coptions=/O2^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% @@ -539,7 +567,8 @@ cd %cdir% cc^ config.config.hermetic=true^ config.cxx=%cxx%^ - config.cc.coptions=/O2^ + %coptions%^ + %loptions%^ config.bin.lib=shared^ config.install.root=%idir%^ %conf_exe_affixes% diff --git a/build.sh.in b/build.sh.in index 2260b1f..f9279b7 100644 --- a/build.sh.in +++ b/build.sh.in @@ -3,7 +3,7 @@ # file : build.sh.in # license : MIT; see accompanying LICENSE file -usage="Usage: $0 [-h|--help] [] []" +usage="Usage: $0 [-h|--help] [] [--] [] [-- ]" # Package repository URL (or path). # @@ -68,8 +68,6 @@ make= make_options= verbose= -cxx= - while test $# -ne 0; do case "$1" in -h|--help) @@ -287,24 +285,53 @@ while test $# -ne 0; do verbose="$1" shift ;; - *) - cxx="$1" + --) shift break ;; + *) + break + ;; esac done -if test -z "$cxx"; then +# Compiler. +# +if test $# -eq 0; then diag "error: compiler executable expected" diag "$usage" exit 1 +else + cxx="$1" + shift fi -# Place default into the $@ array. +# Compile and link options. # -if test $# -eq 0; then - set -- -O3 +compile_ops= +link_ops= + +while test $# -ne 0; do + if test "$1" != "--"; then + compile_ops="$compile_ops $1" + shift + else + shift + break + fi +done + +while test $# -ne 0; do + link_ops="$link_ops $1" + shift +done + +if test -z "$compile_ops"; then + compile_ops=-O3 +fi + +if test -z "$link_ops"; then + link_ops="[null]" fi # Merge jobs and make_options into make. @@ -597,7 +624,8 @@ if test "$local" = true; then run build2/build2/b-boot $verbose configure \ config.config.hermetic=true \ config.cxx="$cxx" \ -config.cc.coptions="$*" \ +config.cc.coptions="${compile_ops# }" \ +config.cc.loptions="${link_ops# }" \ config.bin.lib=shared \ config.bin.rpath="$conf_rpath" \ config.install.root="$idir" \ @@ -687,7 +715,8 @@ run "$bpkg_stage" $verbose create \ cc \ config.config.hermetic=true \ config.cxx="$cxx" \ -config.cc.coptions="$*" \ +config.cc.coptions="${compile_ops# }" \ +config.cc.loptions="${link_ops# }" \ config.bin.lib=shared \ config.bin.rpath="$conf_rpath" \ config.install.root="$idir" \ -- cgit v1.1