|
| 1 | +import glob |
| 2 | +import os |
| 3 | +from subprocess import Popen, PIPE |
| 4 | +from distutils import sysconfig |
| 5 | + |
| 6 | +Import('env') |
| 7 | + |
| 8 | +def call(cmd, silent=True): |
| 9 | + stdin, stderr = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate() |
| 10 | + if not stderr: |
| 11 | + return stdin.strip() |
| 12 | + elif not silent: |
| 13 | + print stderr |
| 14 | + |
| 15 | + |
| 16 | +prefix = env['PREFIX'] |
| 17 | +target_path = os.path.normpath(sysconfig.get_python_lib() + os.path.sep + env['MAPNIK_NAME']) |
| 18 | + |
| 19 | +py_env = env.Clone() |
| 20 | + |
| 21 | +py_env.Append(CPPPATH = sysconfig.get_python_inc()) |
| 22 | + |
| 23 | +py_env.Append(CPPDEFINES = env['LIBMAPNIK_DEFINES']) |
| 24 | + |
| 25 | +py_env['LIBS'] = [env['MAPNIK_NAME'],'libboost_python'] |
| 26 | + |
| 27 | +link_all_libs = env['LINKING'] == 'static' or env['RUNTIME_LINK'] == 'static' |
| 28 | + |
| 29 | +# even though boost_thread is no longer used in mapnik core |
| 30 | +# we need to link in for boost_python to avoid missing symbol: _ZN5boost6detail12get_tss_dataEPKv / boost::detail::get_tss_data |
| 31 | +py_env.AppendUnique(LIBS = 'boost_thread%s' % env['BOOST_APPEND']) |
| 32 | + |
| 33 | +if link_all_libs: |
| 34 | + py_env.AppendUnique(LIBS=env['LIBMAPNIK_LIBS']) |
| 35 | + |
| 36 | +# note: on linux -lrt must be linked after thread to avoid: undefined symbol: clock_gettime |
| 37 | +if env['RUNTIME_LINK'] == 'static' and env['PLATFORM'] == 'Linux': |
| 38 | + py_env.AppendUnique(LIBS='rt') |
| 39 | + |
| 40 | +# TODO - do solaris/fedora need direct linking too? |
| 41 | +python_link_flag = '' |
| 42 | +if env['PLATFORM'] == 'Darwin': |
| 43 | + python_link_flag = '-undefined dynamic_lookup' |
| 44 | + |
| 45 | +paths = ''' |
| 46 | +"""Configuration paths of Mapnik fonts and input plugins (auto-generated by SCons).""" |
| 47 | +
|
| 48 | +from os.path import normpath,join,dirname |
| 49 | +
|
| 50 | +mapniklibpath = '%s' |
| 51 | +mapniklibpath = normpath(join(dirname(__file__),mapniklibpath)) |
| 52 | +''' |
| 53 | + |
| 54 | +paths += "inputpluginspath = join(mapniklibpath,'input')\n" |
| 55 | + |
| 56 | +if env['SYSTEM_FONTS']: |
| 57 | + paths += "fontscollectionpath = normpath('%s')\n" % env['SYSTEM_FONTS'] |
| 58 | +else: |
| 59 | + paths += "fontscollectionpath = join(mapniklibpath,'fonts')\n" |
| 60 | + |
| 61 | +paths += "__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n" |
| 62 | + |
| 63 | +if not os.path.exists(env['MAPNIK_NAME']): |
| 64 | + os.mkdir(env['MAPNIK_NAME']) |
| 65 | + |
| 66 | +file('mapnik/paths.py','w').write(paths % (env['MAPNIK_LIB_DIR'])) |
| 67 | + |
| 68 | +# force open perms temporarily so that `sudo scons install` |
| 69 | +# does not later break simple non-install non-sudo rebuild |
| 70 | +try: |
| 71 | + os.chmod('mapnik/paths.py',0666) |
| 72 | +except: pass |
| 73 | + |
| 74 | +# install the shared object beside the module directory |
| 75 | +sources = glob.glob('src/*.cpp') |
| 76 | + |
| 77 | +if 'install' in COMMAND_LINE_TARGETS: |
| 78 | + # install the core mapnik python files, including '__init__.py' |
| 79 | + init_files = glob.glob('mapnik/*.py') |
| 80 | + if 'mapnik/paths.py' in init_files: |
| 81 | + init_files.remove('mapnik/paths.py') |
| 82 | + init_module = env.Install(target_path, init_files) |
| 83 | + env.Alias(target='install', source=init_module) |
| 84 | + # fix perms and install the custom generated 'paths.py' |
| 85 | + targetp = os.path.join(target_path,'paths.py') |
| 86 | + env.Alias("install", targetp) |
| 87 | + # use env.Command rather than env.Install |
| 88 | + # to enable setting proper perms on `paths.py` |
| 89 | + env.Command( targetp, 'mapnik/paths.py', |
| 90 | + [ |
| 91 | + Copy("$TARGET","$SOURCE"), |
| 92 | + Chmod("$TARGET", 0644), |
| 93 | + ]) |
| 94 | + |
| 95 | +if 'uninstall' not in COMMAND_LINE_TARGETS: |
| 96 | + if env['HAS_CAIRO']: |
| 97 | + py_env.Append(CPPPATH = env['CAIRO_CPPPATHS']) |
| 98 | + py_env.Append(CPPDEFINES = '-DHAVE_CAIRO') |
| 99 | + if link_all_libs: |
| 100 | + py_env.Append(LIBS=env['CAIRO_ALL_LIBS']) |
| 101 | + |
| 102 | + if env['HAS_PYCAIRO']: |
| 103 | + py_env.Append(CPPDEFINES = '-DHAVE_PYCAIRO') |
| 104 | + py_env.Append(CPPPATH = env['PYCAIRO_PATHS']) |
| 105 | + |
| 106 | +py_env.Append(LINKFLAGS=python_link_flag) |
| 107 | +py_env.AppendUnique(LIBS='mapnik-json') |
| 108 | +py_env.AppendUnique(LIBS='mapnik-wkt') |
| 109 | + |
| 110 | +_mapnik = py_env.LoadableModule('mapnik/_mapnik', sources, LDMODULEPREFIX='', LDMODULESUFFIX='.so') |
| 111 | + |
| 112 | +Depends(_mapnik, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME'])) |
| 113 | +Depends(_mapnik, env.subst('../../src/json/libmapnik-json${LIBSUFFIX}')) |
| 114 | +Depends(_mapnik, env.subst('../../src/wkt/libmapnik-wkt${LIBSUFFIX}')) |
| 115 | + |
| 116 | +if 'uninstall' not in COMMAND_LINE_TARGETS: |
| 117 | + pymapniklib = env.Install(target_path,_mapnik) |
| 118 | + py_env.Alias(target='install',source=pymapniklib) |
| 119 | + |
| 120 | +env['create_uninstall_target'](env, target_path) |
0 commit comments