summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Gohad <tusharsg@gmail.com>2015-08-01 22:39:42 -0700
committerTushar Gohad <tusharsg@gmail.com>2015-08-01 22:39:42 -0700
commit0c1d3dfe6595fc45a214a15e2f97c0a74fb79a21 (patch)
tree43e0a43fa6e89036482c03f891f89924d901d0b1
parentc0811b748e1ccc1c72b5d96bc4ab51c642c023f6 (diff)
parentc4e03adddee5d38b953ffcc38b22b5a75b6e8537 (diff)
downloadpyeclib-0c1d3dfe6595fc45a214a15e2f97c0a74fb79a21.tar.gz
Merged libec_path into master
-rw-r--r--setup.py115
1 files changed, 72 insertions, 43 deletions
diff --git a/setup.py b/setup.py
index 37881b5..5f3695b 100644
--- a/setup.py
+++ b/setup.py
@@ -28,6 +28,8 @@ import os
import platform
import sys
+from ctypes import *
+from ctypes.util import *
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.sysconfig import EXEC_PREFIX as _exec_prefix
@@ -48,53 +50,87 @@ platform_str = platform.platform()
platform_arch = platform.architecture()
default_python_incdir = get_python_inc()
default_python_libdir = get_python_lib()
-
default_library_paths = [default_python_libdir]
-if platform_arch[0].startswith('64') and os.path.exists('/lib64'):
- default_library_paths.append('/lib64')
-else:
- default_library_paths.append('/lib')
-if platform_arch[0].startswith('64') and os.path.exists('/usr/lib64'):
- default_library_paths.append('/usr/lib64')
-else:
- default_library_paths.append('/usr/lib')
-if platform_arch[0].startswith('64') and os.path.exists('/usr/local/lib64'):
- default_library_paths.append('/usr/local/lib64')
-else:
- default_library_paths.append('/usr/local/lib')
-if platform_arch[0].startswith('64') and os.path.exists('%s/lib64'
- % _exec_prefix):
- default_library_paths.append('%s/lib64' % _exec_prefix)
-else:
- default_library_paths.append('%s/lib' % _exec_prefix)
-
-
-# utility routine
+
+# utility routines
+def _find_library(name):
+ target_lib = None
+ if os.name == 'posix' and sys.platform.startswith('linux'):
+ target_lib = _findLib_gcc(name)
+ else:
+ target_lib = find_library(name)
+ if target_lib:
+ target_lib = os.path.abspath(target_lib)
+ if os.path.islink(target_lib):
+ p = os.readlink(target_lib)
+ if os.path.isabs(p):
+ target_lib = p
+ else:
+ target_lib = os.path.join(os.path.dirname(target_lib), p)
+ # return absolute path to the library if found
+ return target_lib
+
+
+def _build_default_lib_search_path():
+ arch64 = platform_arch[0].startswith('64')
+ for prefix in ('/', '/usr', '/usr/local', _exec_prefix):
+ libdir = os.path.join(prefix, 'lib')
+ libdir64 = os.path.join(prefix, 'lib64')
+ if arch64 and os.path.exists(libdir64):
+ default_library_paths.append(libdir64)
+ else:
+ default_library_paths.append(libdir)
+ return default_library_paths
+
+
def _read_file_as_str(name):
with open(name, "rt") as f:
s = f.readline().strip()
return s
+def _liberasurecode_install_error(library, library_url):
+ print("**********************************************")
+ print("** ")
+ print("*** Error: " + library + " build failed! ")
+ print("*** Please install " + library + " manually. ")
+ print("*** project url: %s" % library_url)
+ print("** ")
+ print("**********************************************")
+
+
class build(_build):
def check_liberasure(self):
- missing = True
library_basename = "liberasurecode"
library_version = "1.0.8"
+ notfound = True
+ found_path = _find_library(library_basename)
+
if platform_str.find("Darwin") > -1:
liberasure_file = \
library_basename + "." + library_version + ".dylib"
else:
liberasure_file = \
library_basename + ".so." + library_version
- for dir in (default_library_paths):
- liberasure_file_path = dir + os.sep + liberasure_file
- if (os.path.isfile(liberasure_file_path)):
- missing = False
- break
- if missing:
+
+ if found_path:
+ if found_path.endswith(library_version) or \
+ found_path.find(library_version + ".") > -1:
+ # call 1.0.8 the only compatible version for now
+ notfound = False
+
+ if found_path and notfound:
+ # look harder
+ _build_default_lib_search_path()
+ for dir in (default_library_paths):
+ liberasure_file_path = dir + os.sep + liberasure_file
+ if (os.path.isfile(liberasure_file_path)):
+ notfound = False
+ break
+
+ if notfound:
print("***************************************************")
print("** ")
print("** Can not locate %s" % (liberasure_file))
@@ -121,32 +157,25 @@ class build(_build):
curdir = os.getcwd()
os.chdir(locallibsrcdir)
configure_cmd = ("./configure --prefix=/usr")
+ if platform_arch[0].startswith('64'):
+ if os.path.exists('/usr/lib64'):
+ configure_cmd = configure_cmd + " --libdir=/usr/lib64"
print(configure_cmd)
retval = os.system(configure_cmd)
if retval != 0:
- print("**********************************************")
- print("** ")
- print("*** Error: " + library + " build failed! ")
- print("*** Please install " + library + " manually. ")
- print("*** project url: %s" % library_url)
- print("** ")
- print("**********************************************")
+ _liberasurecode_install_error(library, library_url)
os.chdir(curdir)
sys.exit(retval)
make_cmd = ("make && make install")
retval = os.system(make_cmd)
if retval != 0:
- print("**********************************************")
- print("** ")
- print("*** Error: " + library + " install failed! ")
- print("*** Please install " + library + " manually. ")
- print("*** project url: %s" % library_url)
- print("** ")
- print("**********************************************")
+ _liberasurecode_install_error(library, library_url)
os.chdir(curdir)
sys.exit(retval)
os.chdir(curdir)
- sys.exit(1)
+ else:
+ _liberasurecode_install_error(library, library_url)
+ sys.exit(-1)
def run(self):
self.check_liberasure()