From 8d1cb3d74a34971d89602ccd6fc03cf3ab72003a Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Sun, 19 Oct 2014 23:13:06 -0400 Subject: [PATCH] Fix building shared libraries on Darwin The original patch by Apple did not support building shared libraries on Darwin. This corrects that oversight. It also fixes a few other miscellaneous issues like incorrect platform detection and the lack of an entry in the README file. Signed-off-by: Richard Yao --- Makefile | 12 ++++++++++-- README | 1 + lib/Makefile | 4 ++++ lib/access.c | 2 ++ lib/configure | 15 +++++++++++---- lib/internal.h | 4 ++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0a21ee8..9589ea3 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,11 @@ install: all $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7 ifeq ($(SHARED),yes) - ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).so$(ABI_VERSION) +ifeq ($(LIBEXT),dylib) + ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT) +else + ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION) +endif endif ifeq ($(SHARED),yes) @@ -130,7 +134,11 @@ install-lib: $(PCIINC_INS) lib/$(PCILIBPC) install-pcilib $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR) ifeq ($(SHARED),yes) - ln -sf $(LIBNAME).so$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).so +ifeq ($(LIBEXT),dylib) + ln -sf $(LIBNAME)$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT) +else + ln -sf $(LIBNAME).$(LIBEXT)$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT) +endif endif uninstall: all diff --git a/README b/README index d136b86..32f5fa2 100644 --- a/README +++ b/README @@ -26,6 +26,7 @@ In runs on the following systems: CYGWIN (direct port access) BeOS (via syscalls) Haiku (via /dev/misc/poke) + Darwin (via IOKit) It should be very easy to add support for other systems as well (volunteers wanted; if you want to try that, I'll be very glad to see the patches and diff --git a/lib/Makefile b/lib/Makefile index 7bab161..1fedbe6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -56,7 +56,11 @@ $(PCILIB): $(addsuffix .o,$(OBJS)) else CFLAGS += -fPIC -fvisibility=hidden $(PCILIB): $(addsuffix .o,$(OBJS)) + ifdef PCI_HAVE_PM_DARWIN_DEVICE + $(CC) -shared $(LDFLAGS) $(SONAME) -Wl,-install_name,$(LIBDIR)/$(PCILIB) -o $@ $^ $(LIB_LDLIBS) + else $(CC) -shared $(LDFLAGS) $(SONAME) -Wl,--version-script=libpci.ver -o $@ $^ $(LIB_LDLIBS) + endif endif $(PCILIBPC): libpci.pc.in diff --git a/lib/access.c b/lib/access.c index c23a2fd..bb5c9ce 100644 --- a/lib/access.c +++ b/lib/access.c @@ -170,11 +170,13 @@ pci_fill_info_v32(struct pci_dev *d, int flags) /* In version 3.1, pci_fill_info got new flags => versioned alias */ /* In version 3.2, the same has happened */ STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v32(d, flags)); +#ifndef __APPLE__ DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v32); DEFINE_ALIAS(int pci_fill_info_v31(struct pci_dev *d, int flags), pci_fill_info_v32); SYMBOL_VERSION(pci_fill_info_v30, pci_fill_info@LIBPCI_3.0); SYMBOL_VERSION(pci_fill_info_v31, pci_fill_info@LIBPCI_3.1); SYMBOL_VERSION(pci_fill_info_v32, pci_fill_info@@LIBPCI_3.2); +#endif void pci_setup_cache(struct pci_dev *d, byte *cache, int len) diff --git a/lib/configure b/lib/configure index e000079..a647d33 100755 --- a/lib/configure +++ b/lib/configure @@ -58,6 +58,7 @@ echo >$m 'WITH_LIBS=' echo_n "Looking for access methods..." LIBRESOLV=-lresolv +LIBEXT=so case $sys in linux*) @@ -101,12 +102,13 @@ case $sys in LIBRESOLV= ;; - darwin) + darwin*) echo_n " darwin-device" echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE' echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit' echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' LIBRESOLV= + LIBEXT=dylib ;; aix) echo_n " aix-device" @@ -146,6 +148,7 @@ case $sys in ;; esac +echo >>$m "LIBEXT="$LIBEXT echo >>$c '#define PCI_HAVE_PM_DUMP' echo " dump" @@ -227,13 +230,17 @@ if [ "$SHARED" = no ] ; then echo >>$m 'LDLIBS=$(WITH_LIBS)' echo >>$m 'LIB_LDLIBS=' else - echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)' + if [ "$LIBEXT" = so ]; then + echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)' + else + echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)' + fi # We link the dependencies _to_ the library, so we do not need explicit deps in .pc echo >>$m 'LDLIBS=' echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)' echo >>$c '#define PCI_SHARED_LIB' - if [ "$SHARED" = yes ] ; then - echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)' + if [ "$SHARED" = yes -a "$LIBEXT" = so ]; then + echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).$(LIBEXT)$(ABI_VERSION)' fi fi echo >>$m 'PCILIBPC=$(LIBNAME).pc' diff --git a/lib/internal.h b/lib/internal.h index 6045948..03c02f9 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -10,7 +10,11 @@ #ifdef PCI_SHARED_LIB #define PCI_ABI __attribute__((visibility("default"))) +#ifdef __APPLE__ +#define STATIC_ALIAS(_decl, _for) _decl { return _for; } +#else #define STATIC_ALIAS(_decl, _for) +#endif #define DEFINE_ALIAS(_decl, _for) extern _decl __attribute__((alias(#_for))) #define SYMBOL_VERSION(_int, _ext) asm(".symver " #_int "," #_ext) #else -- 2.39.5