[12] | 1 | if ! $(gPYTHON_INCLUDED) |
---|
| 2 | { |
---|
| 3 | gPYTHON_INCLUDED = true ; |
---|
| 4 | |
---|
| 5 | import testing ; |
---|
| 6 | |
---|
| 7 | # Do some OS-specific setup |
---|
| 8 | if $(NT) |
---|
| 9 | { |
---|
| 10 | CATENATE = type ; |
---|
| 11 | } |
---|
| 12 | else if $(UNIX) |
---|
| 13 | { |
---|
| 14 | CATENATE = cat ; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | PYTHON_VERSION ?= 2.4 ; |
---|
| 18 | |
---|
| 19 | # Strip the dot from the Python version in order to be able to name |
---|
| 20 | # libraries |
---|
| 21 | PYTHON_VERSION_NODOT |
---|
| 22 | = [ MATCH ([0-9]*)\.([0-9]*) : $(PYTHON_VERSION) ] |
---|
| 23 | ; |
---|
| 24 | PYTHON_VERSION_NODOT = $(PYTHON_VERSION_NODOT:J=) ; |
---|
| 25 | |
---|
| 26 | local RUN_PATH = $(RUN_PATH) ; |
---|
| 27 | |
---|
| 28 | if $(NT) || ( $(UNIX) && $(OS) = CYGWIN ) |
---|
| 29 | { |
---|
| 30 | PYTHON_WINDOWS = true ; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | if $(PYTHON_WINDOWS) |
---|
| 34 | { |
---|
| 35 | # common properties required for compiling any Python module. |
---|
| 36 | PYTHON_PROPERTIES = |
---|
| 37 | boost-python-disable-borland |
---|
| 38 | select-nt-python-includes |
---|
| 39 | <runtime-link>dynamic |
---|
| 40 | <sysinclude>@boost |
---|
| 41 | <$(gcc-compilers)><*><define>USE_DL_IMPORT |
---|
| 42 | ; |
---|
| 43 | |
---|
| 44 | CYGWIN_PYTHON_ROOT ?= /usr ; |
---|
| 45 | if ! $(NT) |
---|
| 46 | { |
---|
| 47 | PYTHON_ROOT ?= $(CYGWIN_PYTHON_ROOT) ; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if $(CYGWIN_PYTHON_ROOT) = /usr |
---|
| 51 | { |
---|
| 52 | CYGWIN_PYTHON_DLL_PATH ?= /bin ; |
---|
| 53 | } |
---|
| 54 | else |
---|
| 55 | { |
---|
| 56 | CYGWIN_PYTHON_DLL_PATH ?= $(CYGWIN_PYTHON_ROOT)/bin ; |
---|
| 57 | } |
---|
| 58 | CYGWIN_PYTHON_VERSION ?= $(PYTHON_VERSION) ; |
---|
| 59 | CYGWIN_PYTHON_LIB_PATH ?= $(CYGWIN_PYTHON_ROOT)/lib/python$(CYGWIN_PYTHON_VERSION)/config ; |
---|
| 60 | |
---|
| 61 | CYGWIN_PYTHON_DEBUG_VERSION ?= $(CYGWIN_PYTHON_VERSION) ; |
---|
| 62 | CYGWIN_PYTHON_DEBUG_ROOT ?= $(PYTHON_ROOT) ; |
---|
| 63 | CYGWIN_PYTHON_DEBUG_DLL_PATH ?= $(CYGWIN_PYTHON_DEBUG_ROOT)/bin ; |
---|
| 64 | CYGWIN_PYTHON_DEBUG_LIB_PATH ?= $(CYGWIN_PYTHON_DEBUG_ROOT)/lib/python$(CYGWIN_PYTHON_DEBUG_VERSION)/config ; |
---|
| 65 | } |
---|
| 66 | else if $(UNIX) |
---|
| 67 | { |
---|
| 68 | # PYTHON_EMBEDDED_LIBRARY: Libraries to include when |
---|
| 69 | # embedding Python in C++ code. We need the Python library, |
---|
| 70 | # libdl for dynamic loading and possibly libutil on BSD-like |
---|
| 71 | # systems (including Linux). A dynamic libpython should |
---|
| 72 | # automatically pick up the libutil dependency, but we cannot |
---|
| 73 | # tell here if we are linking with a static or dynamic |
---|
| 74 | # libpython, so we include libutil for all UNIX systems where |
---|
| 75 | # it is available. |
---|
| 76 | |
---|
| 77 | if $(OS) = MACOSX |
---|
| 78 | { |
---|
| 79 | PYTHON_EMBEDDED_LIBRARY = ; |
---|
| 80 | } |
---|
| 81 | else if $(OS) = SOLARIS |
---|
| 82 | { |
---|
| 83 | PYTHON_EMBEDDED_LIBRARY = python$(PYTHON_VERSION) dl ; |
---|
| 84 | } |
---|
| 85 | else if $(OS) = OSF |
---|
| 86 | { |
---|
| 87 | PYTHON_EMBEDDED_LIBRARY = python$(PYTHON_VERSION) ; |
---|
| 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
| 91 | PYTHON_EMBEDDED_LIBRARY = python$(PYTHON_VERSION) dl util ; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | if $(NT) |
---|
| 97 | { |
---|
| 98 | PYTHON_ROOT ?= c:/Python$(PYTHON_VERSION_NODOT) ; |
---|
| 99 | |
---|
| 100 | # Reconstitute any paths split due to embedded spaces. |
---|
| 101 | PYTHON_ROOT = $(PYTHON_ROOT:J=" ") ; |
---|
| 102 | |
---|
| 103 | PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/libs [ GLOB $(PYTHON_ROOT) : PCbuild ] ; |
---|
| 104 | |
---|
| 105 | PYTHON_INCLUDES ?= $(PYTHON_ROOT)/include ; |
---|
| 106 | |
---|
| 107 | PYTHON_DLL ?= [ GLOB $(PYTHON_ROOT) $(PATH) $(Path) : python$(PYTHON_VERSION_NODOT).dll ] ; |
---|
| 108 | PYTHON_DEBUG_DLL ?= [ GLOB $(PYTHON_ROOT) $(PATH) $(Path) : python$(PYTHON_VERSION_NODOT)_d.dll ] ; |
---|
| 109 | PYTHON_IMPORT_LIB ?= [ GLOB $(PYTHON_LIB_PATH) : libpython$(PYTHON_VERSION_NODOT).* ] ; |
---|
| 110 | PYTHON_DEBUG_IMPORT_LIB ?= [ GLOB $(PYTHON_LIB_PATH) : libpython$(PYTHON_VERSION_NODOT).* ] ; |
---|
| 111 | } |
---|
| 112 | else if $(UNIX) && $(OS) = MACOSX |
---|
| 113 | { |
---|
| 114 | if ! $(PYTHON_ROOT) |
---|
| 115 | { |
---|
| 116 | if [ GLOB /System/Library/Frameworks : Python.framework ] |
---|
| 117 | { |
---|
| 118 | PYTHON_ROOT ?= /System/Library/Frameworks/Python.framework/Versions/$(PYTHON_VERSION) ; |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | { |
---|
| 122 | PYTHON_ROOT ?= /Library/Frameworks/Python.framework/Versions/$(PYTHON_VERSION) ; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | PYTHON_ROOT = $(PYTHON_ROOT:J=" ") ; |
---|
| 126 | PYTHON_INCLUDES ?= $(PYTHON_ROOT)/include/python$(PYTHON_VERSION) ; |
---|
| 127 | PYTHON_FRAMEWORK ?= $(PYTHON_ROOT) ; |
---|
| 128 | while $(PYTHON_FRAMEWORK:D=) && $(PYTHON_FRAMEWORK:D=) != Python.framework |
---|
| 129 | { |
---|
| 130 | PYTHON_FRAMEWORK = $(PYTHON_FRAMEWORK:D) ; |
---|
| 131 | } |
---|
| 132 | PYTHON_FRAMEWORK = $(PYTHON_FRAMEWORK:D)/Python ; |
---|
| 133 | |
---|
| 134 | PYTHON_PROPERTIES ?= |
---|
| 135 | <sysinclude>$(PYTHON_INCLUDES) |
---|
| 136 | ; |
---|
| 137 | } |
---|
| 138 | else if $(UNIX) |
---|
| 139 | { |
---|
| 140 | PYTHON_ROOT ?= /usr ; |
---|
| 141 | PYTHON_ROOT = $(PYTHON_ROOT:J=" ") ; |
---|
| 142 | PYTHON_INCLUDES ?= $(PYTHON_ROOT)/include/python$(PYTHON_VERSION) ; |
---|
| 143 | PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/lib/python$(PYTHON_VERSION)/config ; |
---|
| 144 | |
---|
| 145 | PYTHON_PROPERTIES ?= |
---|
| 146 | <sysinclude>$(PYTHON_INCLUDES) |
---|
| 147 | <library-path>$(PYTHON_LIB_PATH) |
---|
| 148 | <default>python-intel-use-gcc-stdlib |
---|
| 149 | python-static-multithread |
---|
| 150 | ; |
---|
| 151 | |
---|
| 152 | if $(OS) = OSF |
---|
| 153 | { |
---|
| 154 | local not-gcc-compilers = [ difference $(TOOLS) : $(gcc-compilers) ] ; |
---|
| 155 | |
---|
| 156 | PYTHON_PROPERTIES += |
---|
| 157 | <$(not-gcc-compilers)><*><linkflags>"-expect_unresolved 'Py*' -expect_unresolved '_Py*'" |
---|
| 158 | <$(gcc-compilers)><*><linkflags>"-Xlinker -expect_unresolved -Xlinker 'Py*' -Xlinker -expect_unresolved -Xlinker '_Py*'" ; |
---|
| 159 | } |
---|
| 160 | else if $(OS) = AIX |
---|
| 161 | { |
---|
| 162 | PYTHON_PROPERTIES |
---|
| 163 | += <*><*><linkflags>"-Wl,-bI:$(PYTHON_LIB_PATH)/python.exp" |
---|
| 164 | <*><*><find-library>pthreads ; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | # |
---|
| 169 | # Locate the python executable(s) |
---|
| 170 | # |
---|
| 171 | CYGWIN_ROOT ?= c:/cygwin ; |
---|
| 172 | { |
---|
| 173 | for local cyg in "" CYGWIN_ |
---|
| 174 | { |
---|
| 175 | for local d in "" _D |
---|
| 176 | { |
---|
| 177 | local d_D = _DEBUG ; |
---|
| 178 | local debug = $(d$(d)) ; # "" or _DEBUG |
---|
| 179 | |
---|
| 180 | # select base name of variables |
---|
| 181 | local var-base = $(cyg)PYTHON$(debug) ; |
---|
| 182 | |
---|
| 183 | # Base defaults for the debug build on the non-debug |
---|
| 184 | $(var-base)_VERSION ?= $($(cyg)PYTHON_VERSION) ; |
---|
| 185 | $(var-base)_ROOT ?= $($(cyg)PYTHON_ROOT) ; |
---|
| 186 | |
---|
| 187 | # Version number element of executable name |
---|
| 188 | local exe-version = $($(var-base)_VERSION) ; |
---|
| 189 | if $(NT) && ! $(cyg) { exe-version = $(d:L) ; } |
---|
| 190 | |
---|
| 191 | # assign default target name |
---|
| 192 | local executable = $(cyg)PYTHON$(d) ; |
---|
| 193 | $(executable) ?= <$(cyg)EXE$(d)@>python$(exe-version)$(SUFEXE) ; |
---|
| 194 | |
---|
| 195 | # choose the appropriate root directory/ies to search for the target |
---|
| 196 | local r = $($(var-base)_ROOT) ; |
---|
| 197 | if $(NT) |
---|
| 198 | { |
---|
| 199 | switch $(r) |
---|
| 200 | { |
---|
| 201 | case [/\\]* : # in case of unix-style path |
---|
| 202 | r = $(CYGWIN_ROOT)$(r) $(r) ; # re-root for windows |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | # set up search path |
---|
| 207 | SEARCH on $($(executable)) |
---|
| 208 | = $(r)/bin # Standard locations |
---|
| 209 | $(r) # Standard locations |
---|
| 210 | $(r)/PCBuild # In case building from a windows development Python |
---|
| 211 | $(RUN_PATH) # Just look in the path |
---|
| 212 | ; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | # Normally on Linux, Python is built with GCC. A "poor QOI choice" in |
---|
| 218 | # the implementation of the intel tools prevents the use of |
---|
| 219 | # intel-linked shared libs by a GCC-built executable unless they have |
---|
| 220 | # been told to use the GCC runtime. This rule adds the requisite |
---|
| 221 | # flags to the compile and link lines. |
---|
| 222 | rule python-intel-use-gcc-stdlib ( toolset variant : non-defaults * ) |
---|
| 223 | { |
---|
| 224 | if ( ! $(PYTHON_WINDOWS) ) |
---|
| 225 | && ( ! <define>BOOST_PYTHON_STATIC_LIB in $(non-defaults) ) |
---|
| 226 | && [ MATCH (intel) : $(toolset) ] |
---|
| 227 | { |
---|
| 228 | return <stdlib>gcc ; |
---|
| 229 | } |
---|
| 230 | else |
---|
| 231 | { |
---|
| 232 | return ; |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | # Force statically-linked embedding applications to be multithreaded |
---|
| 237 | # on UNIX. |
---|
| 238 | rule python-static-multithread ( toolset variant : properties * ) |
---|
| 239 | { |
---|
| 240 | if ! $(PYTHON_WINDOWS) |
---|
| 241 | { |
---|
| 242 | local x = <define>BOOST_PYTHON_STATIC_LIB <threading>single ; |
---|
| 243 | if $(x) in $(properties) |
---|
| 244 | { |
---|
| 245 | properties = [ difference $(properties) : <threading>single ] <threading>multi ; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | return $(properties) ; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | # Borland compilers are not supported |
---|
| 252 | rule boost-python-disable-borland ( toolset variant : properties * ) |
---|
| 253 | { |
---|
| 254 | if [ MATCH .*(bcc|borland).* : $(toolset) ] |
---|
| 255 | { |
---|
| 256 | properties += <build>no ; |
---|
| 257 | } |
---|
| 258 | return $(properties) ; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | # select-python-library |
---|
| 262 | # |
---|
| 263 | # Ungristed elements of a requirements list are treated as the rule |
---|
| 264 | # names to be called to transform the property set. This is used when |
---|
| 265 | # the requirements are too complicated to express otherwise. This |
---|
| 266 | # rule selects the right python library when building on Windows. |
---|
| 267 | rule select-python-library ( toolset variant : properties * ) |
---|
| 268 | { |
---|
| 269 | if $(PYTHON_WINDOWS) |
---|
| 270 | { |
---|
| 271 | if $(toolset) in $(gcc-compilers) |
---|
| 272 | { |
---|
| 273 | if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 274 | { |
---|
| 275 | properties += <library-path>$(CYGWIN_PYTHON_DEBUG_LIB_PATH) <find-library>python$(CYGWIN_PYTHON_DEBUG_VERSION).dll ; |
---|
| 276 | } |
---|
| 277 | else |
---|
| 278 | { |
---|
| 279 | properties += <library-path>$(CYGWIN_PYTHON_LIB_PATH) <find-library>python$(CYGWIN_PYTHON_VERSION).dll ; |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | else if [ MATCH .*(mingw).* : $(toolset) ] |
---|
| 283 | { |
---|
| 284 | local lib = $(PYTHON_IMPORT_LIB) ; |
---|
| 285 | if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 286 | { |
---|
| 287 | lib = $(PYTHON_DEBUG_IMPORT_LIB) ; |
---|
| 288 | } |
---|
| 289 | lib ?= $(PYTHON_DLL) ; |
---|
| 290 | if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 291 | { |
---|
| 292 | lib ?= $(PYTHON_DEBUG_DLL) ; |
---|
| 293 | } |
---|
| 294 | properties += <library-file>$(lib) ; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | properties += <library-path>$(PYTHON_LIB_PATH) ; |
---|
| 299 | |
---|
| 300 | if $(toolset) != msvc # msvc compilers auto-find the python library |
---|
| 301 | { |
---|
| 302 | properties += <library-path>$(PYTHON_LIB_PATH) ; |
---|
| 303 | |
---|
| 304 | local lib = python$(PYTHON_VERSION_NODOT) ; |
---|
| 305 | if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 306 | { |
---|
| 307 | lib = python$(PYTHON_VERSION_NODOT)_d ; |
---|
| 308 | } |
---|
| 309 | properties += <find-library>$(lib) ; |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | if $(OS) = MACOSX && [ MATCH .*(darwin).* : $(toolset) ] |
---|
| 314 | { |
---|
| 315 | if <target-type>PYD in $(properties) |
---|
| 316 | { |
---|
| 317 | properties += <link-format>bundle ; |
---|
| 318 | } |
---|
| 319 | properties += <framework>$(PYTHON_FRAMEWORK) ; |
---|
| 320 | } |
---|
| 321 | return $(properties) ; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | if $(NT) |
---|
| 325 | { |
---|
| 326 | python-nt-sysinclude = [ GLOB $(PYTHON_ROOT) : PC ] ; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | rule select-nt-python-includes ( toolset variant : properties * ) |
---|
| 330 | { |
---|
| 331 | if $(toolset) in $(gcc-compilers) |
---|
| 332 | { |
---|
| 333 | local d = "" ; |
---|
| 334 | if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 335 | { |
---|
| 336 | d = DEBUG_ ; |
---|
| 337 | } |
---|
| 338 | properties += <sysinclude>$(CYGWIN_PYTHON_$(d)ROOT)/include/python$(CYGWIN_PYTHON_$(d)VERSION) ; |
---|
| 339 | } |
---|
| 340 | else |
---|
| 341 | { |
---|
| 342 | properties += |
---|
| 343 | <sysinclude>$(PYTHON_INCLUDES) |
---|
| 344 | <sysinclude>$(python-nt-sysinclude) # in case the user is using a source installation |
---|
| 345 | ; |
---|
| 346 | |
---|
| 347 | if [ MATCH (cwpro) : $(toolset) ] && ( $(variant) = debug-python ) |
---|
| 348 | { |
---|
| 349 | properties = [ difference $(properties) : <define>_DEBUG ] ; #it warns about redefinition otherwise. |
---|
| 350 | } |
---|
| 351 | else |
---|
| 352 | { |
---|
| 353 | properties += <debug-python><define>_DEBUG ; |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | return $(properties) ; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | PYTHON_PROPERTIES += |
---|
| 360 | <sysinclude>@boost |
---|
| 361 | <stlport-iostream>on |
---|
| 362 | select-python-library |
---|
| 363 | ; |
---|
| 364 | |
---|
| 365 | BOOST_PYTHON_V2_PROPERTIES |
---|
| 366 | = $(PYTHON_PROPERTIES) |
---|
| 367 | <metrowerks><*><cxxflags>"-inline deferred" |
---|
| 368 | <cwpro8><*><cxxflags>"-inline deferred" # added for internal testing purposes |
---|
| 369 | <cxx><*><sysinclude>@boost/boost/compatibility/cpp_c_headers |
---|
| 370 | <define>BOOST_PYTHON_DYNAMIC_LIB |
---|
| 371 | ; |
---|
| 372 | |
---|
| 373 | # Extends the RUN_PATH assignment for targets built under Cygwin so |
---|
| 374 | # that the Python DLL can be found. |
---|
| 375 | rule add-cygwin-python-run-path ( module ) |
---|
| 376 | { |
---|
| 377 | if <define>BOOST_DEBUG_PYTHON in $(gBUILD_PROPERTIES) |
---|
| 378 | { |
---|
| 379 | gRUN_LD_LIBRARY_PATH($(module)) += $(CYGWIN_PYTHON_DEBUG_DLL_PATH) ; |
---|
| 380 | } |
---|
| 381 | else |
---|
| 382 | { |
---|
| 383 | gRUN_LD_LIBRARY_PATH($(module)) += $(CYGWIN_PYTHON_DLL_PATH) ; |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | # This is the generator function for Python modules. It deals with the |
---|
| 388 | # need to change the name of modules compiled with debugging on. This |
---|
| 389 | # is just a wrapper around the generator for shared libraries, |
---|
| 390 | # dll-files. |
---|
| 391 | rule python-files ( module implib ? : sources * ) |
---|
| 392 | { |
---|
| 393 | dll-files $(module) $(implib) : $(sources) : PYD ; |
---|
| 394 | |
---|
| 395 | if $(gCURRENT_TOOLSET) in $(gcc-compilers) |
---|
| 396 | { |
---|
| 397 | if $(PYTHON_WINDOWS) |
---|
| 398 | { |
---|
| 399 | add-cygwin-python-run-path $(<[-1]) ; |
---|
| 400 | } |
---|
| 401 | else |
---|
| 402 | { |
---|
| 403 | gRUN_PATH($(module)) += $(GCC_ROOT_DIRECTORY)/lib ; |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | if $(NT) |
---|
| 409 | { |
---|
| 410 | # Adjust the name of Python modules so that they have the _d |
---|
| 411 | # suffix when compiled with python debugging enabled. |
---|
| 412 | gNAME_ADJUST(PYD) = name-adjust-PYD ; |
---|
| 413 | |
---|
| 414 | rule name-adjust-PYD ( pyd implib ? : properties * : toolset variant ) |
---|
| 415 | { |
---|
| 416 | # Cygwin python is only happy if compiled modules have a .dll |
---|
| 417 | # extension |
---|
| 418 | if $(toolset) in $(gcc-compilers) |
---|
| 419 | { |
---|
| 420 | pyd = $(pyd:S=.dll) ; |
---|
| 421 | } |
---|
| 422 | else if <define>BOOST_DEBUG_PYTHON in $(properties) |
---|
| 423 | { |
---|
| 424 | pyd = $(pyd:S=)_d$(pyd:S) ; |
---|
| 425 | } |
---|
| 426 | return $(pyd) $(implib) ; |
---|
| 427 | } |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | rule Link-PYD |
---|
| 431 | { |
---|
| 432 | if $(UNIX) |
---|
| 433 | { |
---|
| 434 | LINK_LIBPATH on $(<) = [ join $(gRUN_LD_LIBRARY_PATH($(<))) : $(SPLITPATH) ] ; |
---|
| 435 | } |
---|
| 436 | gRUN_PYTHONPATH($(<)) += $(gLOCATE($(<[1]))) ; |
---|
| 437 | .do-link $(<) : $(>) : PYD ; |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | declare-target-type PYD : <shared-linkable>true ; |
---|
| 441 | gGENERATOR_FUNCTION(PYD) = python-files ; |
---|
| 442 | if $(NT) |
---|
| 443 | { |
---|
| 444 | SUFPYD = .pyd $(SUFDLL[2-]) ; |
---|
| 445 | } |
---|
| 446 | else if $(OS) = MACOSX |
---|
| 447 | { |
---|
| 448 | SUFPYD = .so $(SUFDLL[2-]) ; |
---|
| 449 | } |
---|
| 450 | else |
---|
| 451 | { |
---|
| 452 | SUFPYD = $(SUFDLL) ; |
---|
| 453 | } |
---|
| 454 | PYDMODE = $(DLLMODE) ; |
---|
| 455 | SHARED_TYPES += PYD ; |
---|
| 456 | |
---|
| 457 | gTARGET_TYPE_ID(pyd) = PYD ; |
---|
| 458 | gIS_DEPENDENCY(PYD) = TRUE ; |
---|
| 459 | |
---|
| 460 | # Declare a python extension. |
---|
| 461 | rule extension ( name : sources + : requirements * : default-BUILD * ) |
---|
| 462 | { |
---|
| 463 | requirements += $(BOOST_PYTHON_V2_PROPERTIES) ; |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | declare-local-target $(name) : $(sources) : $(requirements) : $(default-BUILD) : PYD ; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | gGENERATOR_FUNCTION(TEST_PYD) = run-test PYD ; |
---|
| 470 | SUFTEST_PYD = .run ; |
---|
| 471 | |
---|
| 472 | declare-build-succeed-test RUN_PYD : TEST_PYD ; |
---|
| 473 | |
---|
| 474 | # boost-python-runtest target : python-script sources : requirements : local-build : args |
---|
| 475 | # |
---|
| 476 | # declare a python module test $(<).test which builds when out-of-date |
---|
| 477 | # |
---|
| 478 | # pass --python-test-all on the command-line to force rebuilding |
---|
| 479 | rule boost-python-runtest ( |
---|
| 480 | target : sources + : requirements * : local-build * : args * ) |
---|
| 481 | { |
---|
| 482 | local gRUN_TEST_ARGS = $(args) ; |
---|
| 483 | local pyfiles = [ MATCH ^(.*[.]py)$ : $(sources) ] ; |
---|
| 484 | sources = [ difference $(sources) : $(pyfiles) ] ; |
---|
| 485 | local gRUN_TEST_INPUT_FILES = [ FGristFiles $(pyfiles) ] ; |
---|
| 486 | |
---|
| 487 | # tell Jam that the python script is relative to this directory |
---|
| 488 | SEARCH on $(gRUN_TEST_INPUT_FILES) = $(SEARCH_SOURCE) ; |
---|
| 489 | |
---|
| 490 | # The user can add additional arguments in PYTHON_TEST_ARGS. |
---|
| 491 | local gRUN_TEST_ARGS2 = $(PYTHON_TEST_ARGS) ; |
---|
| 492 | gRUN_TEST_ARGS2 ?= -v ; |
---|
| 493 | |
---|
| 494 | # |
---|
| 495 | # Stick the names of the python script and source files used in |
---|
| 496 | # testing into $(source-files) on the main target. This is kind |
---|
| 497 | # of a hack, because boost-test will be returning the name of the |
---|
| 498 | # main target, but unfortunatedly dump-tests runs during the |
---|
| 499 | # evaluation of boost-test and not during the build phase :( |
---|
| 500 | # |
---|
| 501 | local main-target = [ FGristFiles [ expand-target-names $(target) : RUN_PYD ] ] ; |
---|
| 502 | source-files on $(main-target) = $(gRUN_TEST_INPUT_FILES) ; |
---|
| 503 | |
---|
| 504 | local dependencies = [ FGristFiles [ expand-source-names $(sources) ] ] ; |
---|
| 505 | source-files on $(main-target) += $(gTARGET_SOURCES($(dependencies))) ; |
---|
| 506 | |
---|
| 507 | local result = [ |
---|
| 508 | boost-test $(sources) |
---|
| 509 | : RUN_PYD |
---|
| 510 | : $(requirements) |
---|
| 511 | boost-python-disable-borland |
---|
| 512 | <default>python-intel-use-gcc-stdlib # unless otherwise |
---|
| 513 | # specified, assume the GCC standard |
---|
| 514 | # library is needed for intel |
---|
| 515 | : $(target) |
---|
| 516 | : $(local-build) |
---|
| 517 | ] ; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | rule boost-python-test ( name : sources + : requirements * : default-BUILD * ) |
---|
| 521 | { |
---|
| 522 | extension $(name) : $(sources) : $(requirements) <suppress>true : $(4) ; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | # Returns the executable to use for testing one or more Python modules |
---|
| 526 | rule test-executable(PYD) ( targets-to-test + ) |
---|
| 527 | { |
---|
| 528 | # choose the right python executable |
---|
| 529 | local python = $(PYTHON) ; |
---|
| 530 | |
---|
| 531 | if $(NT) |
---|
| 532 | { |
---|
| 533 | local d = "" ; |
---|
| 534 | if <define>BOOST_DEBUG_PYTHON in $(gBUILD_PROPERTIES) |
---|
| 535 | { |
---|
| 536 | d = _D ; |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | if $(gCURRENT_TOOLSET) in $(gcc-compilers) |
---|
| 540 | { |
---|
| 541 | python = $(CYGWIN_PYTHON$(d)) ; |
---|
| 542 | } |
---|
| 543 | else |
---|
| 544 | { |
---|
| 545 | python = $(PYTHON$(d)) ; |
---|
| 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | return $(python) ; |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | rule check-python-config ( ) |
---|
| 553 | { |
---|
| 554 | if --without-python in $(ARGV) |
---|
| 555 | { |
---|
| 556 | gNO_PYTHON_INSTALL = true ; |
---|
| 557 | } |
---|
| 558 | else if ! $(gPYTHON_CONFIG_CHECKED) |
---|
| 559 | { |
---|
| 560 | local dir ; |
---|
| 561 | |
---|
| 562 | if $(NT) && $(TOOLS) in $(gcc-compilers) |
---|
| 563 | { |
---|
| 564 | dir = $(CYGWIN_PYTHON_DEBUG_ROOT) $(CYGWIN_PYTHON_ROOT) ; |
---|
| 565 | v = $(CYGWIN_PYTHON_DEBUG_VERSION) $(CYGWIN_PYTHON_VERSION) ; |
---|
| 566 | dir = $(dir)/include/python$(v) ; |
---|
| 567 | dir = /cygwin/$(dir) $(dir) ; |
---|
| 568 | } |
---|
| 569 | dir += $(PYTHON_INCLUDES) ; |
---|
| 570 | |
---|
| 571 | # This represents an improvement over the checking that was in |
---|
| 572 | # Boost 1.28.0, but it is still an imperfect hack. For |
---|
| 573 | # Boost.Build v2 we will clean up the rules. |
---|
| 574 | if ! [ GLOB $(dir) : Python.h ] |
---|
| 575 | { |
---|
| 576 | gNO_PYTHON_INSTALL = true ; |
---|
| 577 | ECHO "---------------------------------------------------------------------" ; |
---|
| 578 | ECHO "*** If you don't need Boost.Python, you can ignore this section ***" ; |
---|
| 579 | ECHO "*** pass --without-python to suppress this message in the future ***" ; |
---|
| 580 | ECHO ; |
---|
| 581 | ECHO skipping Boost.Python library build due to missing or incorrect configuration ; |
---|
| 582 | ECHO ; |
---|
| 583 | ECHO "couldn't find Python.h in" \"$(dir:J=" ")\" ; |
---|
| 584 | ECHO ; |
---|
| 585 | ECHO You can configure the location of your python installation by setting: ; |
---|
| 586 | ECHO "PYTHON_VERSION - The 2-part python Major.Minor version number (e.g." ; |
---|
| 587 | ECHO " \"2.2\", NOT \"2.2.1\") - currently" \"$(PYTHON_VERSION)\" ; |
---|
| 588 | ECHO ; |
---|
| 589 | if $(NT) |
---|
| 590 | { |
---|
| 591 | ECHO "PYTHON_ROOT - automatically configured from PYTHON_VERSION if not" ; |
---|
| 592 | ECHO " otherwise set ; currently" \"$(PYTHON_ROOT:J=" ")\" ; |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | ECHO "PYTHON_ROOT - currently" \"$(PYTHON_ROOT:J=" ")\" ; |
---|
| 597 | } |
---|
| 598 | ECHO ; |
---|
| 599 | ECHO "The following are automatically configured from PYTHON_ROOT if not" ; |
---|
| 600 | ECHO "otherwise set:" ; |
---|
| 601 | ECHO ; |
---|
| 602 | ECHO " PYTHON_LIB_PATH - path to Python library object; currently" ; |
---|
| 603 | ECHO " \""$(PYTHON_LIB_PATH:J=" ")\" ; |
---|
| 604 | |
---|
| 605 | if ! $(NT) |
---|
| 606 | { |
---|
| 607 | ECHO " PYTHON_INCLUDES - path to Python #include directories; currently" ; |
---|
| 608 | ECHO " \""$(PYTHON_INCLUDES:J=" ")\" ; |
---|
| 609 | } |
---|
| 610 | else if [ intersection $(TOOLS) : $(gcc-compilers) ] |
---|
| 611 | { |
---|
| 612 | ECHO ; |
---|
| 613 | ECHO " For detailed configuration of Boost.Python for Cygwin GCC" ; |
---|
| 614 | ECHO " under Windows NT please see" ; |
---|
| 615 | ECHO " http://www.boost.org/libs/python/doc/building.html" ; |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | ECHO "---------------------------------------------------------------------" ; |
---|
| 619 | } |
---|
| 620 | gPYTHON_CONFIG_CHECKED = true ; |
---|
| 621 | } |
---|
| 622 | if ! $(gNO_PYTHON_INSTALL) |
---|
| 623 | { |
---|
| 624 | return true ; |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | } |
---|