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.
This commit is contained in:
Saagar Jha 2020-02-11 22:16:34 -08:00 committed by GitHub
parent 901efc4bd4
commit d69ebfa55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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: