diff --git a/.gitignore b/.gitignore index 52e45c485..15a823372 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,10 @@ SconsBuilder* .scon* .build +# sandbox directory # +####################### +sandbox + # Eclipse related files # ######################### .setting* @@ -70,4 +74,4 @@ win/*.suo win/Debug/ win/Release/ win/bin/ -win/bin-debug/ \ No newline at end of file +win/bin-debug/ diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..e151feec3 --- /dev/null +++ b/Rakefile @@ -0,0 +1,67 @@ +testdata_folder = "testdata" #where to locate test data +sandbox = "sandbox" #where to locate builds, server configs and test data +area_name = "amager" #name of OSM data file + +desc "Rebuild, reprocess OSM data and run server" +task :default => [:build, :process, :run] + +desc "Build using Scons" +task :build do + system "scons" +end + + +file "#{sandbox}/#{area_name}.osm.pbf" => "#{testdata_folder}/#{area_name}.osm.pbf" do |t| + raise unless system "cp #{t.prerequisites.join} #{t.name}" +end + +desc "Process OSM test data" +task :process => ["#{sandbox}/#{area_name}.osm.pbf", :setup] do + prev = Dir.pwd + cd sandbox #we must be in the sandbox folder to use the speedprofile.ini in that folder + raise "Error while extracting data." unless system "./osrm-extract #{area_name}.osm.pbf" + raise "Error while preparing data." unless system "./osrm-prepare #{area_name}.osrm #{area_name}.osrm.restrictions" + cd prev +end + +desc "Download fresh OSM for the test data" +task :download => :setup do + start = Time.now + country = 'denmark' + bbox = 'top=55.6655 left=12.5589 bottom=55.6462 right=12.5963' + area = area_name + + raise "Error while downloading data." unless system "curl http://download.geofabrik.de/osm/europe/#{country}.osm.pbf -o #{sandbox}/#{country}.osm.pbf" + raise "Error while cropping data." unless system "osmosis --read-pbf file=#{sandbox}/#{country}.osm.pbf --bounding-box #{bbox} --write-pbf file=#{sandbox}/#{area}.osm.pbf omitmetadata=true" +end + +desc "Setup server files" +task :setup => ["#{sandbox}/speedprofile.ini", "#{sandbox}/extractor.ini", "#{sandbox}/server.ini"] + +file "#{sandbox}/speedprofile.ini" => "speedprofile.ini" do |t| + system "cp #{t.prerequisites.join} #{t.name}" +end + +file "#{sandbox}/extractor.ini" => "extractor.ini" do |t| + system "cp #{t.prerequisites.join} #{t.name}" +end + +file "#{sandbox}/server.ini" => "server.ini" do |t| + #first time the file is copied, we adjusts server settings to point to data files in our sandbox folder + text = File.read(t.prerequisites.join) + text.gsub!('/opt/osm/germany', "#{Dir.pwd}/sandbox/#{area_name}") + file = File.new( t.name, "w+") + file.puts text + file.close +end + +desc "Run the OSRM server" +task :run => :setup do + cd sandbox + system "osrm-routed" +end + +desc "Run all test" +task :test do + puts "Test would go here..." +end \ No newline at end of file diff --git a/SConstruct b/SConstruct index b36216746..9df1512f8 100644 --- a/SConstruct +++ b/SConstruct @@ -49,68 +49,72 @@ 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 }) -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: + env.Append(CCFLAGS = ['-O3', '-DNDEBUG']) + + +if sys.platform == 'darwin': #Mac OS X + env.Append(CPPPATH = ['/usr/include/libxml2'] ) #comes with os x + #assume dependencies are installed with homebrew, and call out get folder locations + import subprocess + stxxl_prefix = subprocess.check_output(["brew", "--prefix", "libstxxl"]).strip() + env.Append(CPPPATH = [stxxl_prefix+"/include"] ) + env.Append(LIBPATH = [stxxl_prefix+"/lib"] ) + + boost_prefix = subprocess.check_output(["brew", "--prefix", "boost"]).strip() + env.Append(CPPPATH = [boost_prefix+"/include"] ) + env.Append(LIBPATH = [boost_prefix+"/lib"] ) + + #libxml2_prefix = subprocess.check_output(["brew", "--prefix", "libxml2"]).strip() + #env.Append(CPPPATH = [libxml2_prefix+"/include"] ) + #env.Append(LIBPATH = [libxml2_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 sys.platform != 'darwin': + if not conf.CheckHeader('omp.h'): + print "Compiler does not support OpenMP. Exiting" Exit(-1) -if not conf.CheckLibWithHeader('bz2', 'bzlib.h', 'CXX'): - print "bz2 library not found. Exiting" - Exit(-1) -if not conf.CheckLibWithHeader('libzip', 'zip.h', 'CXX'): - print "Zip library not found. Exiting" - Exit(-1) -if not conf.CheckLibWithHeader('protobuf', 'google/protobuf/descriptor.h', 'CXX'): - print "Google Protobuffer library not found. Exiting" - Exit(-1) -#check for protobuf 2.3.0 -if not (conf.CheckProtobuf('2.3.0')): - print 'libprotobuf version >= 2.3.0 needed' - Exit(-1); -if not (env.Detect('protoc')): - print 'protobuffer compiler not found' - Exit(-1); -if not conf.CheckLibWithHeader('stxxl', 'stxxl.h', 'CXX'): - print "stxxl library not found. Exiting" - Exit(-1) + if not conf.CheckLibWithHeader('xml2', 'libxml/xmlreader.h', 'CXX'): print "libxml2 library or header not found. Exiting" Exit(-1) @@ -143,12 +147,14 @@ if not conf.CheckLibWithHeader('boost_thread', 'boost/thread.hpp', 'CXX'): if not conf.CheckLibWithHeader('boost_regex', 'boost/regex.hpp', 'CXX'): print "boost/regex.hpp not found. Exiting" Exit(-1) -if not conf.CheckCXXHeader('boost/array.hpp'): - print "boost/thread.hpp not found. Exiting" - Exit(-1) -if not conf.CheckCXXHeader('boost/asio.hpp'): - print "boost/thread.hpp not found. Exiting" - Exit(-1) +if not conf.CheckLib('boost_system', language="C++"): + 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) @@ -191,18 +197,27 @@ if not conf.CheckCXXHeader('boost/tuple/tuple.hpp'): if not conf.CheckCXXHeader('boost/unordered_map.hpp'): print "boost thread header not found. Exiting" Exit(-1) +#if os.sysconf('SC_NPROCESSORS_ONLN') > 1: +# env.Append(CCFLAGS = ' -D_GLIBCXX_PARALLEL'); +if not (conf.CheckBoost('1.41')): + print 'Boost version >= 1.41 needed' + Exit(-1); +#check for protobuf 2.3.0, else rebuild proto files +if not (conf.CheckProtobuf('2.3.0')): + print 'libprotobuf version >= 2.3.0 needed' + Exit(-1); +if not (env.Detect('protoc')): + print 'protobuffer compiler not found' + 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(LINKFLAGS = ['-lboost_system']) -env.Program(target = 'osrm-extract', source = ["extractor.cpp", Glob('DataStructures/pbf-proto/*.pb.cc'), Glob('Util/*.cpp')]) -env.Program(target = 'osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp', Glob('Util/SRTMLookup/*.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'], CCFLAGS = ['-DROUTED']) +env.Program(target = 'sandbox/osrm-extract', source = ["extractor.cpp", 'DataStructures/pbf-proto/fileformat.pb.cc', 'DataStructures/pbf-proto/osmformat.pb.cc']) +env.Program(target = 'sandbox/osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp']) +env.Program(target = 'sandbox/osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp']) env = conf.Finish() diff --git a/testdata/amager.osm.pbf b/testdata/amager.osm.pbf new file mode 100644 index 000000000..bfcb5b654 Binary files /dev/null and b/testdata/amager.osm.pbf differ