From 3faecf9a00512dcbc8712c4bca9adae72fb64410 Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Sat, 12 May 2012 14:01:52 -0400 Subject: Give in and copy bjam into cdec source code --- jam-files/sanity.jam | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 jam-files/sanity.jam (limited to 'jam-files/sanity.jam') diff --git a/jam-files/sanity.jam b/jam-files/sanity.jam new file mode 100644 index 00000000..a89e95f9 --- /dev/null +++ b/jam-files/sanity.jam @@ -0,0 +1,186 @@ +import modules ; +import option ; +import os ; +import path ; +import project ; + +#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) ] ] ; +} + +#Run g++ with empty main and these arguments to see if it passes. +rule test_flags ( flags * ) { + local cmd = "bash -c \"g++ "$(flags:J=" ")" -x c++ - <<<'int main() {}' -o /dev/null >/dev/null 2>/dev/null\"" ; + local ret = [ SHELL $(cmd) : exit-status ] ; + if --debug-configuration in [ modules.peek : ARGV ] { + echo $(cmd) ; + echo $(ret) ; + } + return $(ret[2]) == 0 ; +} + +rule test_header ( name ) { + return [ test_flags "-include $(name)" ] ; +} + +rule test_library ( name ) { + 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) ; +} + +#Determine if a library can be compiled statically. +rule auto-shared ( name : additional * ) { + additional ?= "" ; + if [ test_flags $(additional)" -static -l"$(name) ] { + 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 ; +} +else { + with-boost = [ option.get "with-boost" ] ; + 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 ; + } else { + L-boost-search = "" ; + boost-search = ; + I-boost-include = "" ; + boost-include = ; + } +} + +#Are we linking static binaries against shared boost? +boost-auto-shared = [ auto-shared "boost_program_options" : $(L-boost-search) ] ; +#Convenience rule for boost libraries. Defines library boost_$(name). +rule boost-lib ( name macro ) { + #Link multi-threaded programs against the -mt version if available. Old + #versions of boost do not have -mt tagged versions of all libraries. Sadly, + #boost.jam does not handle this correctly. + if [ test_flags $(L-boost-search)" -lboost_"$(name)"-mt" ] { + lib inner_boost_$(name) : : single $(boost-search) boost_$(name) ; + lib inner_boost_$(name) : : multi $(boost-search) boost_$(name)-mt ; + } else { + lib inner_boost_$(name) : : $(boost-search) boost_$(name) ; + } + + alias boost_$(name) : inner_boost_$(name) : $(boost-auto-shared) : : shared:BOOST_$(macro) $(boost-include) ; +} + +#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_VERSION '\"" ; + 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 ; + } + 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 ; + } + #See tools/build/v2/contrib/boost.jam in a boost distribution for a table of macros to define. + boost-lib thread THREAD_DYN_DLL ; + boost-lib program_options PROGRAM_OPTIONS_DYN_LINK ; + boost-lib unit_test_framework TEST_DYN_LINK ; + boost-lib iostreams IOSTREAMS_DYN_LINK ; + boost-lib serialization SERIALIZATION_DYN_LINK ; + boost-lib mpi MPI_DYN_LINK ; +} + +#Link normally to a library, but sometimes static isn't installed so fall back to dynamic. +rule external-lib ( name : search-path * ) { + lib $(name) : : [ auto-shared $(name) : "-L"$(search-path) ] $(search-path) ; +} + +#Write the current command line to previous.sh. This does not do shell escaping. +{ + local build-log = $(TOP)/previous.sh ; + if ! [ path.exists $(build-log) ] { + SHELL "touch $(build-log) && chmod +x $(build-log)" ; + } + local script = [ modules.peek : ARGV ] ; + if $(script[1]) = "./jam-files/bjam" { + #The ./bjam shell script calls ./jam-files/bjam so that appears in argv but + #we want ./bjam to appear so the environment variables are set correctly. + script = "./bjam "$(script[2-]:J=" ") ; + } else { + script = $(script:J=" ") ; + } + script = "#!/bin/sh\n$(script)\n" ; + local ignored = @($(build-log):E=$(script)) ; +} + +requirements = ; +{ + local cxxflags = [ os.environ "CXXFLAGS" ] ; + local cflags = [ os.environ "CFLAGS" ] ; + local ldflags = [ os.environ "LDFLAGS" ] ; + + #Boost jam's static clang is buggy. + requirements += $(cxxflags) $(cflags) $(ldflags) clang:shared ; + + #libSegFault prints a stack trace on segfault. Link against it if available. + if [ test_flags "-lSegFault" ] { + external-lib SegFault ; + requirements += SegFault ; + } +} + +if [ option.get "git" : : "yes" ] { + local revision = [ _shell "git rev-parse --verify HEAD |head -c 7" ] ; + constant GITTAG : "/"$(revision) ; +} else { + constant GITTAG : "" ; +} + +prefix = [ option.get "prefix" ] ; +if $(prefix) { + prefix = [ path.root $(prefix) [ path.pwd ] ] ; +} else { + prefix = $(TOP)/dist$(GITTAG) ; +} +rule install-bin-libs ( deps * ) { + local bindir = [ option.get "bindir" : $(prefix)/bin ] ; + local libdir = [ option.get "libdir" : $(prefix)/lib ] ; + install prefix-bin : $(deps) : $(bindir) on EXE shared:$(libdir) ; + install prefix-lib : $(deps) : $(libdir) on LIB shared:$(libdir) ; +} +rule install-headers ( name : list * : source-root ? ) { + local includedir = [ option.get "includedir" : $(prefix)/include ] ; + source-root ?= "." ; + install $(name) : $(list) : $(includedir) $(source-root) ; +} + +rule build-projects ( projects * ) { + for p in $(projects) { + build-project $(p) ; + } +} -- cgit v1.2.3 From 5d2fba19f7989b8a2c55834a5735f5fd5b60197c Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Sat, 12 May 2012 14:44:02 -0400 Subject: Build fixes: correct config error, fix paths for tests --- decoder/cfg_test.cc | 3 ++- decoder/hg_test.cc | 3 ++- decoder/hg_test.h | 6 +++--- jam-files/sanity.jam | 6 +++++- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'jam-files/sanity.jam') diff --git a/decoder/cfg_test.cc b/decoder/cfg_test.cc index c61f9f2c..b8f4cf11 100644 --- a/decoder/cfg_test.cc +++ b/decoder/cfg_test.cc @@ -33,7 +33,8 @@ struct CFGTest : public TestWithParam { istringstream ws(wts); EXPECT_TRUE(ws>>featw); CSHOW(featw) - HGSetup::JsonTestFile(&hg,file); + std::string path(boost::unit_test::framework::master_test_suite().argc == 2 ? boost::unit_test::framework::master_test_suite().argv[1] : "test_data"); + HGSetup::JsonTestFile(&hg,path,file); hg.Reweight(featw); cfg.Init(hg,true,true,false); } diff --git a/decoder/hg_test.cc b/decoder/hg_test.cc index 8455a865..92ed98b2 100644 --- a/decoder/hg_test.cc +++ b/decoder/hg_test.cc @@ -335,7 +335,8 @@ BOOST_AUTO_TEST_CASE(TestAddExpectations) { BOOST_AUTO_TEST_CASE(Small) { Hypergraph hg; - CreateSmallHG(&hg); + std::string path(boost::unit_test::framework::master_test_suite().argc == 2 ? boost::unit_test::framework::master_test_suite().argv[1] : "test_data"); + CreateSmallHG(&hg, path); SparseVector wts; wts.set_value(FD::Convert("Model_0"), -2.0); wts.set_value(FD::Convert("Model_1"), -0.5); diff --git a/decoder/hg_test.h b/decoder/hg_test.h index 043f970a..2e308c37 100644 --- a/decoder/hg_test.h +++ b/decoder/hg_test.h @@ -46,10 +46,10 @@ struct HGSetup { ReadFile rf(f); HypergraphIO::ReadFromJSON(rf.stream(), hg); } - static void JsonTestFile(Hypergraph *hg,std::string n) { - JsonFile(hg,"test_data/"+n); + static void JsonTestFile(Hypergraph *hg,std::string path,std::string n) { + JsonFile(hg,path + "/"+n); } - static void CreateSmallHG(Hypergraph *hg) { JsonTestFile(hg,small_json); } + static void CreateSmallHG(Hypergraph *hg, std::string path) { JsonTestFile(hg,path,small_json); } }; namespace { diff --git a/jam-files/sanity.jam b/jam-files/sanity.jam index a89e95f9..eeb59f6e 100644 --- a/jam-files/sanity.jam +++ b/jam-files/sanity.jam @@ -21,7 +21,11 @@ rule test_flags ( flags * ) { echo $(cmd) ; echo $(ret) ; } - return $(ret[2]) == 0 ; + if $(ret[2]) = 0 { + return true ; + } else { + return ; + } } rule test_header ( name ) { -- cgit v1.2.3 From 2f64af3e06a518b93f7ca2c30a9d0aeb2c947031 Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Sat, 12 May 2012 15:18:29 -0400 Subject: with-google-hash option, more respect for environment variables --- Jamroot | 15 +++++++++++++-- jam-files/sanity.jam | 12 +++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'jam-files/sanity.jam') diff --git a/Jamroot b/Jamroot index b5b786cd..f873db68 100644 --- a/Jamroot +++ b/Jamroot @@ -1,10 +1,21 @@ +#cdec compilation with bjam +# +#--with-boost=/usr/include +#--with-google-hash=/usr/include so that $with-google-hash/google/dense_hash_map exists +# +#-a forces the build to run from scratch +#-jN parallelizes just like make +# +#Respects CXXFLAGS, CFLAGS, and LDFLAGS environment variables. + path-constant TOP : . ; include $(TOP)/jam-files/sanity.jam ; boost 104400 ; external-lib z ; -if [ test_header google/dense_hash_map ] { - requirements += HAVE_SPARSEHASH ; +with-google-hash = [ option.get "with-google-hash" ] ; +if [ test_header google/dense_hash_map ] || $(with-google-hash) { + requirements += HAVE_SPARSEHASH $(with-google-hash) ; } if [ test_header boost/serialization/map.hpp ] && [ test_library boost_serialization ] { diff --git a/jam-files/sanity.jam b/jam-files/sanity.jam index eeb59f6e..9c75c247 100644 --- a/jam-files/sanity.jam +++ b/jam-files/sanity.jam @@ -13,9 +13,15 @@ rule _shell ( cmd : extras * ) { return [ trim-nl [ SHELL $(cmd) : $(extras) ] ] ; } +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 * ) { - local cmd = "bash -c \"g++ "$(flags:J=" ")" -x c++ - <<<'int main() {}' -o /dev/null >/dev/null 2>/dev/null\"" ; + local add = $(CXXFLAGS) $(LDFLAGS) ; + add ?= "" ; + local cmd = "bash -c \"g++ $(add) "$(flags:J=" ")" -x c++ - <<<'int main() {}' -o /dev/null >/dev/null 2>/dev/null\"" ; local ret = [ SHELL $(cmd) : exit-status ] ; if --debug-configuration in [ modules.peek : ARGV ] { echo $(cmd) ; @@ -144,10 +150,6 @@ rule external-lib ( name : search-path * ) { requirements = ; { - local cxxflags = [ os.environ "CXXFLAGS" ] ; - local cflags = [ os.environ "CFLAGS" ] ; - local ldflags = [ os.environ "LDFLAGS" ] ; - #Boost jam's static clang is buggy. requirements += $(cxxflags) $(cflags) $(ldflags) clang:shared ; -- cgit v1.2.3