mosesdecoder/Jamroot

242 lines
8.3 KiB
Plaintext
Raw Normal View History

2011-11-25 21:30:36 +04:00
#BUILDING MOSES
#
2011-11-25 21:30:36 +04:00
#PACKAGES
#Language models (optional):
2011-11-25 15:55:36 +04:00
#--with-irstlm=/path/to/irstlm
#--with-srilm=/path/to/srilm See moses/src/LM/Jamfile for more options.
#--with-randlm=/path/to/randlm
#KenLM is always compiled.
#
2011-11-25 15:55:36 +04:00
#--with-boost=/path/to/boost
#If Boost is in a non-standard location, specify it here. This directory is
#expected to contain include and lib or lib64.
#
2011-11-21 21:19:24 +04:00
#--with-xmlrpc-c=/path/to/xmlrpc-c for libxmlrpc-c (used by server)
#Note that, like language models, this is the --prefix where the library was
#installed, not some executable within the library.
#
2011-11-25 20:53:02 +04:00
#--with-giza=/path/to/giza
#Indicates where binaries GIZA++, snt2cooc.out, and mkcls live.
#Builds scripts/training/train-model.perl using these paths.
#
#Thread-caching malloc (optional):
#--with-tcmalloc
2011-11-21 21:19:24 +04:00
#
#REGRESSION TESTING
#--with-regtest=/path/to/moses-reg-test-data
#
#
2011-11-25 20:53:02 +04:00
#INSTALLATION
2011-11-28 16:01:33 +04:00
#--prefix=/path/to/prefix sets the install prefix [dist].
#--bindir=/path/to/prefix/bin sets the bin directory [PREFIX/bin]
#--libdir=/path/to/prefix/lib sets the lib directory [PREFIX/lib]
2012-02-13 23:31:37 +04:00
#--includedir=/path/to/prefix/include installs headers.
# Does not install if missing. No argument defaults to PREFIX/include .
2011-11-25 20:53:02 +04:00
#--install-scripts=/path/to/scripts copies scripts into a directory.
2011-11-28 16:01:33 +04:00
#--git appends the git revision to the prefix directory.
2011-11-21 21:19:24 +04:00
#
2011-11-25 21:30:36 +04:00
#
#BUILD OPTIONS
2011-11-23 15:29:42 +04:00
# By default, the build is multi-threaded, optimized, and statically linked.
# Pass these to change the build:
#
2011-11-23 15:29:42 +04:00
# threading=single|multi controls threading (default multi)
#
2011-11-23 15:29:42 +04:00
# variant=release|debug|profile builds optimized (default), for debug, or for
# profiling
#
# link=static|shared controls linking (default static)
#
# debug-symbols=on|off include (default) or exclude debugging
# information also known as -g
#
2011-11-25 22:09:07 +04:00
# --notrace compiles without TRACE macros
2011-11-25 21:30:36 +04:00
#
2011-11-27 20:53:40 +04:00
# --enable-boost-pool uses Boost pools for the memory SCFG table
#
2011-11-23 15:29:42 +04:00
#
2011-11-25 21:30:36 +04:00
#CONTROLLING THE BUILD
2011-11-21 21:19:24 +04:00
#-a to build from scratch
#-j$NCPUS to compile in parallel
2011-11-23 15:29:42 +04:00
#--clean to clean
2011-12-05 15:09:48 +04:00
import option ;
import modules ;
2012-03-31 03:57:05 +04:00
import path ;
2011-12-05 15:09:48 +04:00
path-constant TOP : . ;
# Shell with trailing line removed http://lists.boost.org/boost-build/2007/08/17051.php
2011-11-30 12:53:13 +04:00
rule trim-nl ( str extras * ) {
return [ MATCH "([^
2011-11-30 12:53:13 +04:00
]*)" : $(str) ] $(extras) ;
}
2011-11-30 12:53:13 +04:00
rule _shell ( cmd : extras * ) {
return [ trim-nl [ SHELL $(cmd) : $(extras) ] ] ;
}
local cleaning = [ option.get "clean" : : yes ] ;
2011-12-05 14:53:35 +04:00
cleaning ?= [ option.get "clean-all" : no : yes ] ;
2011-12-05 15:09:48 +04:00
if "clean" in [ modules.peek : ARGV ] {
cleaning = yes ;
}
constant CLEANING : $(cleaning) ;
2011-12-05 14:53:35 +04:00
2011-11-27 20:53:40 +04:00
#Run g++ with empty main and these arguments to see if it passes.
rule test_flags ( flags ) {
if [ SHELL $(TOP)"/jam-files/test.sh "$(flags) ] = 0 {
return true ;
} else {
return ;
}
}
2011-11-27 20:53:40 +04:00
#Determine if a library can be compiled statically.
2011-11-25 15:55:36 +04:00
rule auto_shared ( name : additional ? ) {
additional ?= "" ;
if [ test_flags $(additional)" -static -l"$(name) ] {
return ;
} else {
return "<link>shared" ;
}
}
2011-11-25 15:55:36 +04:00
with-boost = [ option.get "with-boost" ] ;
if $(with-boost) {
L-boost-search = -L$(with-boost)/lib" "-L$(with-boost)/lib64 ;
boost-search = <search>$(with-boost)/lib <search>$(with-boost)/lib64 ;
2011-11-26 16:18:17 +04:00
I-boost-include = -I$(with-boost)/include ;
2011-11-25 15:55:36 +04:00
boost-include = <include>$(with-boost)/include ;
} else {
L-boost-search = "" ;
boost-search = ;
2011-11-26 16:18:17 +04:00
I-boost-include = "" ;
boost-include = ;
}
2011-12-05 14:53:35 +04:00
boost-shell = [ SHELL "g++ "$(I-boost-include)" -dM -x c++ -E /dev/null -include boost/version.hpp 2>/dev/null |grep '#define BOOST_VERSION '" : exit-status ] ;
if $(boost-shell[2]) != 0 && $(CLEANING) = no {
2011-11-26 16:18:17 +04:00
exit Boost does not seem to be installed or g++ is confused. : 1 ;
}
boost-version = [ MATCH "#define BOOST_VERSION ([0-9]*)" : $(boost-shell[1]) ] ;
2011-12-05 14:53:35 +04:00
if $(boost-version) < 103600 && $(cleaning) = no {
2011-11-26 16:18:17 +04:00
exit You have Boost $(boost-version). Moses requires at least 103600 (and preferably newer). : 1 ;
2011-11-25 15:55:36 +04:00
}
#Are we linking static binaries against shared boost?
2011-12-01 16:11:58 +04:00
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 ) {
2011-11-27 20:53:40 +04:00
#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.
2011-11-25 15:55:36 +04:00
if [ test_flags $(L-boost-search)" -lboost_"$(name)"-mt" ] {
lib inner_boost_$(name) : : <threading>single $(boost-search) <name>boost_$(name) ;
lib inner_boost_$(name) : : <threading>multi $(boost-search) <name>boost_$(name)-mt ;
} else {
2011-11-25 15:55:36 +04:00
lib inner_boost_$(name) : : $(boost-search) <name>boost_$(name) ;
}
2011-11-25 15:55:36 +04:00
alias boost_$(name) : inner_boost_$(name) : $(boost-auto-shared) : : <link>shared:<define>BOOST_$(macro) $(boost-include) ;
}
#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 ;
#Link normally to a library, but sometimes static isn't installed so fall back to dynamic.
rule external_lib ( name ) {
lib $(name) : : [ auto_shared $(name) ] ;
}
external_lib z ;
requirements = ;
#libSegFault prints a stack trace on segfault. Link against it if available.
if [ test_flags "-lSegfault" ] {
external_lib SegFault ;
requirements += <library>SegFault ;
}
if [ option.get "with-tcmalloc" : : "yes" ] {
external_lib tcmalloc ;
requirements += <library>tcmalloc ;
}
requirements += [ option.get "notrace" : <define>TRACE_ENABLE=1 ] ;
requirements += [ option.get "enable-boost-pool" : : <define>USE_BOOST_POOL ] ;
2011-11-28 13:35:46 +04:00
import os ;
cxxflags = [ os.environ "CXXFLAGS" ] ;
cflags = [ os.environ "CFLAGS" ] ;
ldflags = [ os.environ "LDFLAGS" ] ;
project : default-build
<threading>multi
<warnings>on
<debug-symbols>on
<variant>release
<link>static
;
project : requirements
<threading>multi:<define>WITH_THREADS
<threading>multi:<library>boost_thread
<define>_FILE_OFFSET_BITS=64 <define>_LARGE_FILES
$(requirements)
2012-05-07 04:13:19 +04:00
<os>LINUX,<link>static,<toolset>clang:<linkflags>-static #apparently bjam doesn't pass -static properly.
2011-11-28 13:35:46 +04:00
<cxxflags>$(cxxflags)
<cflags>$(cflags)
<linkflags>$(ldflags)
;
#Add directories here if you want their incidental targets too (i.e. tests).
build-project lm ;
build-project util ;
#Trigger instllation into legacy paths.
2011-11-26 02:14:04 +04:00
build-project mert ;
build-project moses-cmd/src ;
build-project moses-chart-cmd/src ;
2011-11-26 16:18:17 +04:00
#Scripts have their own binaries.
2011-11-25 20:53:02 +04:00
build-project scripts ;
#Regression tests (only does anything if --with-regtest is passed)
build-project regression-testing ;
if [ option.get "git" : : "yes" ] {
2011-11-25 18:41:49 +04:00
local revision = [ _shell "git rev-parse --verify HEAD |head -c 7" ] ;
2011-11-28 16:01:33 +04:00
constant GITTAG : "/"$(revision) ;
2011-11-25 18:41:49 +04:00
} else {
constant GITTAG : "" ;
}
alias programs : lm//query lm//build_binary moses-chart-cmd/src//moses_chart moses-cmd/src//programs OnDiskPt//CreateOnDisk mert//programs contrib/server//mosesserver misc//programs ;
2011-11-28 16:01:33 +04:00
prefix = [ option.get "prefix" : $(TOP)/dist$(GITTAG) ] ;
bindir = [ option.get "bindir" : $(prefix)/bin ] ;
libdir = [ option.get "libdir" : $(prefix)/lib ] ;
install prefix-bin : programs : <location>$(bindir) <install-dependencies>on <install-type>EXE <link>shared:<dll-path>$(libdir) ;
install prefix-lib : programs : <location>$(libdir) <install-dependencies>on <install-type>LIB <link>shared:<dll-path>$(libdir) ;
2012-02-13 23:31:37 +04:00
includedir = [ option.get "includedir" : : $(prefix)/include ] ;
if $(includedir) {
install prefix-header : [ glob-tree *.h *.hh : jam-files dist kenlm moses ] : <location>$(includedir) <install-source-root>. ;
install prefix-moses-header : moses/src//headers-to-install : <location>$(includedir) <install-source-root>moses/src ;
}
2012-03-31 03:57:05 +04:00
#Write the current command line to previous.sh. This does not do shell escaping.
path-constant BUILD-LOG : 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=" ") ;
}
2012-03-31 03:57:05 +04:00
script = "#!/bin/sh\n$(script)\n" ;
local ignored = @($(BUILD-LOG):E=$(script)) ;