From d69ebfa55c2b9ffc224cf2e95411db0737c98991 Mon Sep 17 00:00:00 2001 From: Saagar Jha Date: Tue, 11 Feb 2020 22:16:34 -0800 Subject: [PATCH] Make it easier to link against libunicorn on macOS (#1195) Adding @rpath to the install name to make it possible to link against the library without modifying it with install_name_tool. Copying both the versioned and unversioned dylibs simplifies linking. --- Makefile | 2 +- bindings/python/setup.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 680701e4..571456ac 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ API_MAJOR=$(shell echo `grep -e UC_API_MAJOR include/unicorn/unicorn.h | grep -v ifeq ($(UNAME_S),Darwin) EXT = dylib VERSION_EXT = $(API_MAJOR).$(EXT) -$(LIBNAME)_LDFLAGS += -dynamiclib -install_name lib$(LIBNAME).$(VERSION_EXT) -current_version $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA) -compatibility_version $(PKG_MAJOR).$(PKG_MINOR) +$(LIBNAME)_LDFLAGS += -dynamiclib -install_name @rpath/lib$(LIBNAME).$(VERSION_EXT) -current_version $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA) -compatibility_version $(PKG_MAJOR).$(PKG_MINOR) AR_EXT = a UNICORN_CFLAGS += -fvisibility=hidden diff --git a/bindings/python/setup.py b/bindings/python/setup.py index aa01fe12..78d65da6 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -60,6 +60,7 @@ else: if SYSTEM == 'darwin': LIBRARY_FILE = "libunicorn.dylib" + MAC_LIBRARY_FILE = "libunicorn*.dylib" STATIC_LIBRARY_FILE = None elif SYSTEM in ('win32', 'cygwin'): LIBRARY_FILE = "unicorn.dll" @@ -171,7 +172,11 @@ def build_libraries(): subprocess.call(cmd, env=new_env) - shutil.copy(LIBRARY_FILE, LIBS_DIR) + if SYSTEM == 'darwin': + for file in glob.glob(MAC_LIBRARY_FILE): + shutil.copy(file, LIBS_DIR, follow_symlinks=False) + else: + shutil.copy(LIBRARY_FILE, LIBS_DIR) try: # static library may fail to build on windows if user doesn't have visual studio installed. this is fine. if STATIC_LIBRARY_FILE is not None: