Skip to content

Commit e6e34ca

Browse files
author
Dane Springmeyer
committed
add scons build file
1 parent a3570a3 commit e6e34ca

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

build.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
if env['PLATFORM'] == 'Darwin':
42+
python_link_flag = '-undefined dynamic_lookup'
43+
44+
paths = '''
45+
"""Configuration paths of Mapnik fonts and input plugins (auto-generated by SCons)."""
46+
47+
from os.path import normpath,join,dirname
48+
49+
mapniklibpath = '%s'
50+
mapniklibpath = normpath(join(dirname(__file__),mapniklibpath))
51+
'''
52+
53+
paths += "inputpluginspath = join(mapniklibpath,'input')\n"
54+
55+
if env['SYSTEM_FONTS']:
56+
paths += "fontscollectionpath = normpath('%s')\n" % env['SYSTEM_FONTS']
57+
else:
58+
paths += "fontscollectionpath = join(mapniklibpath,'fonts')\n"
59+
60+
paths += "__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n"
61+
62+
if not os.path.exists(env['MAPNIK_NAME']):
63+
os.mkdir(env['MAPNIK_NAME'])
64+
65+
file('mapnik/paths.py','w').write(paths % (env['MAPNIK_LIB_DIR']))
66+
67+
# force open perms temporarily so that `sudo scons install`
68+
# does not later break simple non-install non-sudo rebuild
69+
try:
70+
os.chmod('mapnik/paths.py',0666)
71+
except: pass
72+
73+
# install the shared object beside the module directory
74+
sources = glob.glob('src/*.cpp')
75+
76+
if 'install' in COMMAND_LINE_TARGETS:
77+
# install the core mapnik python files, including '__init__.py'
78+
init_files = glob.glob('mapnik/*.py')
79+
if 'mapnik/paths.py' in init_files:
80+
init_files.remove('mapnik/paths.py')
81+
init_module = env.Install(target_path, init_files)
82+
env.Alias(target='install', source=init_module)
83+
# fix perms and install the custom generated 'paths.py'
84+
targetp = os.path.join(target_path,'paths.py')
85+
env.Alias("install", targetp)
86+
# use env.Command rather than env.Install
87+
# to enable setting proper perms on `paths.py`
88+
env.Command( targetp, 'mapnik/paths.py',
89+
[
90+
Copy("$TARGET","$SOURCE"),
91+
Chmod("$TARGET", 0644),
92+
])
93+
94+
if 'uninstall' not in COMMAND_LINE_TARGETS:
95+
if env['HAS_CAIRO']:
96+
py_env.Append(CPPPATH = env['CAIRO_CPPPATHS'])
97+
py_env.Append(CPPDEFINES = '-DHAVE_CAIRO')
98+
if link_all_libs:
99+
py_env.Append(LIBS=env['CAIRO_ALL_LIBS'])
100+
101+
if env['HAS_PYCAIRO']:
102+
py_env.Append(CPPDEFINES = '-DHAVE_PYCAIRO')
103+
py_env.Append(CPPPATH = env['PYCAIRO_PATHS'])
104+
105+
py_env.Append(LINKFLAGS=python_link_flag)
106+
py_env.AppendUnique(LIBS='mapnik-json')
107+
py_env.AppendUnique(LIBS='mapnik-wkt')
108+
109+
_mapnik = py_env.LoadableModule('mapnik/_mapnik', sources, LDMODULEPREFIX='', LDMODULESUFFIX='.so')
110+
111+
Depends(_mapnik, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
112+
Depends(_mapnik, env.subst('../../src/json/libmapnik-json${LIBSUFFIX}'))
113+
Depends(_mapnik, env.subst('../../src/wkt/libmapnik-wkt${LIBSUFFIX}'))
114+
115+
if 'uninstall' not in COMMAND_LINE_TARGETS:
116+
pymapniklib = env.Install(target_path,_mapnik)
117+
py_env.Alias(target='install',source=pymapniklib)
118+
119+
env['create_uninstall_target'](env, target_path)

0 commit comments

Comments
 (0)