import modules ;
import option ;
import os ;
import path ;
import project ;
import build-system ;
import version ;
#Shell with trailing line removed http://lists.boost.org/boost-build/2007/08/17051.php
rule trim-nl ( str extras * ) {
return [ MATCH "([^
]*)" : $(str) ] $(extras) ;
}
rule _shell ( cmd : extras * ) {
return [ trim-nl [ SHELL $(cmd) : $(extras) ] ] ;
}
rule shell_or_fail ( cmd ) {
local ret = [ SHELL $(cmd) : exit-status ] ;
if $(ret[2]) != 0 {
exit $(cmd) failed : 1 ;
}
}
rule shell_or_die ( cmd ) {
local ret = [ SHELL $(cmd) : exit-status ] ;
if $(ret[2]) != 0 {
exit $(cmd) failed : 1 ;
}
return [ trim-nl $(ret[1]) ] ;
}
cxxflags = [ os.environ "CXXFLAGS" ] ;
cflags = [ os.environ "CFLAGS" ] ;
ldflags = [ os.environ "LDFLAGS" ] ;
#Run g++ with empty main and these arguments to see if it passes.
rule test_flags ( flags * : main ? ) {
flags = $(cxxflags) $(ldflags) $(flags) ;
if ! $(main) {
main = "int main() {}" ;
}
local cmd = "bash -c \"g++ "$(flags:J=" ")" -x c++ - <<<'$(main)' -o $(TOP)/dummy >/dev/null 2>/dev/null && rm $(TOP)/dummy 2>/dev/null\"" ;
local ret = [ SHELL $(cmd) : exit-status ] ;
if --debug-configuration in [ modules.peek : ARGV ] {
echo $(cmd) ;
echo $(ret) ;
}
if $(ret[2]) = 0 {
return true ;
} else {
return ;
}
}
rule test_header ( name ) {
return [ test_flags "-include $(name)" ] ;
}
requirements = ;
FORCE-STATIC = [ option.get "static" : : "yes" ] ;
if $(FORCE-STATIC) {
requirements += static static ;
}
rule test_library ( name ) {
if $(FORCE-STATIC) {
return [ test_flags "-Wl,-Bstatic -l$(name) -Wl,-Bdynamic" ] ;
} else {
return [ test_flags "-l$(name)" ] ;
}
}
{
local cleaning = [ option.get "clean" : : yes ] ;
cleaning ?= [ option.get "clean-all" : no : yes ] ;
if "clean" in [ modules.peek : ARGV ] {
cleaning = yes ;
}
constant CLEANING : $(cleaning) ;
}
shared-command-line = ;
local argv = [ modules.peek : ARGV ] ;
while $(argv) {
if $(argv[1]) = "link=shared" {
shared-command-line = shared ;
}
argv = $(argv[2-]) ;
}
#Determine if a library can be compiled statically.
rule auto-shared ( name : additional * ) {
additional ?= "" ;
if $(shared-command-line) = "shared" {
return "shared" ;
} else {
if [ test_flags $(additional)" -Wl,-Bstatic -l"$(name)" -Wl,-Bdynamic" ] {
return ;
} else {
if $(FORCE-STATIC) {
echo "Could not statically link against lib $(name). Your build will probably fail." ;
return ;
} else {
return "shared" ;
}
}
}
}
# MacPorts' default location is /opt/local -- use this if no path is given.
with-macports = [ option.get "with-macports" : : "/opt/local" ] ;
if $(with-macports) {
using darwin ;
ECHO "Using --with-macports=$(with-macports), implying use of darwin GCC" ;
L-boost-search = -L$(with-macports)/lib ;
boost-search = $(with-macports)/lib ;
I-boost-include = -I$(with-macports)/include ;
boost-include = $(with-macports)/include ;
requirements += $(boost-include) ;
} else {
with-boost = [ option.get "with-boost" ] ;
with-boost ?= [ os.environ "BOOST_ROOT" ] ;
if $(with-boost) {
L-boost-search = -L$(with-boost)/lib" "-L$(with-boost)/lib64 ;
boost-search = $(with-boost)/lib $(with-boost)/lib64 ;
I-boost-include = -I$(with-boost)/include ;
boost-include = $(with-boost)/include ;
requirements += $(boost-include) ;
} else {
L-boost-search = "" ;
boost-search = ;
I-boost-include = "" ;
boost-include = ;
}
}
#Convenience rule for boost libraries. Defines library boost_$(name).
rule boost-lib ( name macro : deps * ) {
lib boost_$(name)_static : $(deps) : $(boost-search) boost_$(name)$(boost-lib-version) static ;
lib boost_$(name)_shared : $(deps) : $(boost-search) boost_$(name)$(boost-lib-version) shared : : BOOST_$(macro) ;
alias boost_$(name)_default : $(deps) : static: