]> mj.ucw.cz Git - pciutils.git/commitdiff
Added infrastructure for building libpci as a shared library.
authorMartin Mares <mj@ucw.cz>
Sun, 17 Feb 2008 22:21:23 +0000 (23:21 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 17 Feb 2008 22:21:23 +0000 (23:21 +0100)
Use `make SHARED=yes' or `make SHARED=local' to enable this feature.
Restriction of symbol exports and symbol versioning will come soon.

.gitignore
Makefile
README
lib/Makefile
lib/configure

index 224072ae6ecad4d36f561d4f0a6398aaf9936f61..7d67bb7bd7a16c2ab739523032be58a25c498561 100644 (file)
@@ -1,5 +1,6 @@
 *.a
 *.o
+*.so
 *.[0-9]
 lspci
 setpci
index f755a522ed6378b5cb023d7657f82fa7e6898c8a..4624d72b98ed0be5a1b57190c60db0777a43f893 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,12 @@ ZLIB=
 # Support for resolving ID's by DNS (yes/no, default: detect)
 DNS=
 
+# Build libpci as a shared library (yes/no; or local for testing; requires GCC)
+SHARED=no
+
+# ABI version suffix in the name of the shared library
+ABI_VERSION=.2.2.99
+
 # Installation directories
 PREFIX=/usr/local
 SBINDIR=$(PREFIX)/sbin
@@ -34,18 +40,19 @@ STRIP=-s
 AR=ar
 RANLIB=ranlib
 
-PCILIB=lib/libpci.a
-PCILIBPC=lib/libpci.pc
-PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
-PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
+# Base name of the library (overriden on NetBSD, which has its own libpci)
+LIBNAME=libpci
 
 -include lib/config.mk
 
+PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
+PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
+
 export
 
-all: $(PCILIB) lspci setpci lspci.8 setpci.8 pcilib.7 update-pciids update-pciids.8 $(PCI_IDS)
+all: lib/$(PCILIB) lspci setpci lspci.8 setpci.8 pcilib.7 update-pciids update-pciids.8 $(PCI_IDS)
 
-$(PCILIB): $(PCIINC) force
+lib/$(PCILIB): $(PCIINC) force
        $(MAKE) -C lib all
 
 force:
@@ -53,8 +60,8 @@ force:
 lib/config.h lib/config.mk:
        cd lib && ./configure
 
-lspci: lspci.o common.o $(PCILIB)
-setpci: setpci.o common.o $(PCILIB)
+lspci: lspci.o common.o lib/$(PCILIB)
+setpci: setpci.o common.o lib/$(PCILIB)
 
 lspci.o: lspci.c pciutils.h $(PCIINC)
 setpci.o: setpci.c pciutils.h $(PCIINC)
@@ -72,7 +79,7 @@ update-pciids: update-pciids.sh
 
 clean:
        rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
-       rm -f update-pciids lspci setpci lib/config.* lib/example *.[78] pci.ids.* lib/*.pc
+       rm -f update-pciids lspci setpci lib/config.* lib/example *.[78] pci.ids.* lib/*.pc lib/*.so lib/*.so.*
        rm -rf maint/dist
 
 distclean: clean
@@ -85,12 +92,16 @@ install: all
        $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
        $(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)
+       $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
+       $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
+endif
 
-install-lib: $(PCIINC_INS) $(PCILIB) $(PCILIBPC)
+install-lib: $(PCIINC_INS) lib/$(PCILIB) lib/$(PCILIBPC)
        $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(LIBDIR) $(DESTDIR)$(PKGCFDIR)
        $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
-       $(INSTALL) -c -m 644 $(PCILIB) $(DESTDIR)$(LIBDIR)
-       $(INSTALL) -c -m 644 $(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
+       $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
+       $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
 
 uninstall: all
        rm -f $(DESTDIR)$(SBINDIR)/lspci $(DESTDIR)$(SBINDIR)/setpci $(DESTDIR)$(SBINDIR)/update-pciids
diff --git a/README b/README
index d8eab4182fc5dee16915b1befabb8ecbdc699782..8c354bf57b119ed34475b46226c1063708518c8e 100644 (file)
--- a/README
+++ b/README
@@ -43,6 +43,7 @@ The utilities include:  (See manual pages for more details)
 2. Compiling and (un)installing
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Just run "make" to compile the package and then "make install" to install it.
+Please note that GNU make is needed on most platforms.
 
 If you want to change the default installation location, please override
 the PREFIX variable specified in the Makefile -- e.g., you can use
@@ -52,12 +53,31 @@ will allow you to install to a different directory from the one you intend
 to eventually run it from.  This is useful for people who are packaging
 pciutils to install on other computers.
 
-The configure script will automatically enable support for a compressed
-pci.ids if you have zlib installed.  You can override its guess by using
-"make ZLIB=no" or "make ZLIB=yes".  If compressed support is enabled,
-pciutils will use pci.ids.gz in preference to pci.ids, even if the
-pci.ids file is newer.  If the pci.ids.gz file is missing, it will use
-pci.ids instead.
+There are several options which can be set in the Makefile or overridden
+when running make:
+
+  ZLIB=yes/no  Enable support for compressed pci.ids (requires zlib).
+               If it is enabled, pciutils will use pci.ids.gz in preference to
+               pci.ids, even if the pci.ids file is newer.  If the pci.ids.gz
+               file is missing, it will use pci.ids instead.  If you do not
+               specify this option, the configure script will try to guess
+               automatically based on the presence of zlib.
+
+  DNS=yes/no   Enable support for querying the central database of PCI ID's
+               using DNS.  Requires libresolv (which is available on most
+               systems as a part of the standard libraries) and tries to
+               autodetect its presence if the option is not specified.
+
+  SHARED=yes/  Build libpci as a shared library.  Requires the GNU toolchain.
+  no/local     The ABI of the shared library is intended to remain backward
+               compatible for a long time (we use symbol versioning to achieve
+               that, like GNU libc does).  The value `local' includes the
+               right directory name in the binaries, so the utilities can be
+               run without installation.  This is not recommended for any
+               production builds.
+
+"make install-lib" installs the library together with its header files
+for use by other programs.
 
 When you are bored of dumping PCI registers, just use "make uninstall".
 
index 18fff3a9df7de4e1d624a7752a14169c6bbdc4d4..1a729da7c5e5a3b2f540270c8195381a9ead04b1 100644 (file)
@@ -3,30 +3,27 @@
 
 include config.mk
 
-OBJS=init.o access.o generic.o dump.o names.o filter.o names-hash.o names-parse.o names-net.o names-cache.o params.o
+OBJS=init access generic dump names filter names-hash names-parse names-net names-cache params
 INCL=internal.h pci.h config.h header.h sysdep.h types.h
 
-PCILIB=libpci.a
-PCILIBPC=libpci.pc
-
 ifdef PCI_HAVE_PM_LINUX_SYSFS
-OBJS += sysfs.o
+OBJS += sysfs
 endif
 
 ifdef PCI_HAVE_PM_LINUX_PROC
-OBJS += proc.o
+OBJS += proc
 endif
 
 ifdef PCI_HAVE_PM_INTEL_CONF
-OBJS += i386-ports.o
+OBJS += i386-ports
 endif
 
 ifdef PCI_HAVE_PM_DUMP
-OBJS += dump.o
+OBJS += dump
 endif
 
 ifdef PCI_HAVE_PM_FBSD_DEVICE
-OBJS += fbsd-device.o
+OBJS += fbsd-device
 CFLAGS += -I/usr/src/sys
 ifdef FREEBSD_SYS
 CFLAGS += -I${FREEBSD_SYS}
@@ -34,26 +31,31 @@ endif
 endif
 
 ifdef PCI_HAVE_PM_OBSD_DEVICE
-OBJS += obsd-device.o
+OBJS += obsd-device
 endif
 
 ifdef PCI_HAVE_PM_AIX_DEVICE
-OBJS += aix-device.o
+OBJS += aix-device
 endif
 
 ifdef PCI_HAVE_PM_NBSD_LIBPCI
-OBJS += nbsd-libpci.o
-PCILIB=libpciutils.a
+OBJS += nbsd-libpci
 endif
 
 all: $(PCILIB) $(PCILIBPC)
 
-$(PCILIB): $(OBJS)
+ifeq ($(SHARED),no)
+$(PCILIB): $(addsuffix .o,$(OBJS))
        rm -f $@
        $(AR) rcs $@ $^
        $(RANLIB) $@
+else
+CFLAGS += -fPIC
+$(PCILIB): $(addsuffix .o,$(OBJS))
+       $(CC) -shared $(SONAME) -o $@ $^ $(LIB_LDLIBS)
+endif
 
-$(PCILIBPC): $(PCILIBPC).in
+$(PCILIBPC): libpci.pc.in
        sed <$< >$@ -e 's,@PREFIX@,$(PREFIX),' \
                -e 's,@INCDIR@,$(INCDIR),' \
                -e 's,@LIBDIR@,$(LIBDIR),' \
index 20720230189bfa2398aec8090fe4a9e87e175f17..e5ee300b2dd7d0f329c193b20212fbeb0f0ea9e7 100755 (executable)
@@ -44,7 +44,7 @@ c=config.h
 m=config.mk
 echo >$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
-echo >$m 'LDLIBS='
+echo >$m 'WITH_LIBS='
 
 echo_n "Looking for access methods..."
 
@@ -97,8 +97,8 @@ case $sys in
                echo_n " nbsd-libpci"
                echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
                echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
-               echo >>$m 'PCILIB=lib/libpciutils.a'
-               echo >>$m 'LDLIBS+=-lpci'
+               echo >>$m 'LIBNAME=libpciutils'
+               echo >>$m 'WITH_LIBS+=-lpci'
                ;;
        gnu)
                echo_n " i386-ports"
@@ -128,7 +128,7 @@ if [ "$ZLIB" = yes ] ; then
        echo >>$c '#define PCI_COMPRESSED_IDS'
        echo >>$c '#define PCI_IDS "pci.ids.gz"'
        echo >>$m 'LIBZ=-lz'
-       echo >>$m 'LDLIBS+=$(LIBZ)'
+       echo >>$m 'WITH_LIBS+=$(LIBZ)'
 else
        echo >>$c '#define PCI_IDS "pci.ids"'
 fi
@@ -148,8 +148,24 @@ fi
 if [ "$DNS" = yes ] ; then
        echo >>$c "#define PCI_USE_DNS"
        echo >>$c "#define PCI_ID_DOMAIN \"pci-id.ucw.cz\""
-       echo >>$m 'LDLIBS+=-lresolv'
+       echo >>$m 'WITH_LIBS+=-lresolv'
 fi
 
+echo "Checking whether to build a shared library... $SHARED (set manually)"
+if [ "$SHARED" = no ] ; then
+       echo >>$m 'PCILIB=$(LIBNAME).a'
+       echo >>$m 'LDLIBS=$(WITH_LIBS)'
+       echo >>$m 'LIB_LDLIBS='
+else
+       echo >>$m 'PCILIB=$(LIBNAME)-$(VERSION).so'
+       # 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)'
+       if [ "$SHARED" = yes ] ; then
+               echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
+       fi
+fi
+echo >>$m 'PCILIBPC=$(LIBNAME).pc'
+
 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m