diff --git a/SConstruct b/SConstruct index 89602d3c7..b658d40fb 100644 --- a/SConstruct +++ b/SConstruct @@ -291,6 +291,8 @@ opts.AddVariables( ('CC', 'The C compiler used for configure checks of C libs (defaults to gcc).', 'gcc'), ('CUSTOM_CXXFLAGS', 'Custom C++ flags, e.g. -I if you have headers in a nonstandard directory ', ''), ('CUSTOM_LDFLAGS', 'Custom linker flags, e.g. -L if you have libraries in a nonstandard directory ', ''), + EnumVariable('LINKING', "Set library format for libmapnik",'shared', ['shared','static']), + EnumVariable('RUNTIME_LINK', "Set preference for linking dependecies",'shared', ['shared','static']), EnumVariable('OPTIMIZATION','Set g++ optimization level','3', ['0','1','2','3','4','s']), # Note: setting DEBUG=True will override any custom OPTIMIZATION level BoolVariable('DEBUG', 'Compile a debug version of Mapnik', 'False'), @@ -393,6 +395,9 @@ pickle_store = [# Scons internal variables 'LINKFLAGS', 'CUSTOM_LDFLAGS', # user submitted 'CUSTOM_CXXFLAGS', # user submitted + 'MAPNIK_LIB_NAME', + 'LINK', + 'RUNTIME_LINK', # Mapnik's SConstruct build variables 'PLUGINS', 'ABI_VERSION', @@ -597,6 +602,7 @@ def get_pkg_lib(context, config, lib): return libname def parse_pg_config(context, config): + # TODO - leverage `LDFLAGS_SL` if RUNTIME_LINK==static env = context.env tool = config.lower() context.Message( 'Checking for %s... ' % tool) @@ -604,8 +610,8 @@ def parse_pg_config(context, config): if ret: lib_path = call('%s --libdir' % env[config]) inc_path = call('%s --includedir' % env[config]) - env.AppendUnique(CPPPATH = inc_path) - env.AppendUnique(LIBPATH = lib_path) + env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) + env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) lpq = env['PLUGINS']['postgis']['lib'] env.Append(LIBS = lpq) else: @@ -936,6 +942,11 @@ if not preconfigured: env['HAS_PYCAIRO'] = False env['HAS_LIBXML2'] = False env['SVN_REVISION'] = None + if env['LINKING'] == 'static': + env['MAPNIK_LIB_NAME'] = '${LIBPREFIX}mapnik2${LIBSUFFIX}' + else: + env['MAPNIK_LIB_NAME'] = '${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}' + env['LIBDIR_SCHEMA'] = LIBDIR_SCHEMA env['PLUGINS'] = PLUGINS @@ -984,8 +995,8 @@ if not preconfigured: for required in ('PNG', 'JPEG', 'TIFF','PROJ','ICU'): inc_path = env['%s_INCLUDES' % required] lib_path = env['%s_LIBS' % required] - env.AppendUnique(CPPPATH = inc_path) - env.AppendUnique(LIBPATH = lib_path) + env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) + env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) conf.parse_config('FREETYPE_CONFIG') @@ -1140,7 +1151,7 @@ if not preconfigured: # Note, the 'delete_existing' keyword makes sure that these paths are prepended # to the beginning of the path list even if they already exist incpath = env['%s_INCLUDES' % details['path']] - env.PrependUnique(CPPPATH = incpath,delete_existing=True) + env.PrependUnique(CPPPATH = os.path.realpath(incpath),delete_existing=True) env.PrependUnique(LIBPATH = env['%s_LIBS' % details['path']],delete_existing=True) if not conf.CheckLibWithHeader(details['lib'], details['inc'], details['lang']): env.Replace(**backup) @@ -1369,7 +1380,7 @@ if not preconfigured: # as they are later set in the python SConscript # ugly hack needed until we have env specific conf backup = env.Clone().Dictionary() - env.AppendUnique(CPPPATH = env['PYTHON_INCLUDES']) + env.AppendUnique(CPPPATH = os.path.realpath(env['PYTHON_INCLUDES'])) if not conf.CheckHeader(header='Python.h',language='C'): color_print(1,'Could not find required header files for the Python language (version %s)' % env['PYTHON_VERSION']) diff --git a/bindings/python/SConscript b/bindings/python/SConscript index 9e1865f11..08183f85d 100644 --- a/bindings/python/SConscript +++ b/bindings/python/SConscript @@ -197,7 +197,10 @@ if env['SVN_REVISION']: if env['HAS_CAIRO'] or env['HAS_PYCAIRO']: # attach libs to _mapnik.so linking environment - py_env.ParseConfig('pkg-config --libs cairomm-1.0') + cmd = 'pkg-config --libs cairomm-1.0' + if lib_env['RUNTIME_LINK'] == 'static': + cmd += ' --static' + py_env.ParseConfig(cmd) env2 = py_env.Clone() fixup = ['mapnik_image.cpp','python_cairo.cpp'] if not env['SVN_REVISION']: diff --git a/plugins/input/gdal/SConscript b/plugins/input/gdal/SConscript index c64f88c82..7f4113d48 100644 --- a/plugins/input/gdal/SConscript +++ b/plugins/input/gdal/SConscript @@ -33,16 +33,21 @@ gdal_src = Split( """ ) -libraries = [env['PLUGINS']['gdal']['lib']] +# clear out and rebuild libs +plugin_env['LIBS'] = [env['PLUGINS']['gdal']['lib']] # Link Library to Dependencies -libraries.append('mapnik2') -libraries.append(env['ICU_LIB_NAME']) +plugin_env['LIBS'].append('mapnik2') +plugin_env['LIBS'].append(env['ICU_LIB_NAME']) -input_plugin = plugin_env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) +if env['RUNTIME_LINK'] == 'static': + cmd = 'gdal-config --dep-libs' + plugin_env.ParseConfig(cmd) + +input_plugin = plugin_env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/geos/SConscript b/plugins/input/geos/SConscript index 4d509734a..0c261cbbd 100644 --- a/plugins/input/geos/SConscript +++ b/plugins/input/geos/SConscript @@ -45,7 +45,7 @@ libraries.append('boost_filesystem%s' % env['BOOST_APPEND']) input_plugin = plugin_env.SharedLibrary('../geos', source=geos_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/kismet/SConscript b/plugins/input/kismet/SConscript index 08198b54d..289a39618 100644 --- a/plugins/input/kismet/SConscript +++ b/plugins/input/kismet/SConscript @@ -42,7 +42,7 @@ libraries.append('boost_thread%s' % env['BOOST_APPEND']) input_plugin = plugin_env.SharedLibrary('../kismet', source=kismet_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/occi/SConscript b/plugins/input/occi/SConscript index d81437c57..29e096491 100644 --- a/plugins/input/occi/SConscript +++ b/plugins/input/occi/SConscript @@ -43,7 +43,7 @@ libraries.append(env['ICU_LIB_NAME']) input_plugin = plugin_env.SharedLibrary('../occi', source=occi_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/ogr/SConscript b/plugins/input/ogr/SConscript index d0eaa01ae..20e803a3c 100644 --- a/plugins/input/ogr/SConscript +++ b/plugins/input/ogr/SConscript @@ -36,18 +36,22 @@ ogr_src = Split( """ ) -libraries = [env['PLUGINS']['ogr']['lib']] +plugin_env['LIBS'] = [env['PLUGINS']['ogr']['lib']] # Link Library to Dependencies -libraries.append('mapnik2') -libraries.append(env['ICU_LIB_NAME']) -libraries.append('boost_system%s' % env['BOOST_APPEND']) -libraries.append('boost_filesystem%s' % env['BOOST_APPEND']) +plugin_env['LIBS'].append('mapnik2') +plugin_env['LIBS'].append(env['ICU_LIB_NAME']) +plugin_env['LIBS'].append('boost_system%s' % env['BOOST_APPEND']) +plugin_env['LIBS'].append('boost_filesystem%s' % env['BOOST_APPEND']) -input_plugin = plugin_env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) +if env['RUNTIME_LINK'] == 'static': + cmd = 'gdal-config --dep-libs' + plugin_env.ParseConfig(cmd) + +input_plugin = plugin_env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/osm/SConscript b/plugins/input/osm/SConscript index 26a9ecbd7..bbdcfb66f 100644 --- a/plugins/input/osm/SConscript +++ b/plugins/input/osm/SConscript @@ -45,7 +45,7 @@ libraries.append(env['ICU_LIB_NAME']) input_plugin = plugin_env.SharedLibrary('../osm', source=osm_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/postgis/SConscript b/plugins/input/postgis/SConscript index f92ff019d..18ae8e73f 100644 --- a/plugins/input/postgis/SConscript +++ b/plugins/input/postgis/SConscript @@ -44,7 +44,7 @@ if env['THREADING'] == 'multi': input_plugin = plugin_env.SharedLibrary('../postgis', source=postgis_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/raster/SConscript b/plugins/input/raster/SConscript index 84285d10f..211e5c6fc 100644 --- a/plugins/input/raster/SConscript +++ b/plugins/input/raster/SConscript @@ -44,7 +44,7 @@ libraries.append('boost_filesystem%s' % env['BOOST_APPEND']) input_plugin = plugin_env.SharedLibrary('../raster', source=raster_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/rasterlite/SConscript b/plugins/input/rasterlite/SConscript index 7cf3cf28f..5dfd4c49c 100644 --- a/plugins/input/rasterlite/SConscript +++ b/plugins/input/rasterlite/SConscript @@ -44,7 +44,7 @@ libraries.append('boost_filesystem%s' % env['BOOST_APPEND']) input_plugin = plugin_env.SharedLibrary('../rasterlite', source=rasterlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/shape/SConscript b/plugins/input/shape/SConscript index c1077c69d..821f48b35 100644 --- a/plugins/input/shape/SConscript +++ b/plugins/input/shape/SConscript @@ -51,7 +51,7 @@ if env['SHAPE_MEMORY_MAPPED_FILE']: input_plugin = plugin_env.SharedLibrary('../shape', SHLIBSUFFIX='.input', source=shape_src, SHLIBPREFIX='', LIBS = libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/plugins/input/sqlite/SConscript b/plugins/input/sqlite/SConscript index 938a1b1f0..b91af964d 100644 --- a/plugins/input/sqlite/SConscript +++ b/plugins/input/sqlite/SConscript @@ -44,7 +44,7 @@ libraries.append('boost_filesystem%s' % env['BOOST_APPEND']) input_plugin = plugin_env.SharedLibrary('../sqlite', source=sqlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) # if the plugin links to libmapnik2 ensure it is built first -Depends(input_plugin, env.subst('../../../src/${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}')) +Depends(input_plugin, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) if 'uninstall' not in COMMAND_LINE_TARGETS: env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', input_plugin) diff --git a/src/SConscript b/src/SConscript index 93f52ef0c..ceb38ef34 100644 --- a/src/SConscript +++ b/src/SConscript @@ -224,7 +224,10 @@ if env['SVG_RENDERER']: # svg backend if env['HAS_CAIRO']: # attach libs to library linking environment try: - lib_env.ParseConfig('pkg-config --libs cairomm-1.0') + cmd = 'pkg-config --libs cairomm-1.0' + if lib_env['RUNTIME_LINK'] == 'static': + cmd += ' --static' + lib_env.ParseConfig(cmd) env2 = lib_env.Clone() env2.Append(CXXFLAGS = '-DHAVE_CAIRO') # attach cflags to specific compile environment @@ -264,7 +267,13 @@ if env['CUSTOM_LDFLAGS']: else: linkflags = mapnik_lib_link_flag -mapnik = lib_env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags) +if env['LIBMAPNIK_LINKFLAGS']: + linkflags = '%s %s' % (env['LIBMAPNIK_LINKFLAGS'],linkflags) + +if env['LINKING'] == 'static': + mapnik = lib_env.StaticLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags) +else: + mapnik = lib_env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags) if env['PLATFORM'] != 'Darwin': # Symlink command, only works if both files are in same directory