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:boost_$(name)_static shared:boost_$(name)_shared ;
alias boost_$(name)_static_works : $(deps) : [ check-target-builds empty_test_shared "Shared Boost" : boost_$(name)_default : boost_$(name)_static ] ;
alias boost_$(name) : $(deps) : [ check-target-builds empty_test_static "Static Boost" : boost_$(name)_static_works : boost_$(name)_shared ] ;
}
#Argument is e.g. 103600
rule boost ( min-version ) {
local cmd = "bash -c \"g++ "$(I-boost-include)" -dM -x c++ -E /dev/null -include boost/version.hpp 2>/dev/null |grep '#define BOOST_'\"" ;
local boost-shell = [ SHELL "$(cmd)" : exit-status ] ;
if $(boost-shell[2]) != 0 && $(CLEANING) = no {
echo Failed to run "$(cmd)" ;
exit Boost does not seem to be installed or g++ is confused. : 1 ;
}
constant BOOST-VERSION : [ MATCH "#define BOOST_VERSION ([0-9]*)" : $(boost-shell[1]) ] ;
if $(BOOST-VERSION) < $(min-version) && $(CLEANING) = no {
exit You have Boost $(BOOST-VERSION). This package requires Boost at least $(min-version) (and preferably newer). : 1 ;
}
# If matching version tags exist, use them.
boost-lib-version = [ MATCH "#define BOOST_LIB_VERSION \"([^\"]*)\"" : $(boost-shell[1]) ] ;
if [ test_flags $(L-boost-search)" -lboost_program_options-"$(boost-lib-version) ] {
boost-lib-version = "-"$(boost-lib-version) ;
} else {
boost-lib-version = "" ;
}
#Crazy amount of testing to make sure that BOOST_TEST_DYN_LINK is defined properly.
lib boost_unit_test_framework_static_test : : $(boost-search) boost_unit_test_framework$(boost-lib-version) static ;
obj empty_test_static.o : jam-files/empty_test_main.cc boost_unit_test_framework_static_test : $(boost-include) ;
exe empty_test_static : empty_test_static.o boost_unit_test_framework_static_test ;
lib boost_unit_test_framework_shared_test : : $(boost-search) boost_unit_test_framework$(boost-lib-version) shared : : BOOST_TEST_DYN_LINK ;
obj empty_test_shared.o : jam-files/empty_test_main.cc boost_unit_test_framework_shared_test : $(boost-include) ;
exe empty_test_shared : empty_test_shared.o boost_unit_test_framework_shared_test ;
explicit empty_test_static.o empty_test_static empty_test_shared.o empty_test_shared ;
#See tools/build/v2/contrib/boost.jam in a boost distribution for a table of macros to define.
boost-lib system SYSTEM_DYN_LINK ;
boost-lib thread THREAD_DYN_DLL : boost_system ;
boost-lib program_options PROGRAM_OPTIONS_DYN_LINK ;
boost-lib iostreams IOSTREAMS_DYN_LINK ;
boost-lib filesystem FILE_SYSTEM_DYN_LINK ;
boost-lib unit_test_framework TEST_DYN_LINK ;
# if $(BOOST-VERSION) >= 104800 {
# boost-lib chrono CHRONO_DYN_LINK ;
# boost-lib timer TIMER_DYN_LINK : boost_chrono ;
# }
}
#Link normally to a library, but sometimes static isn't installed so fall back to dynamic.
rule external-lib ( name : search-path * : deps * ) {
lib $(name) : : [ auto-shared $(name) : "-L"$(search-path) ] $(search-path)