11#! /usr/bin/env python
22
33import os
4+ import os .path
45import re
56import shutil
67import subprocess
78import sys
89from distutils import sysconfig
10+ from ctypes .util import find_library
911
10- from setuptools import Extension , setup
12+ from setuptools import Command , Extension , setup
1113
12- PYTHON3 = sys .version_info [ 0 ] == 3
14+ PYTHON3 = sys .version_info . major == 3
1315
1416
1517# Utils
@@ -21,6 +23,64 @@ def check_output(args):
2123 return output .rstrip ('\n ' )
2224
2325
26+ def clean_boost_name (name ):
27+ name = name .split ('.' )[0 ]
28+ if name .startswith ('lib' ):
29+ name = name [3 :]
30+ return name
31+
32+
33+ def find_boost_library (_id ):
34+ suffixes = [
35+ "" , # standard naming
36+ "-mt" # former naming schema for multithreading build
37+ ]
38+ if "python" in _id :
39+ # Debian naming convention for versions installed in parallel
40+ suffixes .insert (0 , "-py%d%d" % (sys .version_info .major ,
41+ sys .version_info .minor ))
42+ # standard suffix for Python3
43+ suffixes .insert (1 , sys .version_info .major )
44+ for suf in suffixes :
45+ name = "%s%s" % (_id , suf )
46+ lib = find_library (name )
47+ if lib is not None :
48+ return name
49+
50+
51+ def get_boost_library_names ():
52+ wanted = ['boost_python' , 'boost_system' , 'boost_thread' ]
53+ found = []
54+ missing = []
55+ for _id in wanted :
56+ name = os .environ .get ("%s_LIB" % _id .upper (), find_boost_library (_id ))
57+ if name :
58+ found .append (name )
59+ else :
60+ missing .append (_id )
61+ if missing :
62+ msg = ""
63+ for name in missing :
64+ msg += ("\n Missing {} boost library, try to add its name with "
65+ "{}_LIB environment var." ).format (name , name .upper ())
66+ raise EnvironmentError (msg )
67+ return found
68+
69+
70+ class WhichBoostCommand (Command ):
71+ description = 'Output found boost names. Useful for debug.'
72+ user_options = []
73+
74+ def initialize_options (self ):
75+ pass
76+
77+ def finalize_options (self ):
78+ pass
79+
80+ def run (self ):
81+ print ("\n " .join (get_boost_library_names ()))
82+
83+
2484cflags = sysconfig .get_config_var ('CFLAGS' )
2585sysconfig ._config_vars ['CFLAGS' ] = re .sub (
2686 ' +' , ' ' , cflags .replace ('-g' , '' ).replace ('-Os' , '' ).replace ('-arch i386' , '' ))
@@ -48,9 +108,6 @@ def check_output(args):
48108 mapnik_config = 'mapnik-config'
49109 mason_build = False
50110
51- boost_python_lib = os .environ .get ("BOOST_PYTHON_LIB" , 'boost_python-mt' )
52- boost_system_lib = os .environ .get ("BOOST_SYSTEM_LIB" , 'boost_system-mt' )
53- boost_thread_lib = os .environ .get ("BOOST_THREAD_LIB" , 'boost_thread-mt' )
54111
55112try :
56113 linkflags = check_output ([mapnik_config , '--libs' ]).split (' ' )
@@ -204,6 +261,9 @@ def check_output(args):
204261 'mapnik' : ['libmapnik.*' , 'plugins/*/*' ],
205262 },
206263 test_suite = 'nose.collector' ,
264+ cmdclass = {
265+ 'whichboost' : WhichBoostCommand ,
266+ },
207267 ext_modules = [
208268 Extension ('mapnik._mapnik' , [
209269 'src/mapnik_color.cpp' ,
@@ -247,10 +307,7 @@ def check_output(args):
247307 'mapnik' ,
248308 'mapnik-wkt' ,
249309 'mapnik-json' ,
250- boost_python_lib ,
251- boost_thread_lib ,
252- boost_system_lib
253- ],
310+ ] + get_boost_library_names (),
254311 extra_compile_args = extra_comp_args ,
255312 extra_link_args = linkflags ,
256313 )
0 commit comments