1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
if ! $(gPYTHON_INCLUDED)
{
gPYTHON_INCLUDED = true ;
# Do some OS-specific setup
if $(NT)
{
CATENATE = type ;
PYTHON_VERSION ?= 2.1 ;
}
else if $(UNIX)
{
CATENATE = cat ;
PYTHON_VERSION ?= 1.5 ;
}
# Strip the dot from the Python version in order to be able to name
# libraries
PYTHON_VERSION_NODOT
= [ SUBST $(PYTHON_VERSION) ([0-9]*)\.([0-9]*) $1$2 ]
;
local RUN_PATH = $(RUN_PATH) ;
if $(NT)
{
PYTHON_ROOT ?= c:/tools/python ;
PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/libs $(PYTHON_ROOT)/PCBuild ;
# Locate Python libraries. In the case of MSVC the libraries are
# found implicitly, and GCC/MINGW will use -lpython<version> to
# find it, but other compilers may need an explicit pointer on the
# command line.
PYTHON_LIB ?= <python-library@>python$(PYTHON_VERSION_NODOT).lib ;
SEARCH on $(PYTHON_LIB) = $(PYTHON_LIB_PATH) ;
PYTHON_D_LIB ?= <python-library@>python$(PYTHON_VERSION_NODOT)_d.lib ;
SEARCH on $(PYTHON_D_LIB) = $(PYTHON_LIB_PATH) ;
# common properties required for compiling any Python module.
PYTHON_PROPERTIES ?=
select-python-includes
<runtime-link>dynamic
<include>$(BOOST_ROOT)
<gcc><*><define>SIZEOF_LONG=4
<gcc><*><define>USE_DL_IMPORT
<gcc><*><find-library>python$(PYTHON_VERSION).dll
;
GCC_PYTHON_ROOT ?= $(CYGWIN_ROOT)/usr/local ;
GCC_PYTHON_ROOT ?= /usr/local ;
GCC_PYTHON_DEBUG_ROOT ?= $(CYGWIN_ROOT)/usr/local/pydebug ;
GCC_PYTHON_DEBUG_ROOT ?= /usr/local/pydebug ;
}
else if $(UNIX)
{
PYTHON_VERSION ?= 1.5 ;
PYTHON_ROOT ?= /usr/local ;
PYTHON_INCLUDES ?= $(PYTHON_ROOT)/include/python$(PYTHON_VERSION) ;
PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/lib/python$(PYTHON_VERSION)/config ;
PYTHON_PROPERTIES ?=
<include>$(PYTHON_INCLUDES)
<library-path>$(PYTHON_LIB_PATH)
<cxx><*><cflags>"-expect_unresolved 'Py*' -expect_unresolved '_Py*'"
;
}
# Locate the python executable
PYTHON ?= <executable@>python$(SUFEXE) ;
SEARCH on $(PYTHON) = $(PYTHON_ROOT) $(PYTHON_ROOT)/bin $(PYTHON_ROOT)/PCBuild $(RUN_PATH) ;
# And the debugging version
PYTHON_D ?= $(PYTHON:S=)_d$(PYTHON:S) ;
SEARCH on $(PYTHON_D) = $(PYTHON_ROOT) $(PYTHON_ROOT)/bin $(PYTHON_ROOT)/PCBuild $(RUN_PATH) ;
# select-python-library
#
# Ungristed elements of a requirements list are treated as the rule
# names to be called to transform the property set. This is used when
# the requirements are too complicated to express otherwise. This
# rule selects the right python library when building on Windows.
rule select-python-library ( toolset variant : properties * )
{
if $(NT)
{
if $(toolset) = mingw
{
local lib = python$(PYTHON_VERSION_NODOT) ;
if <define>BOOST_DEBUG_PYTHON in $(properties)
{
lib = python$(PYTHON_VERSION_NODOT)_d ;
}
properties += <find-library>$(lib) ;
}
else if $(toolset) = gcc
{
local python-root = $(GCC_PYTHON_ROOT) ;
if <define>BOOST_DEBUG_PYTHON in $(properties)
{
python-root = $(GCC_PYTHON_DEBUG_ROOT) ;
}
properties += <library-path>$(python-root)/lib/python$(PYTHON_VERSION)/config ;
}
else if ! ( $(toolset) = msvc )
{
local lib = $(PYTHON_LIB) ;
if <define>BOOST_DEBUG_PYTHON in $(properties)
{
lib = $(PYTHON_D_LIB) ;
}
properties += <library-file>$(lib) ;
}
}
return $(properties) ;
}
rule select-python-includes ( toolset variant : properties * )
{
if $(toolset) = gcc
{
local python-root = $(GCC_PYTHON_ROOT) ;
if <define>BOOST_DEBUG_PYTHON in $(properties)
{
python-root = $(GCC_PYTHON_DEBUG_ROOT) ;
}
properties += <include>$(python-root)/include/python$(PYTHON_VERSION) ;
}
else
{
properties +=
<include>$(PYTHON_ROOT)/include
<include>$(PYTHON_ROOT)/PC # in case the user is using a source installation
<debug-python><define>_DEBUG
;
}
return $(properties) ;
}
PYTHON_PROPERTIES
+=
<gcc><*><find-library>util
<include>$(BOOST_ROOT)
select-python-library
# These two compilers pick up implicit directions from #pragmas
# to look for those libraries.
<mingw><*><library-path>$(PYTHON_LIB_PATH)
<msvc><*><library-path>$(PYTHON_LIB_PATH)
<intel-win32><*><library-path>$(PYTHON_LIB_PATH)
;
# Extends the RUN_PATH assignment for targets built under Cygwin so
# that the Python DLL can be found.
rule add-cygwin-python-run-path ( module )
{
local d = $(GCC_ROOT_DIRECTORY) ;
while $(d:D) != $(d)
{
local python-root = $(GCC_PYTHON_ROOT) ;
if <define>BOOST_DEBUG_PYTHON in $(gBUILD_PROPERTIES)
{
python-root = $(GCC_PYTHON_DEBUG_ROOT) ;
}
gRUN_PATH($(module)) += $(python-root)/lib/python$(PYTHON_VERSION)/config ;
d = $(d:D) ;
}
}
# This is the generator function for Python modules. It deals with the
# need to change the name of modules compiled with debugging on. This
# is just a wrapper around the generator for shared libraries,
# dll-files.
rule python-files ( module implib ? : sources * )
{
dll-files $(module) $(implib) : $(sources) : PYD ;
if ( $(gCURRENT_TOOLSET) = gcc )
{
if $(NT)
{
add-cygwin-python-run-path $(<[-1]) ;
}
else
{
gRUN_PATH($(module)) += $(GCC_ROOT_DIRECTORY)/lib ;
}
}
}
if $(NT)
{
# Adjust the name of Python modules so that they have the _d
# suffix when compiled with python debugging enabled.
gNAME_ADJUST(PYD) = name-adjust-PYD ;
rule name-adjust-PYD ( pyd implib ? : properties * : toolset variant )
{
# Cygwin python is only happy if compiled modules have a .dll
# extension
if $(toolset) = gcc
{
pyd = $(pyd:S=.dll) ;
}
else if <define>BOOST_DEBUG_PYTHON in $(properties)
{
pyd = $(pyd:S=)_d$(pyd:S) ;
}
return $(pyd) $(implib) ;
}
}
rule Link-PYD
{
if $(<[2])
{
MODE on $(<[2]) = $(IMPMODE) ;
Chmod $(<[2]) ;
}
gRUN_PATH($(<)) += $(gLOCATE($(<[1]))) ;
if $(UNIX)
{
gRUN_LD_LIBRARY_PATH($(<)) += $(gLOCATE($(<[1]))) ;
}
Link-action $(<) : $(>) : PYD ;
}
declare-target-type PYD : <shared-linkable>true ;
gGENERATOR_FUNCTION(PYD) = python-files ;
if $(NT)
{
SUFPYD = .pyd $(SUFDLL[2-]) ;
}
else
{
SUFPYD = $(SUFDLL) ;
}
PYDMODE = $(DLLMODE) ;
SHARED_TYPES += PYD ;
# Declare a python extension.
rule extension ( name : sources + : requirements * : default-BUILD * )
{
requirements += $(PYTHON_PROPERTIES) ;
declare-local-target $(name) : $(sources) : $(requirements) : $(default-BUILD) : PYD ;
}
# boost-python-runtest target : python-script sources : requirements : local-build : args
#
# declare two python module tests: $(<).test which builds when out-of-date, and
# $(<).run which builds unconditionally.
rule boost-python-runtest (
target : python-script sources + : requirements * : local-build * : args * )
{
# tell Jam that the python script is relative to this directory
SEARCH on $(python-script) = $(SEARCH_SOURCE) ;
# The user can add additional arguments in PYTHON_TEST_ARGS.
local gPYTHON_TEST_ARGS = $(args) $(PYTHON_TEST_ARGS) ;
# declare the two subsidiary tests.
declare-local-target $(<:S=.test) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_TEST ;
declare-local-target $(<:S=.run) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_RUNTEST ;
}
rule boost-python-test ( name : sources + : requirements * : default-BUILD * )
{
type-DEPENDS test : $(name) ;
local gSUPPRESS_FAKE_TARGETS = true ;
extension $(name) : $(sources) : $(requirements) : $(4) ;
}
# special rules for two new target types: PYTHON_TEST and PYTHON_RUNTEST.
# These are identical except that PYTHON_TEST runs the test when out-of-date, and
# PYTHON_RUNTEST runs the test unconditionally. These are used by boost-python-runtest.
SUFPYTHON_TEST = .test ;
gGENERATOR_FUNCTION(PYTHON_TEST) = python-test-target ;
rule python-test-target ( test-target : sources + )
{
python-runtest-aux $(test-target) : $(sources) ;
Clean clean : $(test-target) ; # remove the test-target as part of any clean operation
type-DEPENDS test : $(test-target) ;
MakeLocate $(test-target) : $(LOCATE_TARGET) ;
MakeLocate $(test-target) : $(LOCATE_TARGET) ;
}
actions python-test-target bind PYTHON
{
$(SHELL_SET)PATH=$(PATH)
$(SHELL_EXPORT)PATH
$(SHELL_SET)LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)
$(SHELL_EXPORT)LD_LIBRARY_PATH
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
$(PYTHON_LAUNCH) $(PYTHON) $(PYTHON_ARGS) "$(>)" $(ARGS) 2>&1 "$(<)" || $(CATENATE) "$(<)"
}
SUFPYTHON_RUNTEST = .run ;
gGENERATOR_FUNCTION(PYTHON_RUNTEST) = python-runtest-target ;
rule python-runtest-target ( test-target : sources + )
{
type-DEPENDS runtest : $(test-target) ;
python-runtest-aux $(test-target) : $(sources) ;
NOTFILE $(test-target) ;
ALWAYS $(test-target) ;
}
actions python-runtest-target bind PYTHON
{
$(SHELL_SET)PATH=$(PATH)
$(SHELL_EXPORT)PATH
$(SHELL_SET)LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)
$(SHELL_EXPORT)LD_LIBRARY_PATH
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
$(PYTHON_LAUNCH) $(PYTHON) $(PYTHON_ARGS) "$(>)" $(ARGS)
}
# This is the rule that actually causes the test to run. It is used by
# bothe python-test-target and python-runtest-target.
rule python-runtest-aux ( target : sources + )
{
DEPENDS $(target) : $(>) ;
ARGS on $(target) += $(gPYTHON_TEST_ARGS) ;
# Some tests need an extra command-line arg if built with
# msvc. Checking the target grist is a cheap way to
# find out.
switch $(target)
{
case <*\\\\msvc\\\\*>* : ARGS on $(target) += --broken-auto-ptr ;
case <*\\\\intel-win32\\\\*>* : ARGS on $(target) += --broken-auto-ptr ;
}
# choose the right python executable
local python = $(PYTHON) ;
local splitpath = $(SPLITPATH) ;
# compute the PYTHONPATH environment variable that will allow the test to
# find all of the modules on which it depends.
local pythonpath =
$(gLOCATE($(>[1]))) # location of python test file
$(gRUN_PATH($(target))) # location of module dependencies
[ join-path $(TOP) libs python test ] # location of doctest
$(>:D) # directory of python driver file(s)
$(PYTHONPATH) # base PYTHONPATH from environment
;
if $(NT) && ( $(gCURRENT_TOOLSET) = gcc )
{
python = python$(PYTHON_VERSION)$(SUFEXE) ;
local python-root = $(GCC_PYTHON_ROOT) ;
if <define>BOOST_DEBUG_PYTHON in $(gBUILD_PROPERTIES)
{
python-root = $(GCC_PYTHON_DEBUG_ROOT) ;
}
SEARCH on $(python) = [ join-path [ split-path $(python-root)/bin ] ] $(RUN_PATH) ;
splitpath = ":" ;
local pp ;
for local p in $(pythonpath)
{
# if already rooted...
if $(p:R=xx) = $(p)
{
p = [ split-path $(p) ] ;
p = [ join-path /cygdrive [ SUBST $(p[1]) ^(.).* $1 ] $(p[2-]) ] ;
}
pp += $(p) ;
}
pythonpath = $(pp:T) ;
}
else if <define>BOOST_DEBUG_PYTHON in $(gBUILD_PROPERTIES) && $(NT)
{
python = $(PYTHON_D) ;
}
PYTHONPATH on $(target) = [ join $(pythonpath) : $(splitpath) ] ;
# set the path so that DLLs linked into extension modules will be
# found
PATH on $(target) = [ join
$(gRUN_PATH($(target))) # location of module dependencies
$(>:D) # directory of python driver file(s)
$(PATH) # base PATH from environment
: $(SPLITPATH) ] ; # platform path separator
LD_LIBRARY_PATH on $(target) = [ join
$(gRUN_LD_LIBRARY_PATH($(target))) # location of module dependencies
: $(SPLITPATH) ] ; # platform path separator
PYTHON on $(target) = $(python) ;
DEPENDS $(target) : $(python) ;
}
}
|