From 4f8d7b00e9cb2163448e9d01483e04e0cf9be3e7 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Thu, 1 Dec 2011 20:17:55 +0100 Subject: [PATCH 1/3] Rakefile for building binaries --- .gitignore | 4 +++ Rakefile | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 Rakefile diff --git a/.gitignore b/.gitignore index 6ce0714bd..d82026a43 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,10 @@ SconsBuilder* .scon* .build +# Rake build directory # +####################### +build + # Eclipse related files # ######################### .setting* diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..fd257fc4c --- /dev/null +++ b/Rakefile @@ -0,0 +1,75 @@ + +build_dir = "build" +compiler = 'g++' #build osrm with the default gcc 4.2. +opt = '' #don't use OpenMP +proto = 'DataStructures/pbf-proto' +formats = "-L#{proto} -losmformat.pb.o -lfileformat.pb.o" + +#assume libs are installed with homebrew +#call out to the brew binary to find folders with latest version +stxxl_prefix = `brew --prefix libstxxl`.strip +boost_prefix = `brew --prefix boost`.strip +stxxl = "-I#{stxxl_prefix}/include -L#{stxxl_prefix}/lib -lstxxl " +boost = "-L#{boost_prefix}/lib -lboost_system-mt -lboost_thread-mt -lboost_regex-mt -lboost_iostreams-mt " + +xml2 = "-I/usr/include/libxml2 -lxml2 " +bz = "-lbz2 -lz " +pbf = "-lprotobuf " + + +task :default => 'compile' + +desc "Compile OSRM" +task :compile => [build_dir, "protobuffer", "binaries"] do + puts "Done." +end + +directory build_dir + + +#compile protobuffer files +task "protobuffer" => ["#{proto}/fileformat.pb.o", "#{proto}/osmformat.pb.o" ] + +file "#{proto}/fileformat.pb.o" => ["#{proto}/fileformat.pb.cc"] do |t| + sh "#{compiler} -c #{proto}/fileformat.pb.cc -o #{proto}/fileformat.pb.o #{opt}" +end + +file "#{proto}/osmformat.pb.o" => ["#{proto}/osmformat.pb.cc"] do |t| + sh "#{compiler} -c #{proto}/osmformat.pb.cc -o #{proto}/osmformat.pb.o #{opt}" +end + +file "#{proto}/fileformat.pb.cc" => ["#{proto}/fileformat.proto"] do |t| + sh "protoc #{proto}/fileformat.proto -I=#{proto} --cpp_out=#{proto}" +end + +file "#{proto}/osmformat.pb.cc" => ["#{proto}/osmformat.proto"] do |t| + sh "protoc #{proto}/osmformat.proto -I=#{proto} --cpp_out=#{proto}" +end + +#compile binaries +task "binaries" => ["#{build_dir}/osrm-extract", "#{build_dir}/osrm-prepare", "#{build_dir}/osrm-routed" ] + +def cpp_files prerequisites + prerequisites.select { |f| f =~ /.cpp$/ } +end + +task :headers => FileList['typedefs.h', 'DataStructures/*.h', 'Contractor/*.h', 'Util/*.h'] + +file "#{build_dir}/osrm-extract" => :headers +file "#{build_dir}/osrm-extract" => ['extractor.cpp'] do |t| + sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost+bz+pbf+formats} #{opt}" +end + +file "#{build_dir}/osrm-prepare" => :headers +file "#{build_dir}/osrm-prepare" => ['createHierarchy.cpp', 'Contractor/EdgeBasedGraphFactory.cpp'] do |t| + sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost} #{opt}" +end + +file "#{build_dir}/osrm-routed" => :headers +file "#{build_dir}/osrm-routed" => FileList['Descriptors/*.h', 'Server/*.h', 'Plugins/*.h'] +file "#{build_dir}/osrm-routed" => ['routed.cpp', 'Descriptors/DescriptionFactory.cpp'] do |t| + sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost+bz} #{opt}" +end + + + From cccd76b39ef34d9b3ba86cb3e305cab47a35bed8 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 3 Dec 2011 08:33:33 +0100 Subject: [PATCH 2/3] updated SConstruct file to compile on Mac --- SConstruct | 90 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/SConstruct b/SConstruct index 0440fa32b..5cbab86de 100644 --- a/SConstruct +++ b/SConstruct @@ -49,49 +49,65 @@ def CheckProtobuf(context, version): context.Result(ret) return ret + AddOption('--cxx', dest='cxx', type='string', nargs=1, action='store', metavar='STRING', help='C++ Compiler') AddOption('--stxxlroot', dest='stxxlroot', type='string', nargs=1, action='store', metavar='STRING', help='root directory of STXXL') AddOption('--verbosity', dest='verbosity', type='string', nargs=1, action='store', metavar='STRING', help='make Scons talking') AddOption('--buildconfiguration', dest='buildconfiguration', type='string', nargs=1, action='store', metavar='STRING', help='debug or release') -env = Environment(ENV = {'PATH' : os.environ['PATH']} ,COMPILER = GetOption('cxx')) -if sys.platform.startswith("freebsd"): - env.ParseConfig('pkg-config --cflags --libs protobuf') + +env = Environment( ENV = {'PATH' : os.environ['PATH']} ,COMPILER = GetOption('cxx')) +conf = Configure(env, custom_tests = { 'CheckBoost' : CheckBoost, 'CheckProtobuf' : CheckProtobuf }) + + if GetOption('cxx') is None: #default Compiler print 'Using default C++ Compiler: ', env['CXX'] else: env.Replace(CXX = GetOption('cxx')) print 'Using user supplied C++ Compiler: ', env['CXX'] -if GetOption('stxxlroot') is not None: - env.Append(CPPPATH = GetOption('stxxlroot')+'/include') - env.Append(LIBPATH = GetOption('stxxlroot')+'/lib') - print 'STXXLROOT = ', GetOption('stxxlroot') -if sys.platform == 'win32': - #SCons really wants to use Microsoft compiler - print "Compiling is not yet supported on Windows" - Exit(-1) -else: #Mac OS X - if sys.platform == 'darwin': - print "Compiling is experimental on Mac" - env.Append(CPPPATH = ['/opt/local/include/', '/opt/local/include/libxml2']) - env.Append(LIBPATH = ['/opt/local/lib']) - elif sys.platform.startswith('freebsd'): - env.Append(CPPPATH = ['/usr/local/include', '/usr/local/include/libxml2']) - env.Append(LIBPATH = ['/usr/local/lib']) - else: - env.Append(CPPPATH = ['/usr/include', '/usr/include/include', '/usr/include/libxml2/']) + if GetOption('buildconfiguration') == 'debug': env.Append(CCFLAGS = ['-Wall', '-g3', '-rdynamic']) else: - env.Append(CCFLAGS = ['-O3', '-DNDEBUG', '-march=native']) -#print "Compiling with: ", env['CXX'] -conf = Configure(env, custom_tests = { 'CheckBoost' : CheckBoost, 'CheckProtobuf' : CheckProtobuf }) + env.Append(CCFLAGS = ['-O3', '-DNDEBUG']) + + +if sys.platform == 'darwin': #Mac OS X + env.Append(CPPPATH = ['/usr/include/libxml2'] ) #comes with os x + #assume stxxl and boost are installed via homebrew. + #call out to brew to get the folder locations + import subprocess + stxxl_prefix = subprocess.check_output(["brew", "--prefix", "libstxxl"]).strip() + boost_prefix = subprocess.check_output(["brew", "--prefix", "boost"]).strip() + env.Append(CPPPATH = [stxxl_prefix+"/include"] ) + env.Append(LIBPATH = [stxxl_prefix+"/lib"] ) + env.Append(CPPPATH = [boost_prefix+"/include"] ) + env.Append(LIBPATH = [boost_prefix+"/lib"] ) +elif sys.platform.startswith("freebsd"): + env.ParseConfig('pkg-config --cflags --libs protobuf') + env.Append(CPPPATH = ['/usr/local/include', '/usr/local/include/libxml2']) + env.Append(LIBPATH = ['/usr/local/lib']) + if GetOption('stxxlroot') is not None: + env.Append(CPPPATH = GetOption('stxxlroot')+'/include') + env.Append(LIBPATH = GetOption('stxxlroot')+'/lib') + print 'STXXLROOT = ', GetOption('stxxlroot') + if GetOption('buildconfiguration') != 'debug': + env.Append(CCFLAGS = ['-march=native']) + #print "Compiling with: ", env['CXX'] + env.Append(CCFLAGS = ['-fopenmp']) + env.Append(LINKFLAGS = ['-fopenmp']) +elif sys.platform == 'win32': + #SCons really wants to use Microsoft compiler + print "Compiling is not yet supported on Windows" + Exit(-1) +else: + print "Unknown platform.." + env.Append(CPPPATH = ['/usr/include', '/usr/include/include', '/usr/include/libxml2/']) + + if not conf.CheckHeader('omp.h'): print "Compiler does not support OpenMP. Exiting" - if sys.platform == 'darwin': - print "Continuing because we are on Mac. This might be fatal." - else: - Exit(-1) + Exit(-1) if not conf.CheckLibWithHeader('xml2', 'libxml/xmlreader.h', 'CXX'): print "libxml2 library or header not found. Exiting" Exit(-1) @@ -131,8 +147,13 @@ if not conf.CheckCXXHeader('boost/thread.hpp'): print "boost thread header not found. Exiting" Exit(-1) if not conf.CheckLib('boost_system', language="C++"): - print "boost_system library not found. Exiting" - Exit(-1) + if not conf.CheckLib('boost_system-mt', language="C++"): + print "boost_system library not found. Exiting" + Exit(-1) + else: + print "using boost -mt" + env.Append(CCFLAGS = ' -lboost_system-mt') + env.Append(LINKFLAGS = ' -lboost_system-mt') if not conf.CheckCXXHeader('boost/bind.hpp'): print "boost/bind.hpp not found. Exiting" Exit(-1) @@ -162,19 +183,18 @@ if not (conf.CheckProtobuf('2.3.0')): Exit(-1); if not (env.Detect('protoc')): print 'protobuffer compiler not found' - Exit(-1); + + protobld = Builder(action = 'protoc -I=DataStructures/pbf-proto --cpp_out=DataStructures/pbf-proto $SOURCE') env.Append(BUILDERS = {'Protobuf' : protobld}) env.Protobuf('DataStructures/pbf-proto/fileformat.proto') env.Protobuf('DataStructures/pbf-proto/osmformat.proto') -env.Append(CCFLAGS = ['-fopenmp']) -env.Append(LINKFLAGS = ['-fopenmp']) +env.Append(CCFLAGS = ['-lboost_regex', '-lboost_iostreams', '-lbz2', '-lz', '-lprotobuf']) +#env.Append(LINKFLAGS = ['-lboost_system']) env.Program(target = 'osrm-extract', source = ["extractor.cpp", 'DataStructures/pbf-proto/fileformat.pb.cc', 'DataStructures/pbf-proto/osmformat.pb.cc']) env.Program(target = 'osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp']) -env.Append(CCFLAGS = ['-lboost_regex', '-lboost_iostreams', '-lbz2', '-lz', '-lprotobuf']) -env.Append(LINKFLAGS = ['-lboost_system']) env.Program(target = 'osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp']) env = conf.Finish() From 1c38827b556ab057dde32f76b20e3a908cd48ad0 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 3 Dec 2011 08:34:57 +0100 Subject: [PATCH 3/3] remove rakefile --- Rakefile | 75 -------------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 Rakefile diff --git a/Rakefile b/Rakefile deleted file mode 100644 index fd257fc4c..000000000 --- a/Rakefile +++ /dev/null @@ -1,75 +0,0 @@ - -build_dir = "build" -compiler = 'g++' #build osrm with the default gcc 4.2. -opt = '' #don't use OpenMP -proto = 'DataStructures/pbf-proto' -formats = "-L#{proto} -losmformat.pb.o -lfileformat.pb.o" - -#assume libs are installed with homebrew -#call out to the brew binary to find folders with latest version -stxxl_prefix = `brew --prefix libstxxl`.strip -boost_prefix = `brew --prefix boost`.strip -stxxl = "-I#{stxxl_prefix}/include -L#{stxxl_prefix}/lib -lstxxl " -boost = "-L#{boost_prefix}/lib -lboost_system-mt -lboost_thread-mt -lboost_regex-mt -lboost_iostreams-mt " - -xml2 = "-I/usr/include/libxml2 -lxml2 " -bz = "-lbz2 -lz " -pbf = "-lprotobuf " - - -task :default => 'compile' - -desc "Compile OSRM" -task :compile => [build_dir, "protobuffer", "binaries"] do - puts "Done." -end - -directory build_dir - - -#compile protobuffer files -task "protobuffer" => ["#{proto}/fileformat.pb.o", "#{proto}/osmformat.pb.o" ] - -file "#{proto}/fileformat.pb.o" => ["#{proto}/fileformat.pb.cc"] do |t| - sh "#{compiler} -c #{proto}/fileformat.pb.cc -o #{proto}/fileformat.pb.o #{opt}" -end - -file "#{proto}/osmformat.pb.o" => ["#{proto}/osmformat.pb.cc"] do |t| - sh "#{compiler} -c #{proto}/osmformat.pb.cc -o #{proto}/osmformat.pb.o #{opt}" -end - -file "#{proto}/fileformat.pb.cc" => ["#{proto}/fileformat.proto"] do |t| - sh "protoc #{proto}/fileformat.proto -I=#{proto} --cpp_out=#{proto}" -end - -file "#{proto}/osmformat.pb.cc" => ["#{proto}/osmformat.proto"] do |t| - sh "protoc #{proto}/osmformat.proto -I=#{proto} --cpp_out=#{proto}" -end - -#compile binaries -task "binaries" => ["#{build_dir}/osrm-extract", "#{build_dir}/osrm-prepare", "#{build_dir}/osrm-routed" ] - -def cpp_files prerequisites - prerequisites.select { |f| f =~ /.cpp$/ } -end - -task :headers => FileList['typedefs.h', 'DataStructures/*.h', 'Contractor/*.h', 'Util/*.h'] - -file "#{build_dir}/osrm-extract" => :headers -file "#{build_dir}/osrm-extract" => ['extractor.cpp'] do |t| - sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost+bz+pbf+formats} #{opt}" -end - -file "#{build_dir}/osrm-prepare" => :headers -file "#{build_dir}/osrm-prepare" => ['createHierarchy.cpp', 'Contractor/EdgeBasedGraphFactory.cpp'] do |t| - sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost} #{opt}" -end - -file "#{build_dir}/osrm-routed" => :headers -file "#{build_dir}/osrm-routed" => FileList['Descriptors/*.h', 'Server/*.h', 'Plugins/*.h'] -file "#{build_dir}/osrm-routed" => ['routed.cpp', 'Descriptors/DescriptionFactory.cpp'] do |t| - sh "#{compiler} -o #{t.name} #{cpp_files(t.prerequisites).join ' '} #{stxxl+xml2+boost+bz} #{opt}" -end - - -