summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMarc Abramowitz <marc@marc-abramowitz.com>2015-01-27 17:12:18 -0800
committerMarc Abramowitz <marc@marc-abramowitz.com>2015-01-27 17:12:18 -0800
commitdaab9dd6e9baa26ec7f1c1edf84004890cbedba8 (patch)
treec911e03899655393c60a2171eaa62498b240aaad /setup.py
parent6a2b0aeab86e01354960be326cfb55a91736964f (diff)
downloadcffi-daab9dd6e9baa26ec7f1c1edf84004890cbedba8.tar.gz
OS X with Homebrew: set PKG_CONFIG_PATHosx_use_homebrew
so that it automatically finds a Homebrew-installed libffi Without this, I get: [marca@marca-mac2 cffi]$ python setup.py build Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found ... /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch x86_64 -I/usr/include/ffi -I/usr/include/libffi -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.6-intel-2.7/c/_cffi_backend.o c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 error generated. error: command '/usr/bin/clang' failed with exit status 1 With this, I get: [marca@marca-mac2 cffi]$ python setup.py build_ext -i ... /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch x86_64 -I/usr/local/Cellar/libffi/3.0.13/lib/libffi-3.0.13/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.6-intel-2.7/c/_cffi_backend.o creating build/lib.macosx-10.6-intel-2.7 /usr/bin/clang -bundle -undefined dynamic_lookup -g -arch x86_64 build/temp.macosx-10.6-intel-2.7/c/_cffi_backend.o -L/usr/local/Cellar/libffi/3.0.13/lib -lffi -o build/lib.macosx-10.6-intel-2.7/_cffi_backend.so copying build/lib.macosx-10.6-intel-2.7/_cffi_backend.so -> [marca@marca-mac2 cffi]$ ls -l _cffi_backend.so -rwxr-xr-x+ 1 marca staff 99844 Jan 27 17:11 _cffi_backend.so* [marca@marca-mac2 cffi]$ python -c "import _cffi_backend; print(_cffi_backend)" <module '_cffi_backend' from '_cffi_backend.so'>
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index 91247ce..6f8c7f2 100644
--- a/setup.py
+++ b/setup.py
@@ -66,12 +66,24 @@ def ask_supports_thread():
sys.stderr.write("The above error message can be safely ignored\n")
def use_pkg_config():
+ if sys.platform == 'darwin' and os.path.exists('/usr/local/bin/brew'):
+ use_homebrew_for_libffi()
+
_ask_pkg_config(include_dirs, '--cflags-only-I', '-I', sysroot=True)
_ask_pkg_config(extra_compile_args, '--cflags-only-other')
_ask_pkg_config(library_dirs, '--libs-only-L', '-L', sysroot=True)
_ask_pkg_config(extra_link_args, '--libs-only-other')
_ask_pkg_config(libraries, '--libs-only-l', '-l')
+def use_homebrew_for_libffi():
+ # We can build by setting:
+ # PKG_CONFIG_PATH = $(brew --prefix libffi)/lib/pkgconfig
+ with os.popen('brew --prefix libffi') as brew_prefix_cmd:
+ prefix = brew_prefix_cmd.read().strip()
+ pkgconfig = os.path.join(prefix, 'lib', 'pkgconfig')
+ os.environ['PKG_CONFIG_PATH'] = (
+ os.environ.get('PKG_CONFIG_PATH', '') + ':' + pkgconfig)
+
if sys.platform == 'win32':
COMPILE_LIBFFI = 'c/libffi_msvc' # from the CPython distribution