| 1 | # |
|---|
| 2 | # This file is part of Mapnik (c++ mapping toolkit) |
|---|
| 3 | # |
|---|
| 4 | # Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon |
|---|
| 5 | # |
|---|
| 6 | # Mapnik is free software; you can redistribute it and/or |
|---|
| 7 | # modify it under the terms of the GNU Lesser General Public |
|---|
| 8 | # License as published by the Free Software Foundation; either |
|---|
| 9 | # version 2.1 of the License, or (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This library is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 14 | # Lesser General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU Lesser General Public |
|---|
| 17 | # License along with this library; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | # |
|---|
| 20 | # $Id$ |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | import os, sys, platform |
|---|
| 24 | |
|---|
| 25 | if platform.uname()[4] == 'x86_64': |
|---|
| 26 | LIBDIR_SCHEMA='lib64' |
|---|
| 27 | else: |
|---|
| 28 | LIBDIR_SCHEMA='lib' |
|---|
| 29 | |
|---|
| 30 | #### SCons build options and initial setup #### |
|---|
| 31 | |
|---|
| 32 | # All of the following options may be modified at the command-line, for example: |
|---|
| 33 | # `python scons/scons PREFIX=/opt` |
|---|
| 34 | opts = Options('config.py') |
|---|
| 35 | opts.Add('CXX', 'The C++ compiler to use (defaults to g++).', 'g++') |
|---|
| 36 | opts.Add('PREFIX', 'The install path "prefix"', '/usr/local') |
|---|
| 37 | opts.Add(PathOption('BOOST_INCLUDES', 'Search path for boost include files', '/usr/include')) |
|---|
| 38 | opts.Add(PathOption('BOOST_LIBS', 'Search path for boost library files', '/usr/' + LIBDIR_SCHEMA)) |
|---|
| 39 | opts.Add('BOOST_TOOLKIT','Specify boost toolkit e.g. gcc41.','',False) |
|---|
| 40 | opts.Add(('FREETYPE_CONFIG', 'The path to the freetype-config executable.', 'freetype-config')) |
|---|
| 41 | opts.Add(('XML2_CONFIG', 'The path to the xml2-config executable.', 'xml2-config')) |
|---|
| 42 | opts.Add(PathOption('FRIBIDI_INCLUDES', 'Search path for fribidi include files', '/usr/include')) |
|---|
| 43 | opts.Add(PathOption('FRIBIDI_LIBS','Search path for fribidi include files','/usr/' + LIBDIR_SCHEMA)) |
|---|
| 44 | opts.Add(PathOption('PNG_INCLUDES', 'Search path for libpng include files', '/usr/include')) |
|---|
| 45 | opts.Add(PathOption('PNG_LIBS','Search path for libpng include files','/usr/' + LIBDIR_SCHEMA)) |
|---|
| 46 | opts.Add(PathOption('JPEG_INCLUDES', 'Search path for libjpeg include files', '/usr/include')) |
|---|
| 47 | opts.Add(PathOption('JPEG_LIBS', 'Search path for libjpeg library files', '/usr/' + LIBDIR_SCHEMA)) |
|---|
| 48 | opts.Add(PathOption('TIFF_INCLUDES', 'Search path for libtiff include files', '/usr/include')) |
|---|
| 49 | opts.Add(PathOption('TIFF_LIBS', 'Search path for libtiff library files', '/usr/' + LIBDIR_SCHEMA)) |
|---|
| 50 | opts.Add(PathOption('PGSQL_INCLUDES', 'Search path for PostgreSQL include files', '/usr/include')) |
|---|
| 51 | opts.Add(PathOption('PGSQL_LIBS', 'Search path for PostgreSQL library files', '/usr/' + LIBDIR_SCHEMA)) |
|---|
| 52 | opts.Add(PathOption('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/local/include')) |
|---|
| 53 | opts.Add(PathOption('PROJ_LIBS', 'Search path for PROJ.4 library files', '/usr/local/' + LIBDIR_SCHEMA)) |
|---|
| 54 | opts.Add(PathOption('GDAL_INCLUDES', 'Search path for GDAL include files', '/usr/include')) |
|---|
| 55 | opts.Add(PathOption('GDAL_LIBS', 'Search path for GDAL library files', '/usr/' + LIBDIR_SCHEMA)) |
|---|
| 56 | opts.Add(PathOption('PYTHON','Python executable', sys.executable)) |
|---|
| 57 | opts.Add(ListOption('INPUT_PLUGINS','Input drivers to include','all',['postgis','shape','raster','gdal'])) |
|---|
| 58 | opts.Add(ListOption('BINDINGS','Language bindings to build','all',['python'])) |
|---|
| 59 | opts.Add(BoolOption('DEBUG', 'Compile a debug version of mapnik', 'False')) |
|---|
| 60 | opts.Add('DESTDIR', 'The root directory to install into. Useful mainly for binary package building', '/') |
|---|
| 61 | opts.Add(BoolOption('BIDI', 'BIDI support', 'False')) |
|---|
| 62 | opts.Add(EnumOption('THREADING','Set threading support','multi', ['multi','single'])) |
|---|
| 63 | opts.Add(EnumOption('XMLPARSER','Set xml parser ','tinyxml', ['tinyxml','spirit','libxml2'])) |
|---|
| 64 | |
|---|
| 65 | env = Environment(ENV=os.environ, options=opts) |
|---|
| 66 | |
|---|
| 67 | def color_print(color,text): |
|---|
| 68 | # 1 - red |
|---|
| 69 | # 2 - green |
|---|
| 70 | # 3 - yellow |
|---|
| 71 | # 4 - blue |
|---|
| 72 | print "\033[9%sm%s\033[0m" % (color,text) |
|---|
| 73 | |
|---|
| 74 | env['LIBDIR_SCHEMA'] = LIBDIR_SCHEMA |
|---|
| 75 | env['PLATFORM'] = platform.uname()[0] |
|---|
| 76 | color_print (4,"Building on %s ..." % env['PLATFORM']) |
|---|
| 77 | Help(opts.GenerateHelpText(env)) |
|---|
| 78 | |
|---|
| 79 | thread_suffix = '-mt' |
|---|
| 80 | |
|---|
| 81 | if env['PLATFORM'] == 'FreeBSD': |
|---|
| 82 | thread_suffix = '' |
|---|
| 83 | env.Append(LIBS = 'pthread') |
|---|
| 84 | |
|---|
| 85 | conf = Configure(env) |
|---|
| 86 | |
|---|
| 87 | #### Libraries and headers dependency checks #### |
|---|
| 88 | |
|---|
| 89 | # Helper function for uniquely appending paths to a SCons path listing. |
|---|
| 90 | def uniq_add(env, key, val): |
|---|
| 91 | if not val in env[key]: env[key].append(val) |
|---|
| 92 | |
|---|
| 93 | # Libraries and headers dependency checks |
|---|
| 94 | env['CPPPATH'] = ['#agg/include', '#tinyxml', '#include', '#'] |
|---|
| 95 | env['LIBPATH'] = ['#agg', '#src'] |
|---|
| 96 | |
|---|
| 97 | # Solaris & Sun Studio settings (the `SUNCC` flag will only be |
|---|
| 98 | # set if the `CXX` option begins with `CC`) |
|---|
| 99 | SOLARIS = env['PLATFORM'] == 'SunOS' |
|---|
| 100 | SUNCC = SOLARIS and env['CXX'].startswith('CC') |
|---|
| 101 | |
|---|
| 102 | # For Solaris include paths (e.g., for freetype2, ltdl, etc.). |
|---|
| 103 | if SOLARIS: |
|---|
| 104 | blastwave_dir = '/opt/csw/%s' |
|---|
| 105 | uniq_add(env, 'CPPPATH', blastwave_dir % 'include') |
|---|
| 106 | uniq_add(env, 'LIBPATH', blastwave_dir % LIBDIR_SCHEMA) |
|---|
| 107 | |
|---|
| 108 | # If the Sun Studio C++ compiler (`CC`) is used instead of GCC. |
|---|
| 109 | if SUNCC: |
|---|
| 110 | env['CC'] = 'cc' |
|---|
| 111 | # To be compatible w/Boost everything needs to be compiled |
|---|
| 112 | # with the `-library=stlport4` flag (which needs to come |
|---|
| 113 | # before the `-o` flag). |
|---|
| 114 | env['CXX'] = 'CC -library=stlport4' |
|---|
| 115 | if env['THREADING'] == 'multi': |
|---|
| 116 | env['CXXFLAGS'] = ['-mt'] |
|---|
| 117 | |
|---|
| 118 | # Adding the prerequisite library directories to the include path for |
|---|
| 119 | # compiling and the library path for linking, respectively. |
|---|
| 120 | for prereq in ('BOOST', 'PNG', 'JPEG', 'TIFF', 'PGSQL', 'PROJ', 'GDAL',): |
|---|
| 121 | inc_path = env['%s_INCLUDES' % prereq] |
|---|
| 122 | lib_path = env['%s_LIBS' % prereq] |
|---|
| 123 | uniq_add(env, 'CPPPATH', inc_path) |
|---|
| 124 | uniq_add(env, 'LIBPATH', lib_path) |
|---|
| 125 | |
|---|
| 126 | env.ParseConfig(env['FREETYPE_CONFIG'] + ' --libs --cflags') |
|---|
| 127 | |
|---|
| 128 | if env['BIDI']: |
|---|
| 129 | env.Append(CXXFLAGS = '-DUSE_FRIBIDI') |
|---|
| 130 | if env['FRIBIDI_INCLUDES'] not in env['CPPPATH']: |
|---|
| 131 | env['CPPPATH'].append(env['FRIBIDI_INCLUDES']) |
|---|
| 132 | if env['FRIBIDI_LIBS'] not in env['LIBPATH']: |
|---|
| 133 | env['LIBPATH'].append(env['FRIBIDI_LIBS']) |
|---|
| 134 | env['LIBS'].append('fribidi') |
|---|
| 135 | |
|---|
| 136 | if env['XMLPARSER'] == 'tinyxml': |
|---|
| 137 | env.Append(CXXFLAGS = '-DBOOST_PROPERTY_TREE_XML_PARSER_TINYXML -DTIXML_USE_STL') |
|---|
| 138 | elif env['XMLPARSER'] == 'libxml2': |
|---|
| 139 | env.ParseConfig(env['XML2_CONFIG'] + ' --libs --cflags') |
|---|
| 140 | env.Append(CXXFLAGS = '-DHAVE_LIBXML2'); |
|---|
| 141 | |
|---|
| 142 | C_LIBSHEADERS = [ |
|---|
| 143 | ['m', 'math.h', True], |
|---|
| 144 | ['ltdl', 'ltdl.h', True], |
|---|
| 145 | ['png', 'png.h', True], |
|---|
| 146 | ['tiff', 'tiff.h', True], |
|---|
| 147 | ['z', 'zlib.h', True], |
|---|
| 148 | ['jpeg', ['stdio.h', 'jpeglib.h'], True], |
|---|
| 149 | ['proj', 'proj_api.h', True], |
|---|
| 150 | ['iconv', 'iconv.h', False], |
|---|
| 151 | ['pq', 'libpq-fe.h', False] |
|---|
| 152 | ] |
|---|
| 153 | |
|---|
| 154 | CXX_LIBSHEADERS = [ |
|---|
| 155 | ['gdal', 'gdal_priv.h',False] |
|---|
| 156 | ] |
|---|
| 157 | |
|---|
| 158 | if env['BIDI'] : C_LIBSHEADERS.append(['fribidi','fribidi/fribidi.h',True]) |
|---|
| 159 | |
|---|
| 160 | BOOST_LIBSHEADERS = [ |
|---|
| 161 | # ['system', 'boost/system/system_error.hpp', True], # uncomment this on Darwin + boost_1_35 |
|---|
| 162 | ['filesystem', 'boost/filesystem/operations.hpp', True], |
|---|
| 163 | ['regex', 'boost/regex.hpp', True], |
|---|
| 164 | ['iostreams','boost/iostreams/device/mapped_file.hpp',True], |
|---|
| 165 | ['program_options', 'boost/program_options.hpp', False] |
|---|
| 166 | ] |
|---|
| 167 | |
|---|
| 168 | if env['THREADING'] == 'multi': |
|---|
| 169 | BOOST_LIBSHEADERS.append(['thread', 'boost/thread/mutex.hpp', True]) |
|---|
| 170 | |
|---|
| 171 | for libinfo in C_LIBSHEADERS: |
|---|
| 172 | if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], 'C') and libinfo[2]: |
|---|
| 173 | color_print (1,'Could not find header or shared library for %s, exiting!' % libinfo[0]) |
|---|
| 174 | Exit(1) |
|---|
| 175 | |
|---|
| 176 | for libinfo in CXX_LIBSHEADERS: |
|---|
| 177 | if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], 'C++') and libinfo[2]: |
|---|
| 178 | color_print(1,'Could not find header or shared library for %s, exiting!' % libinfo[0]) |
|---|
| 179 | Exit(1) |
|---|
| 180 | |
|---|
| 181 | if len(env['BOOST_TOOLKIT']): |
|---|
| 182 | env['BOOST_APPEND'] = '-%s' % env['BOOST_TOOLKIT'] |
|---|
| 183 | else: |
|---|
| 184 | env['BOOST_APPEND']='' |
|---|
| 185 | |
|---|
| 186 | for count, libinfo in enumerate(BOOST_LIBSHEADERS): |
|---|
| 187 | if env['THREADING'] == 'multi' : |
|---|
| 188 | if not conf.CheckLibWithHeader('boost_%s%s%s' % (libinfo[0],env['BOOST_APPEND'],thread_suffix), libinfo[1], 'C++') and libinfo[2] : |
|---|
| 189 | color_print(1,'Could not find header or shared library for boost %s, exiting!' % libinfo[0]) |
|---|
| 190 | Exit(1) |
|---|
| 191 | elif not conf.CheckLibWithHeader('boost_%s%s' % (libinfo[0], env['BOOST_APPEND']), libinfo[1], 'C++') : |
|---|
| 192 | color_print(1,'Could not find header or shared library for boost %s, exiting!' % libinfo[0]) |
|---|
| 193 | Exit(1) |
|---|
| 194 | |
|---|
| 195 | Export('env') |
|---|
| 196 | |
|---|
| 197 | inputplugins = [ driver.strip() for driver in Split(env['INPUT_PLUGINS'])] |
|---|
| 198 | |
|---|
| 199 | bindings = [ binding.strip() for binding in Split(env['BINDINGS'])] |
|---|
| 200 | |
|---|
| 201 | #### Build instructions & settings #### |
|---|
| 202 | |
|---|
| 203 | # Build agg first, doesn't need anything special |
|---|
| 204 | SConscript('agg/SConscript') |
|---|
| 205 | |
|---|
| 206 | # Build the core library |
|---|
| 207 | SConscript('src/SConscript') |
|---|
| 208 | |
|---|
| 209 | # Build shapeindex and remove its dependency from the LIBS |
|---|
| 210 | if 'boost_program_options%s%s' % (env['BOOST_APPEND'],thread_suffix) in env['LIBS']: |
|---|
| 211 | SConscript('utils/shapeindex/SConscript') |
|---|
| 212 | env['LIBS'].remove('boost_program_options%s%s' % (env['BOOST_APPEND'],thread_suffix)) |
|---|
| 213 | |
|---|
| 214 | # Build the input plug-ins |
|---|
| 215 | if 'postgis' in inputplugins and 'pq' in env['LIBS']: |
|---|
| 216 | SConscript('plugins/input/postgis/SConscript') |
|---|
| 217 | env['LIBS'].remove('pq') |
|---|
| 218 | |
|---|
| 219 | if 'shape' in inputplugins: |
|---|
| 220 | SConscript('plugins/input/shape/SConscript') |
|---|
| 221 | |
|---|
| 222 | if 'raster' in inputplugins: |
|---|
| 223 | SConscript('plugins/input/raster/SConscript') |
|---|
| 224 | |
|---|
| 225 | if 'gdal' in inputplugins and 'gdal' in env['LIBS']: |
|---|
| 226 | SConscript('plugins/input/gdal/SConscript') |
|---|
| 227 | |
|---|
| 228 | if 'gigabase' in inputplugins and 'gigabase_r' in env['LIBS']: |
|---|
| 229 | SConscript('plugins/input/gigabase/SConscript') |
|---|
| 230 | |
|---|
| 231 | # Build the Python bindings. |
|---|
| 232 | if 'python' in env['BINDINGS']: |
|---|
| 233 | if not os.access(env['PYTHON'], os.X_OK): |
|---|
| 234 | color_print(1,"Cannot run python interpreter at '%s', make sure that you have the permissions to execute it." % env['PYTHON']) |
|---|
| 235 | Exit(1) |
|---|
| 236 | |
|---|
| 237 | env['PYTHON_PREFIX'] = os.popen("%s -c 'import sys; print sys.prefix'" % env['PYTHON']).read().strip() |
|---|
| 238 | env['PYTHON_VERSION'] = os.popen("%s -c 'import sys; print sys.version'" % env['PYTHON']).read()[0:3] |
|---|
| 239 | |
|---|
| 240 | color_print(4,'Bindings Python version... %s' % env['PYTHON_VERSION']) |
|---|
| 241 | |
|---|
| 242 | majver, minver = env['PYTHON_VERSION'].split('.') |
|---|
| 243 | |
|---|
| 244 | if (int(majver), int(minver)) < (2, 2): |
|---|
| 245 | color_print(1,"Python version 2.2 or greater required") |
|---|
| 246 | Exit(1) |
|---|
| 247 | |
|---|
| 248 | color_print(4,'Python %s prefix... %s' % (env['PYTHON_VERSION'], env['PYTHON_PREFIX'])) |
|---|
| 249 | |
|---|
| 250 | SConscript('bindings/python/SConscript') |
|---|
| 251 | |
|---|
| 252 | env = conf.Finish() |
|---|
| 253 | |
|---|
| 254 | # Common C++ flags. |
|---|
| 255 | if env['THREADING'] == 'multi' : |
|---|
| 256 | common_cxx_flags = '-D%s -DBOOST_SPIRIT_THREADSAFE -DMAPNIK_THREADSAFE ' % env['PLATFORM'].upper() |
|---|
| 257 | else : |
|---|
| 258 | common_cxx_flags = '-D%s ' % env['PLATFORM'].upper() |
|---|
| 259 | |
|---|
| 260 | # Mac OSX (Darwin) special settings |
|---|
| 261 | if env['PLATFORM'] == 'Darwin': |
|---|
| 262 | pthread = '' |
|---|
| 263 | # Getting the macintosh version number, sticking as a compiler macro |
|---|
| 264 | # for Leopard -- needed because different workarounds are needed than |
|---|
| 265 | # for Tiger. |
|---|
| 266 | if platform.mac_ver()[0].startswith('10.5'): |
|---|
| 267 | common_cxx_flags += '-DOSX_LEOPARD ' |
|---|
| 268 | else: |
|---|
| 269 | pthread = '-pthread' |
|---|
| 270 | |
|---|
| 271 | # Common debugging flags. |
|---|
| 272 | debug_flags = '-g -DDEBUG -DMAPNIK_DEBUG' |
|---|
| 273 | ndebug_flags = '-DNDEBUG' |
|---|
| 274 | |
|---|
| 275 | # Customizing the C++ compiler flags depending on: |
|---|
| 276 | # (1) the C++ compiler used; and |
|---|
| 277 | # (2) whether debug binaries are requested. |
|---|
| 278 | if SUNCC: |
|---|
| 279 | if env['DEBUG']: |
|---|
| 280 | env.Append(CXXFLAGS = common_cxx_flags + debug_flags) |
|---|
| 281 | else: |
|---|
| 282 | env.Append(CXXFLAGS = common_cxx_flags + '-O %s' % ndebug_flags) |
|---|
| 283 | else: |
|---|
| 284 | # Common flags for GCC. |
|---|
| 285 | gcc_cxx_flags = '-ansi -Wall %s -ftemplate-depth-100 %s' % (pthread, common_cxx_flags) |
|---|
| 286 | |
|---|
| 287 | if env['DEBUG']: |
|---|
| 288 | env.Append(CXXFLAGS = gcc_cxx_flags + '-O0 -fno-inline %s' % debug_flags) |
|---|
| 289 | else: |
|---|
| 290 | env.Append(CXXFLAGS = gcc_cxx_flags + '-O2 -finline-functions -Wno-inline %s' % ndebug_flags) |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | SConscript('fonts/SConscript') |
|---|