1 # Makefile for The PCI Utilities
2 # (c) 1998--2022 Martin Mares <mj@ucw.cz>
5 CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes
10 # Host OS and release (override if you are cross-compiling)
15 # Support for compressed pci.ids (yes/no, default: detect)
18 # Support for resolving ID's by DNS (yes/no, default: detect)
21 # Build libpci as a shared library (yes/no; or local for testing; requires GCC)
24 # Use libkmod to resolve kernel modules on Linux (yes/no, default: detect)
27 # Use libudev to resolve device names using hwdb on Linux (yes/no, default: detect)
30 # ABI version suffix in the name of the shared library
31 # (as we use proper symbol versioning, this seldom needs changing)
34 # Installation directories
37 SBINDIR=$(PREFIX)/sbin
38 SHAREDIR=$(PREFIX)/share
40 MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi)
41 INCDIR=$(PREFIX)/include
43 PKGCFDIR=$(LIBDIR)/pkgconfig
50 CC=$(CROSS_COMPILE)gcc
55 RANLIB=$(CROSS_COMPILE)ranlib
56 DLLTOOL=$(CROSS_COMPILE)dlltool
57 WINDRES=$(CROSS_COMPILE)windres
59 # Base name of the library (overridden on NetBSD, which has its own libpci)
62 -include lib/config.mk
64 PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
65 PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
69 all: lib/$(PCIIMPLIB) lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS)
71 lib/$(PCIIMPLIB): $(PCIINC) force
76 lib/config.h lib/config.mk:
80 ifeq ($(COMPAT_GETOPT),yes)
81 PCIINC+=compat/getopt.h
82 COMMON+=compat/getopt.o
85 lspci$(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/$(PCIIMPLIB)
86 setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
88 LSPCIINC=lspci.h pciutils.h $(PCIINC)
89 lspci.o: lspci.c $(LSPCIINC)
90 ls-vpd.o: ls-vpd.c $(LSPCIINC)
91 ls-caps.o: ls-caps.c $(LSPCIINC)
92 ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
93 ls-kernel.o: ls-kernel.c $(LSPCIINC)
94 ls-tree.o: ls-tree.c $(LSPCIINC)
95 ls-map.o: ls-map.c $(LSPCIINC)
97 setpci.o: setpci.c pciutils.h $(PCIINC)
98 common.o: common.c pciutils.h $(PCIINC)
99 compat/getopt.o: compat/getopt.c
101 lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
102 ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS)
104 update-pciids: update-pciids.sh
105 sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@"
108 # The example of use of libpci
109 example$(EXEEXT): example.o lib/$(PCIIMPLIB)
110 example.o: example.c $(PCIINC)
113 $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
116 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)#"
120 find . -name '*.[hc]' -exec ctags --append {} +
124 find . -name '*.[hc]' -exec etags --append {} +
127 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
128 rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* lib/*.dll lib/*.def lib/dllrsrc.rc tags
134 # -c is ignored on Linux, but required on FreeBSD
135 $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
136 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
137 $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
138 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
140 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
142 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
144 $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
145 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
146 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
148 ifeq ($(LIBEXT),dylib)
149 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
150 else ifeq ($(LIBEXT),so)
151 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
156 install: install-pcilib
159 install-pcilib: lib/$(PCILIB)
160 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
161 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
162 # DLL library must have executable flag on disk and be placed in same directory as where are EXE files
163 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
164 $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
166 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
169 install-lib: $(PCIINC_INS) install-pcilib
170 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
171 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
172 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
173 ifneq ($(PCIIMPLIB),$(PCILIB))
174 $(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
176 ifneq ($(PCIIMPDEF),)
177 $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
180 ifeq ($(LIBEXT),dylib)
181 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
182 ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
183 else ifeq ($(LIBEXT),so)
184 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
185 ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
190 rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
192 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
194 rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
196 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
197 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
198 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
199 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
200 rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
202 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
204 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
205 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
206 ifneq ($(PCIIMPLIB),$(PCILIB))
207 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
209 ifneq ($(PCIIMPDEF),)
210 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
213 ifneq ($(LIBEXT),dll)
214 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
215 ifeq ($(LIBEXT),dylib)
216 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
218 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
226 .PHONY: all clean distclean install install-lib uninstall force tags TAGS