root/tags/release-0.5.1/SConstruct

Revision 682, 11.7 kB (checked in by dom, 10 months ago)

merge [679] (ppc64 build fix)

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