7818ff41a4e43e986fd1cc1b341f2845e5e8af80
[oota-llvm.git] / bindings / python / llvm / common.py
1 #===- common.py - Python LLVM Bindings -----------------------*- python -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7 #
8 #===------------------------------------------------------------------------===#
9
10 from ctypes import cdll
11
12 import ctypes.util
13 import platform
14
15 __all__ = [
16     "find_library",
17     "get_library",
18 ]
19
20 def find_library():
21     # FIXME should probably have build system define absolute path of shared
22     # library at install time.
23     for lib in ["LLVM-3.1svn", "LLVM"]:
24         result = ctypes.util.find_library(lib)
25         if result:
26             return result
27
28     # FIXME This is a local hack to ease development.
29     return "/usr/local/llvm/lib/libLLVM-3.1svn.so"
30
31 def get_library():
32     """Obtain a reference to the llvm library."""
33     lib = find_library()
34     if not lib:
35         raise Exception("LLVM shared library not found!")
36
37     return cdll.LoadLibrary(lib)