1# Makefile for The PCI Utilities 2# (c) 1998--2020 Martin Mares <[email protected]> 3 4OPT=-O2 5CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes 6 7VERSION=3.7.0 8DATE=2020-05-31 9 10# Host OS and release (override if you are cross-compiling) 11HOST= 12RELEASE= 13CROSS_COMPILE= 14 15# Support for compressed pci.ids (yes/no, default: detect) 16ZLIB= 17 18# Support for resolving ID's by DNS (yes/no, default: detect) 19DNS= 20 21# Build libpci as a shared library (yes/no; or local for testing; requires GCC) 22SHARED=no 23 24# Use libkmod to resolve kernel modules on Linux (yes/no, default: detect) 25LIBKMOD= 26 27# Use libudev to resolve device names using hwdb on Linux (yes/no, default: detect) 28HWDB= 29 30# ABI version suffix in the name of the shared library 31# (as we use proper symbol versioning, this seldom needs changing) 32ABI_VERSION=.3 33 34# Installation directories 35PREFIX=/usr/local 36SBINDIR=$(PREFIX)/sbin 37SHAREDIR=$(PREFIX)/share 38IDSDIR=$(SHAREDIR) 39MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi) 40INCDIR=$(PREFIX)/include 41LIBDIR=$(PREFIX)/lib 42PKGCFDIR=$(LIBDIR)/pkgconfig 43 44# Commands 45INSTALL=install 46DIRINSTALL=install -d 47STRIP=-s 48CC=$(CROSS_COMPILE)gcc 49AR=$(CROSS_COMPILE)ar 50RANLIB=$(CROSS_COMPILE)ranlib 51 52# Base name of the library (overridden on NetBSD, which has its own libpci) 53LIBNAME=libpci 54 55-include lib/config.mk 56 57PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h 58PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h 59 60export 61 62all: lib/$(PCILIB) lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS) 63 64lib/$(PCILIB): $(PCIINC) force 65 $(MAKE) -C lib all 66 67force: 68 69lib/config.h lib/config.mk: 70 cd lib && ./configure 71 72COMMON=common.o 73ifeq ($(COMPAT_GETOPT),yes) 74PCIINC+=compat/getopt.h 75COMMON+=compat/getopt.o 76endif 77 78lspci$(EXEEXT): lspci.o ls-vpd.o ls-caps.o ls-caps-vendor.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o $(COMMON) lib/$(PCILIB) 79setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCILIB) 80 81LSPCIINC=lspci.h pciutils.h $(PCIINC) 82lspci.o: lspci.c $(LSPCIINC) 83ls-vpd.o: ls-vpd.c $(LSPCIINC) 84ls-caps.o: ls-caps.c $(LSPCIINC) 85ls-ecaps.o: ls-ecaps.c $(LSPCIINC) 86ls-kernel.o: ls-kernel.c $(LSPCIINC) 87ls-tree.o: ls-tree.c $(LSPCIINC) 88ls-map.o: ls-map.c $(LSPCIINC) 89 90setpci.o: setpci.c pciutils.h $(PCIINC) 91common.o: common.c pciutils.h $(PCIINC) 92compat/getopt.o: compat/getopt.c 93 94lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS) 95ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS) 96 97update-pciids: update-pciids.sh 98 sed <$< >$@ "s@^DEST=.*@DEST=$(IDSDIR)/$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@" 99 chmod +x $@ 100 101# The example of use of libpci 102example$(EXEEXT): example.o lib/$(PCILIB) 103example.o: example.c $(PCIINC) 104 105%$(EXEEXT): %.o 106 $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ 107 108%.8 %.7 %.5: %.man 109 M=`echo $(DATE) | sed 's/-01-/-January-/;s/-02-/-February-/;s/-03-/-March-/;s/-04-/-April-/;s/-05-/-May-/;s/-06-/-June-/;s/-07-/-July-/;s/-08-/-August-/;s/-09-/-September-/;s/-10-/-October-/;s/-11-/-November-/;s/-12-/-December-/;s/\(.*\)-\(.*\)-\(.*\)/\3 \2 \1/'` ; sed <$< >$@ "s/@TODAY@/$$M/;s/@VERSION@/pciutils-$(VERSION)/;s#@IDSDIR@#$(IDSDIR)#;s#@PCI_IDS@#$(PCI_IDS)#" 110 111ctags: 112 rm -f tags 113 find . -name '*.[hc]' -exec ctags --append {} + 114 115TAGS: 116 rm -f TAGS 117 find . -name '*.[hc]' -exec etags --append {} + 118 119clean: 120 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"` 121 rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags 122 rm -rf maint/dist 123 124distclean: clean 125 126install: all 127# -c is ignored on Linux, but required on FreeBSD 128 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)/$(MANDIR)/man5 129 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR) 130 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR) 131 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR) 132 $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8 133 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7 134 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5 135ifeq ($(SHARED),yes) 136ifeq ($(LIBEXT),dylib) 137 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT) 138else 139 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION) 140endif 141endif 142 143ifeq ($(SHARED),yes) 144install: install-pcilib 145endif 146 147install-pcilib: lib/$(PCILIB) 148 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR) 149 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR) 150 151install-lib: $(PCIINC_INS) install-pcilib 152 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR) 153 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci 154 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR) 155ifeq ($(SHARED),yes) 156ifeq ($(LIBEXT),dylib) 157 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT) 158 ln -sf $(LIBNAME)$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT) 159else 160 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION) 161 ln -sf $(LIBNAME).$(LIBEXT)$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT) 162endif 163endif 164 165uninstall: all 166 rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids 167 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS) 168 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8 169 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7 170 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5 171 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB) 172 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC) 173 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS))) 174ifeq ($(SHARED),yes) 175 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT) 176ifeq ($(LIBEXT),dylib) 177 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT) 178else 179 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION) 180endif 181endif 182 183pci.ids.gz: pci.ids 184 gzip -9n <$< >$@ 185 186.PHONY: all clean distclean install install-lib uninstall force tags TAGS 187