From 267b48de49d3c093a821c4c35efdcdcfe6ad1f28 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 18 Jul 2010 20:39:05 +0000 Subject: [PATCH] add ability to uninstall all tracked scons targets using an 'uninstall' argument like 'scons uninstall' - closes #311 --- SConstruct | 33 ++++++++++++++++++ bindings/python/SConscript | 13 ++++--- plugins/input/gdal/SConscript | 5 +-- plugins/input/kismet/SConscript | 5 +-- plugins/input/occi/SConscript | 5 +-- plugins/input/ogr/SConscript | 5 +-- plugins/input/osm/SConscript | 5 +-- plugins/input/postgis/SConscript | 5 +-- plugins/input/raster/SConscript | 5 +-- plugins/input/rasterlite/SConscript | 5 +-- plugins/input/shape/SConscript | 5 +-- plugins/input/shape/shape.cpp | 5 +++ plugins/input/sqlite/SConscript | 5 +-- src/SConscript | 54 +++++++++++++++++++++-------- utils/ogrindex/SConscript | 5 +-- utils/pgsql2sqlite/SConscript | 10 +++--- utils/upgrade_map_xml/SConscript | 7 ++-- 17 files changed, 130 insertions(+), 47 deletions(-) diff --git a/SConstruct b/SConstruct index c23c5300b..2e509a0b9 100644 --- a/SConstruct +++ b/SConstruct @@ -61,6 +61,24 @@ def call(cmd, silent=False): elif not silent: color_print(1,'Problem encounted with SCons scripts, please post bug report to: http://trac.mapnik.org\nError was: %s' % stderr) +# http://www.scons.org/wiki/InstallTargets +def create_uninstall_target(env, path, is_glob=False): + if is_glob: + all_files = Glob(path,strings=True) + for filei in all_files: + env.Command( "uninstall-"+filei, filei, + [ + Delete("$SOURCE"), + ]) + env.Alias("uninstall", "uninstall-"+filei) + else: + if os.path.exists(path): + env.Command( "uninstall-"+path, path, + [ + Delete("$SOURCE"), + ]) + env.Alias("uninstall", "uninstall-"+path) + def shortest_name(libs): name = '-'*200 for lib in libs: @@ -1155,8 +1173,16 @@ Help(opts.GenerateHelpText(env)) #### Builds #### if not HELP_REQUESTED: + + if 'uninstall' in COMMAND_LINE_TARGETS: + # dummy action in case there is nothing to uninstall, to avoid phony error.. + env.Alias("uninstall", "") + env['create_uninstall_target'] = create_uninstall_target + # export env so it is available in Sconscript files Export('env') + + # clear the '_CPPDEFFLAGS' variable # for unknown reasons this variable puts -DNone @@ -1205,6 +1231,13 @@ if not HELP_REQUESTED: # build internal shape and raster plugins SConscript('plugins/input/%s/SConscript' % plugin) + + # todo - generalize this path construction, also used in plugin SConscript... + plugin_dir = os.path.normpath(env['DESTDIR'] + '/' + env['PREFIX'] + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME']) + create_uninstall_target(env, plugin_dir + '/input' , False) + create_uninstall_target(env, plugin_dir + '/fonts' , False) + create_uninstall_target(env, plugin_dir, False) + # Build the c++ rundemo app if requested if env['DEMO']: SConscript('demo/c++/SConscript') diff --git a/bindings/python/SConscript b/bindings/python/SConscript index b441e60f4..9ff1bd6e1 100644 --- a/bindings/python/SConscript +++ b/bindings/python/SConscript @@ -26,7 +26,7 @@ import os Import('env') prefix = env['PREFIX'] -install_prefix = env['DESTDIR'] + '/' + prefix +target_path = env['PYTHON_INSTALL_LOCATION'] + '/mapnik2' linkflags = '' libraries = ['mapnik2','png','jpeg'] @@ -130,12 +130,12 @@ except: pass # install the core mapnik python files, including '__init__.py' and 'paths.py' init_files = glob.glob('mapnik/*.py') -init_module = env.Install(env['PYTHON_INSTALL_LOCATION'] + '/mapnik2', init_files) +init_module = env.Install(target_path, init_files) env.Alias(target='install', source=init_module) # install the ogcserver module code ogcserver_files = glob.glob('mapnik/ogcserver/*.py') -ogcserver_module = env.Install(env['PYTHON_INSTALL_LOCATION'] + '/mapnik2/ogcserver', ogcserver_files) +ogcserver_module = env.Install(target_path + '/ogcserver', ogcserver_files) env.Alias(target='install', source=ogcserver_module) @@ -177,5 +177,8 @@ if env['HAS_CAIRO'] or env['HAS_PYCAIRO']: _mapnik = py_env.LoadableModule('mapnik/_mapnik2', sources, LIBS=libraries, LDMODULEPREFIX='', LDMODULESUFFIX='.so',LINKFLAGS=linkflags) -pymapniklib = env.Install(env['PYTHON_INSTALL_LOCATION'] + '/mapnik2',_mapnik) -py_env.Alias(target='install',source=pymapniklib) +if 'uninstall' not in COMMAND_LINE_TARGETS: + pymapniklib = env.Install(target_path,_mapnik) + py_env.Alias(target='install',source=pymapniklib) + +env['create_uninstall_target'](env, target_path) \ No newline at end of file diff --git a/plugins/input/gdal/SConscript b/plugins/input/gdal/SConscript index 5438afb8c..cd2b3952a 100644 --- a/plugins/input/gdal/SConscript +++ b/plugins/input/gdal/SConscript @@ -38,5 +38,6 @@ if env['PLATFORM'] == 'Darwin': gdal_inputdriver = env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', gdal_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', gdal_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/kismet/SConscript b/plugins/input/kismet/SConscript index d4c210724..bed6af0f8 100644 --- a/plugins/input/kismet/SConscript +++ b/plugins/input/kismet/SConscript @@ -39,5 +39,6 @@ if env['PLATFORM'] == 'Darwin': kismet_inputdriver = env.SharedLibrary('../kismet', source=kismet_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', kismet_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', kismet_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/occi/SConscript b/plugins/input/occi/SConscript index 33b737f80..eaa2b7d14 100644 --- a/plugins/input/occi/SConscript +++ b/plugins/input/occi/SConscript @@ -41,5 +41,6 @@ if env['PLATFORM'] == 'Darwin': occi_inputdriver = env.SharedLibrary('../occi', source=occi_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', occi_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', occi_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/ogr/SConscript b/plugins/input/ogr/SConscript index b4a9a8622..9a4f9f00a 100644 --- a/plugins/input/ogr/SConscript +++ b/plugins/input/ogr/SConscript @@ -45,5 +45,6 @@ if env['PLATFORM'] == 'Darwin': ogr_inputdriver = env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', ogr_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', ogr_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/osm/SConscript b/plugins/input/osm/SConscript index 4652d4db1..328f2d414 100644 --- a/plugins/input/osm/SConscript +++ b/plugins/input/osm/SConscript @@ -43,5 +43,6 @@ if env['PLATFORM'] == 'Darwin': osm_inputdriver = env.SharedLibrary('../osm', source=osm_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', osm_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', osm_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/postgis/SConscript b/plugins/input/postgis/SConscript index 062e7ac4e..da83e2157 100644 --- a/plugins/input/postgis/SConscript +++ b/plugins/input/postgis/SConscript @@ -41,5 +41,6 @@ if env['PLATFORM'] == 'Darwin': postgis_inputdriver = env.SharedLibrary('../postgis', source=postgis_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', postgis_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', postgis_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/raster/SConscript b/plugins/input/raster/SConscript index cfceeb464..7c3e2a1ee 100644 --- a/plugins/input/raster/SConscript +++ b/plugins/input/raster/SConscript @@ -41,5 +41,6 @@ if env['PLATFORM'] == 'Darwin': raster_inputdriver = env.SharedLibrary('../raster', source=raster_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', raster_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', raster_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/rasterlite/SConscript b/plugins/input/rasterlite/SConscript index 6041a1fa7..950aa3f03 100644 --- a/plugins/input/rasterlite/SConscript +++ b/plugins/input/rasterlite/SConscript @@ -38,5 +38,6 @@ if env['PLATFORM'] == 'Darwin': rasterlite_inputdriver = env.SharedLibrary('../rasterlite', source=rasterlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', rasterlite_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', rasterlite_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/shape/SConscript b/plugins/input/shape/SConscript index 0c7d0e133..e7343ba5a 100644 --- a/plugins/input/shape/SConscript +++ b/plugins/input/shape/SConscript @@ -50,5 +50,6 @@ if env['SHAPE_MEMORY_MAPPED_FILE']: shape_inputdriver = env2.SharedLibrary('../shape', SHLIBSUFFIX='.input', source=shape_src, SHLIBPREFIX='', LIBS = libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', shape_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', shape_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/shape/shape.cpp b/plugins/input/shape/shape.cpp index 3a5e3fc13..2a606262e 100644 --- a/plugins/input/shape/shape.cpp +++ b/plugins/input/shape/shape.cpp @@ -69,6 +69,11 @@ shape_datasource::shape_datasource(const parameters ¶ms) throw datasource_exception("shapefile '" + shape_name_ + ".shp' does not exist"); } + if (boost::filesystem::is_directory(shape_name_ + ".shp")) + { + throw datasource_exception("shapefile '" + shape_name_ + ".shp' appears to be a directory not a file"); + } + try { shape_io shape(shape_name_); diff --git a/plugins/input/sqlite/SConscript b/plugins/input/sqlite/SConscript index 942de854f..c8aa2c974 100644 --- a/plugins/input/sqlite/SConscript +++ b/plugins/input/sqlite/SConscript @@ -40,5 +40,6 @@ if env['PLATFORM'] == 'Darwin': sqlite_inputdriver = env.SharedLibrary('../sqlite', source=sqlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) -env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', sqlite_inputdriver) -env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', sqlite_inputdriver) + env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/src/SConscript b/src/SConscript index abacbc979..f2aac7aeb 100644 --- a/src/SConscript +++ b/src/SConscript @@ -59,17 +59,24 @@ else: libraries.append([lib for lib in env['LIBS'] if lib.startswith('agg')]) +if env['PLATFORM'] == 'Darwin': + mapnik_libname = 'libmapnik2.dylib' +elif env['PLATFORM'] == 'SunOS' and env['CXX'].startswith('CC'): + mapnik_libname = 'libmapnik2.so' +else: + mapnik_libname = 'libmapnik2.so.' + ("%d.%d" % (ABI_VERSION[0],ABI_VERSION[1])) + if env['PLATFORM'] == 'Darwin': if env['FULL_LIB_PATH']: - lib_path = '%s/libmapnik2.dylib' % lib_dir + lib_path = '%s/%s' % (lib_dir,mapnik_libname) else: - lib_path = 'libmapnik2.dylib' + lib_path = mapnik_libname linkflags = '-Wl,-install_name,%s' % lib_path linkflags += ' -current_version 0.8.0 -compatibility_version 0.8.0' elif env['PLATFORM'] == 'SunOS' and env['CXX'].startswith('CC'): - linkflags = '-R. -h libmapnik.so' + linkflags = '-R. -h %s' % mapnik_libname else: # Linux and others - linkflags = '-Wl,-rpath-link,. -Wl,-soname,libmapnik2.so.' + ("%d.%d" % (ABI_VERSION[0],ABI_VERSION[1])) + linkflags = '-Wl,-rpath-link,. -Wl,-soname,%s' % mapnik_libname source = Split( """ @@ -179,6 +186,7 @@ elif env['XMLPARSER'] == 'libxml2' and env['HAS_LIBXML2']: source.insert(0,env2.SharedObject(cpp)) mapnik = env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags) + if env['PLATFORM'] != 'Darwin': # Symlink command, only works if both files are in same directory def symlink(env, target, source): @@ -193,17 +201,35 @@ if env['PLATFORM'] != 'Darwin': soFile = "%s.%d.%d.%d" % (os.path.basename(str(mapnik[0])), major, minor, micro) libDir = install_prefix + '/' + env['LIBDIR_SCHEMA'] - env.Alias(target='install', source=env.InstallAs(target=os.path.join(libDir, soFile), source=mapnik)) + target = os.path.join(libDir, soFile) + + if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Alias(target='install', source=env.InstallAs(target=target, source=mapnik)) + # Install symlinks - link1 = env.Command(os.path.join(libDir, "%s.%d.%d" % (os.path.basename(str(mapnik[0])),major, minor)), - os.path.join(libDir, soFile), symlink) - env.Alias(target='install', source=link1) - link2 = env.Command(os.path.join(libDir, os.path.basename(str(mapnik[0]))), - os.path.join(libDir, "%s.%d.%d" % (os.path.basename(str(mapnik[0])),major, minor)), symlink) - env.Alias(target='install', source=link2) + target1 = os.path.join(libDir, "%s.%d.%d" % (os.path.basename(str(mapnik[0])),major, minor)) + target2 = os.path.join(libDir, os.path.basename(str(mapnik[0]))) + if 'uninstall' not in COMMAND_LINE_TARGETS: + if 'install' in COMMAND_LINE_TARGETS: + link1 = env.Command(target1, target, symlink) + env.Alias(target='install', source=link1) + if 'install' in COMMAND_LINE_TARGETS: + link2 = env.Command(target2, target1, symlink) + env.Alias(target='install', source=link2) + # delete in reverse order.. + env['create_uninstall_target'](env, target2) + env['create_uninstall_target'](env, target1) + env['create_uninstall_target'](env, target) + else: - env.Alias(target='install', source=env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'], mapnik)) + target_path = os.path.normpath(install_prefix + '/' + env['LIBDIR_SCHEMA']) + if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Alias(target='install', source=env.Install(target_path, mapnik)) + env['create_uninstall_target'](env, os.path.join(target_path,mapnik_libname)) includes = glob.glob('../include/mapnik/*.hpp') - -env.Alias(target='install', source=env.Install(install_prefix+'/include/mapnik', includes)) + +inc_target = os.path.normpath(install_prefix+'/include/mapnik') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Alias(target='install', source=env.Install(inc_target, includes)) +env['create_uninstall_target'](env, inc_target) \ No newline at end of file diff --git a/utils/ogrindex/SConscript b/utils/ogrindex/SConscript index 4015c5ecc..425014e6c 100644 --- a/utils/ogrindex/SConscript +++ b/utils/ogrindex/SConscript @@ -50,5 +50,6 @@ if env['PLATFORM'] == 'Darwin': ogrindex = env.Program('ogrindex', source, CPPPATH=headers, LIBS=libraries) -env.Install(install_prefix + '/bin', ogrindex) -env.Alias('install', install_prefix + '/bin') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/bin', ogrindex) + env.Alias('install', install_prefix + '/bin') diff --git a/utils/pgsql2sqlite/SConscript b/utils/pgsql2sqlite/SConscript index 88e13c055..de0d30d49 100644 --- a/utils/pgsql2sqlite/SConscript +++ b/utils/pgsql2sqlite/SConscript @@ -40,8 +40,10 @@ libraries = [boost_program_options,boost_thread,'sqlite3','pq','mapnik2'] if env['PLATFORM'] == 'Darwin': libraries.append(env['ICU_LIB_NAME']) - -pgsql2sqlite = env.Program('pgsql2sqlite', source, CPPPATH=headers, LIBS=libraries) -env.Install(install_prefix + '/bin', pgsql2sqlite) -env.Alias('install', install_prefix + '/bin') +if 'uninstall' not in COMMAND_LINE_TARGETS: + pgsql2sqlite = env.Program('pgsql2sqlite', source, CPPPATH=headers, LIBS=libraries) + env.Install(install_prefix + '/bin', pgsql2sqlite) + env.Alias('install', install_prefix + '/bin') + +env['create_uninstall_target'](env, install_prefix + '/bin/' + 'pgsql2sqlite') diff --git a/utils/upgrade_map_xml/SConscript b/utils/upgrade_map_xml/SConscript index 97282ffd4..35202c574 100644 --- a/utils/upgrade_map_xml/SConscript +++ b/utils/upgrade_map_xml/SConscript @@ -24,5 +24,8 @@ Import ('env') prefix = env['PREFIX'] install_prefix = env['DESTDIR'] + '/' + prefix -env.Install(install_prefix + '/bin', "upgrade_map_xml.py") -env.Alias('install', install_prefix + '/bin') +if 'uninstall' not in COMMAND_LINE_TARGETS: + env.Install(install_prefix + '/bin', "upgrade_map_xml.py") + env.Alias('install', install_prefix + '/bin') + +env['create_uninstall_target'](env, install_prefix + '/bin/' + 'upgrade_map_xml.py')