Skip to content

Commit d4d41d9

Browse files
committed
Add Python version to library suffix.
1 parent 660487c commit d4d41d9

File tree

6 files changed

+165
-159
lines changed

6 files changed

+165
-159
lines changed

Jamfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) 2018 Stefan Seefeld
2+
# All rights reserved.
3+
#
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# (See accompanying file LICENSE_1_0.txt or copy at
6+
# http://www.boost.org/LICENSE_1_0.txt)
7+
8+
import option ;
9+
import regex ;
10+
import python ;
11+
12+
#
13+
# The `version-suffix` rule really belongs into python.jam, and
14+
# should be moved there. `split-version` is only duplicated here
15+
# as a prerequisite. (See https://github.com/boostorg/build/pull/290)
16+
#
17+
18+
19+
# Validate the version string and extract the major/minor part we care about.
20+
#
21+
local rule split-version ( version )
22+
{
23+
local major-minor = [ MATCH "^([0-9]+)\.([0-9]+)(.*)$" : $(version) : 1 2 3 ] ;
24+
if ! $(major-minor[2]) || $(major-minor[3])
25+
{
26+
ECHO "Warning: \"using python\" expects a two part (major, minor) version number; got" $(version) instead ;
27+
28+
# Add a zero to account for the missing digit if necessary.
29+
major-minor += 0 ;
30+
}
31+
32+
return $(major-minor[1]) $(major-minor[2]) ;
33+
}
34+
35+
# Define a version suffix for libraries depending on Python.
36+
# For example, Boost.Python built for Python 2.7 uses the suffix "27"
37+
rule version-suffix ( version )
38+
{
39+
local major-minor = [ split-version $(version) ] ;
40+
local suffix = $(major-minor:J="") ;
41+
return $(suffix) ;
42+
}
43+
44+
45+
# Python build id (for Python libraries only).
46+
python-id = [ option.get "python-buildid" ] ;
47+
if $(python-id)
48+
{
49+
PYTHON_ID = [ regex.replace $(python-id) [*\\/:.\"\'] _ ] ;
50+
}
51+
52+
rule python-tag ( name : type ? : property-set )
53+
{
54+
local result = $(name) ;
55+
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
56+
{
57+
local version = [ $(property-set).get <python> ] ;
58+
local lib-suffix = [ version-suffix $(version) ] ;
59+
result = $(result)$(lib-suffix) ;
60+
}
61+
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB && $(PYTHON_ID)
62+
{
63+
result = $(result)-$(PYTHON_ID) ;
64+
}
65+
66+
# forward to the boost tagging rule
67+
return [ tag $(result) : $(type) : $(property-set) ] ;
68+
}

build/Jamfile

Lines changed: 92 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import indirect ;
77
import modules ;
88
import feature ;
99
import property ;
10-
1110
import python ;
1211

1312
if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
@@ -31,9 +30,6 @@ else
3130
;
3231
}
3332

34-
py2-version = [ py-version 2 ] ;
35-
py3-version = [ py-version 3 ] ;
36-
3733
project boost/python
3834
: source-location ../src
3935
;
@@ -42,146 +38,95 @@ rule cond ( test ? : yes * : no * ) { if $(test) { return $(yes) ; } else { retu
4238
rule unless ( test ? : yes * : no * ) { if ! $(test) { return $(yes) ; } else { return $(no) ; } }
4339
local rule eq ( a : b ) { if $(a) = $(b) { return 1 ; } }
4440

45-
lib_boost_python(2) = boost_python ;
46-
lib_boost_python(3) = boost_python3 ;
47-
48-
lib_boost_python($(py2-version)) = $(lib_boost_python(2)) ;
49-
lib_boost_python($(py3-version)) = $(lib_boost_python(3)) ;
50-
51-
rule lib_boost_python ( version )
52-
{
53-
lib $(lib_boost_python($(version)))
54-
: # sources
55-
list.cpp
56-
long.cpp
57-
dict.cpp
58-
tuple.cpp
59-
str.cpp
60-
slice.cpp
61-
62-
converter/from_python.cpp
63-
converter/registry.cpp
64-
converter/type_id.cpp
65-
object/enum.cpp
66-
object/class.cpp
67-
object/function.cpp
68-
object/inheritance.cpp
69-
object/life_support.cpp
70-
object/pickle_support.cpp
71-
errors.cpp
72-
module.cpp
73-
converter/builtin_converters.cpp
74-
converter/arg_to_python_base.cpp
75-
object/iterator.cpp
76-
object/stl_iterator.cpp
77-
object_protocol.cpp
78-
object_operators.cpp
79-
wrapper.cpp
80-
import.cpp
81-
exec.cpp
82-
object/function_doc_signature.cpp
83-
: # requirements
84-
<link>static:<define>BOOST_PYTHON_STATIC_LIB
85-
<define>BOOST_PYTHON_SOURCE
86-
87-
# On Windows, all code using Python has to link to the Python
88-
# import library.
89-
#
90-
# On *nix we never link libboost_python to libpython. When
91-
# extending Python, all Python symbols are provided by the
92-
# Python interpreter executable. When embedding Python, the
93-
# client executable is expected to explicitly link to
94-
# /python//python (the target representing libpython) itself.
95-
#
96-
# python_for_extensions is a target defined by Boost.Build to
97-
# provide the Python include paths, and on Windows, the Python
98-
# import library, as usage requirements.
99-
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
100-
101-
# we prevent building when there is no python available
102-
# as it's not possible anyway, and to cause dependents to
103-
# fail to build
104-
[ unless [ python.configured ] : <build>no ]
105-
<dependency>config-warning
106-
107-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
108-
<python>$(version)
109-
110-
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
111-
<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).python-tag
112-
113-
<conditional>@python.require-py
114-
115-
: # default build
116-
<link>shared
117-
: # usage requirements
118-
<link>static:<define>BOOST_PYTHON_STATIC_LIB
119-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
120-
;
121-
}
122-
123-
lib_boost_numpy(2) = boost_numpy ;
124-
lib_boost_numpy(3) = boost_numpy3 ;
125-
126-
lib_boost_numpy($(py2-version)) = $(lib_boost_numpy(2)) ;
127-
lib_boost_numpy($(py3-version)) = $(lib_boost_numpy(3)) ;
128-
129-
rule lib_boost_numpy ( version )
130-
{
131-
numpy-include = [ python.numpy-include ] ;
132-
lib $(lib_boost_numpy($(version)))
133-
: # sources
134-
numpy/dtype.cpp
135-
numpy/matrix.cpp
136-
numpy/ndarray.cpp
137-
numpy/numpy.cpp
138-
numpy/scalars.cpp
139-
numpy/ufunc.cpp
140-
: # requirements
141-
<link>static:<define>BOOST_NUMPY_STATIC_LIB
142-
<define>BOOST_NUMPY_SOURCE
143-
[ cond [ python.numpy ] : <library>/python//python_for_extensions ]
144-
[ unless [ python.numpy ] : <build>no ]
145-
<include>$(numpy-include)
146-
<library>$(lib_boost_python($(version)))
147-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
148-
<python>$(version)
149-
150-
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
151-
<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).python-tag
152-
153-
<conditional>@python.require-py
154-
155-
: # default build
156-
<link>shared
157-
: # usage requirements
158-
<link>static:<define>BOOST_NUMPY_STATIC_LIB
159-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
160-
;
161-
}
162-
163-
libraries = ;
164-
165-
for local N in 2 3
166-
{
167-
if $(py$(N)-version)
168-
{
169-
lib_boost_python $(py$(N)-version) ;
170-
libraries += $(lib_boost_python($(py$(N)-version))) ;
171-
}
172-
else
173-
{
174-
alias $(lib_boost_python($(N))) ;
175-
}
176-
if $(py$(N)-version) && [ python.numpy ]
177-
{
178-
lib_boost_numpy $(py$(N)-version) ;
179-
libraries += $(lib_boost_numpy($(py$(N)-version))) ;
180-
}
181-
else
182-
{
183-
alias $(lib_boost_numpy($(N))) ;
184-
}
185-
}
186-
187-
boost-install $(libraries) ;
41+
lib boost_python
42+
: # sources
43+
list.cpp
44+
long.cpp
45+
dict.cpp
46+
tuple.cpp
47+
str.cpp
48+
slice.cpp
49+
50+
converter/from_python.cpp
51+
converter/registry.cpp
52+
converter/type_id.cpp
53+
object/enum.cpp
54+
object/class.cpp
55+
object/function.cpp
56+
object/inheritance.cpp
57+
object/life_support.cpp
58+
object/pickle_support.cpp
59+
errors.cpp
60+
module.cpp
61+
converter/builtin_converters.cpp
62+
converter/arg_to_python_base.cpp
63+
object/iterator.cpp
64+
object/stl_iterator.cpp
65+
object_protocol.cpp
66+
object_operators.cpp
67+
wrapper.cpp
68+
import.cpp
69+
exec.cpp
70+
object/function_doc_signature.cpp
71+
: # requirements
72+
<link>static:<define>BOOST_PYTHON_STATIC_LIB
73+
<define>BOOST_PYTHON_SOURCE
74+
75+
# On Windows, all code using Python has to link to the Python
76+
# import library.
77+
#
78+
# On *nix we never link libboost_python to libpython. When
79+
# extending Python, all Python symbols are provided by the
80+
# Python interpreter executable. When embedding Python, the
81+
# client executable is expected to explicitly link to
82+
# /python//python (the target representing libpython) itself.
83+
#
84+
# python_for_extensions is a target defined by Boost.Build to
85+
# provide the Python include paths, and on Windows, the Python
86+
# import library, as usage requirements.
87+
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
88+
89+
# we prevent building when there is no python available
90+
# as it's not possible anyway, and to cause dependents to
91+
# fail to build
92+
[ unless [ python.configured ] : <build>no ]
93+
<dependency>config-warning
94+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
95+
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
96+
<tag>@$(__name__).python-tag
97+
<conditional>@python.require-py
98+
99+
: # default build
100+
<link>shared
101+
: # usage requirements
102+
<link>static:<define>BOOST_PYTHON_STATIC_LIB
103+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
104+
;
105+
106+
numpy-include = [ python.numpy-include ] ;
107+
lib boost_numpy
108+
: # sources
109+
numpy/dtype.cpp
110+
numpy/matrix.cpp
111+
numpy/ndarray.cpp
112+
numpy/numpy.cpp
113+
numpy/scalars.cpp
114+
numpy/ufunc.cpp
115+
: # requirements
116+
<link>static:<define>BOOST_NUMPY_STATIC_LIB
117+
<define>BOOST_NUMPY_SOURCE
118+
[ cond [ python.numpy ] : <library>/python//python_for_extensions ]
119+
[ unless [ python.numpy ] : <build>no ]
120+
<include>$(numpy-include)
121+
<library>boost_python
122+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
123+
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
124+
<tag>@$(__name__).python-tag
125+
<conditional>@python.require-py
126+
127+
: # default build
128+
<link>shared
129+
: # usage requirements
130+
<link>static:<define>BOOST_NUMPY_STATIC_LIB
131+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
132+
;

fabscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ boost_include = options.get_with('boost-include')
2020
if boost_include:
2121
features += include(boost_include)
2222
python = python.instance()
23+
py_suffix = '{}{}'.format(*python.version.split('.')[:2])
2324
features |= set(python.include, python.linkpath, python.libs)
2425

2526
class has_numpy(try_run):

include/boost/python/detail/config.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@
105105
// Set the name of our library, this will get undef'ed by auto_link.hpp
106106
// once it's done with it:
107107
//
108-
#if PY_MAJOR_VERSION == 2
109-
# define BOOST_LIB_NAME boost_python
110-
#elif PY_MAJOR_VERSION == 3
111-
# define BOOST_LIB_NAME boost_python3
112-
#endif
108+
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
113109
//
114110
// If we're importing code from a dll, then tell auto_link.hpp about it:
115111
//

include/boost/python/numpy/config.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@
6262
// Set the name of our library, this will get undef'ed by auto_link.hpp
6363
// once it's done with it:
6464
//
65-
#if PY_MAJOR_VERSION == 2
66-
# define BOOST_LIB_NAME boost_numpy
67-
#elif PY_MAJOR_VERSION == 3
68-
# define BOOST_LIB_NAME boost_numpy3
69-
#endif
65+
#define BOOST_LIB_NAME boost_numpy##PY_MAJOR_VERSION##PY_MINOR_VERSION
7066
//
7167
// If we're importing code from a dll, then tell auto_link.hpp about it:
7268
//

src/fabscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from faber.tools.compiler import define
1313

1414
root = module('..')
1515

16-
bpl = library('boost_python',
16+
bpl = library('boost_python' + root.py_suffix,
1717
['list.cpp',
1818
'long.cpp',
1919
'dict.cpp',
@@ -44,7 +44,7 @@ bpl = library('boost_python',
4444
dependencies=root.config,
4545
features=features + define('BOOST_PYTHON_SOURCE'))
4646

47-
bnl = library('boost_numpy',
47+
bnl = library('boost_numpy' + root.py_suffix,
4848
['numpy/dtype.cpp',
4949
'numpy/matrix.cpp',
5050
'numpy/ndarray.cpp',

0 commit comments

Comments
 (0)