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
|
#!/usr/bin/python3
import os, re, sys
from glob import glob
from os.path import join, dirname as up
BOOST_MINIMUM_VERSION = (1,47,0)
def str_version(tpl):
return ".".join(map(str, tpl))
def boost_version(boostDir):
versionFile = join(boostDir, "boost/version.hpp")
try:
m = re.search("#define BOOST_VERSION (.*)", open(versionFile).read())
if m:
versionInt = int(m.group(1))
versionTuple = (versionInt // 100000,
(versionInt// 100) % 1000,
versionInt % 100)
return versionTuple
except:
pass
return None
def find_boost():
"""
Look for boost in some standard filesystem places.
Return the one with the highest version, or None if can't find any.
"""
boost_candidates = \
glob("/usr/include/") + \
glob("/usr/include/boost/") + \
glob("/usr/include/boost*/") + \
glob("/usr/local/include/") + \
glob("/usr/local/boost/") + \
glob("/usr/local/boost*/") + \
glob("/opt/local/include/boost/") + \
glob("/opt/local/include/boost*/")
boosts_found_all = [ (boost, boost_version(boost))
for boost in boost_candidates ]
boosts_found = []
for bf in boosts_found_all:
if not bf[1] == None:
boosts_found.append(bf)
if boosts_found:
best_boost = max(boosts_found, key=lambda t: t[1])[0]
return best_boost
else:
return None
if __name__ == '__main__':
if len(sys.argv) > 1:
boost = sys.argv[1]
_candidate = '%s/include' % boost
if os.path.isfile('%s/boost/version.hpp' % _candidate):
boost = _candidate
else:
boost = find_boost()
if boost_version(boost) < BOOST_MINIMUM_VERSION:
print("Boost version at least %s required!" \
% str_version(BOOST_MINIMUM_VERSION), file=sys.stderr)
print("Use --boost=<path> to specify boost location.", file=sys.stderr)
sys.exit(1)
print(boost)
|