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 8import option ; 9import regex ; 10import 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# 21local 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" 37rule 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). 46python-id = [ option.get "python-buildid" ] ; 47if $(python-id) 48{ 49 PYTHON_ID = [ regex.replace $(python-id) "[*\\/:.\"\']" _ ] ; 50} 51 52rule 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} 69