1 # Makefile for The PCI Utilities
2 # (c) 1998--2024 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 STRIP+=--strip-program $(CROSS_COMPILE)strip
51 CC=$(CROSS_COMPILE)gcc
56 RANLIB=$(CROSS_COMPILE)ranlib
57 DLLTOOL=$(CROSS_COMPILE)dlltool
58 WINDRES=$(CROSS_COMPILE)windres
60 # Base name of the library (overridden on NetBSD, which has its own libpci)
63 -include lib/config.mk
65 PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
66 PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
68 UTILINC=pciutils.h bitops.h $(PCIINC)
70 LMR=margin_hw.o margin.o margin_log.o margin_results.o
71 LMROBJS=$(addprefix lmr/,$(LMR))
72 LMRINC=lmr/lmr.h $(UTILINC)
76 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) pcilmr$(EXEEXT) pcilmr.8
78 lib/$(PCIIMPLIB): $(PCIINC) force
83 lib/config.h lib/config.mk:
87 ifeq ($(COMPAT_GETOPT),yes)
88 PCIINC+=compat/getopt.h
89 COMMON+=compat/getopt.o
92 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)
93 setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
95 LSPCIINC=lspci.h $(UTILINC)
96 lspci.o: lspci.c $(LSPCIINC)
97 ls-vpd.o: ls-vpd.c $(LSPCIINC)
98 ls-caps.o: ls-caps.c $(LSPCIINC)
99 ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
100 ls-kernel.o: ls-kernel.c $(LSPCIINC)
101 ls-tree.o: ls-tree.c $(LSPCIINC)
102 ls-map.o: ls-map.c $(LSPCIINC)
104 setpci.o: setpci.c $(UTILINC)
105 common.o: common.c $(UTILINC)
106 compat/getopt.o: compat/getopt.c
108 lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
109 ls-kernel.o: override CFLAGS+=$(LIBKMOD_CFLAGS)
111 update-pciids: update-pciids.sh
112 sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@;s@VERSION=.*@VERSION=$(VERSION)@"
115 # The example of use of libpci
116 example$(EXEEXT): example.o lib/$(PCIIMPLIB)
117 example.o: example.c $(PCIINC)
119 $(LMROBJS) pcilmr.o: override CFLAGS+=-I .
120 $(LMROBJS): %.o: %.c $(LMRINC)
122 pcilmr$(EXEEXT): pcilmr.o $(LMROBJS) $(COMMON) lib/$(PCIIMPLIB)
123 pcilmr.o: pcilmr.c $(LMRINC)
126 $(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
130 %-rsrc.rc: lib/winrsrc.rc.in
131 sed <$< >$@ -e 's,@PCILIB_VERSION@,$(PCILIB_VERSION),' \
132 -e 's,@PCILIB_VERSION_WINRC@,$(subst .,\$(comma),$(PCILIB_VERSION).0),' \
133 -e 's,@FILENAME@,$(subst -rsrc.rc,$(EXEEXT),$@),' \
134 -e 's,@DESCRIPTION@,$(subst -rsrc.rc,,$@),' \
135 -e 's,@LIBRARY_BUILD@,0,' \
136 -e 's,@DEBUG_BUILD@,$(if $(findstring -g,$(CFLAGS)),1,0),'
138 $(WINDRES) --input=$< --output=$@ --input-format=rc --output-format=coff
139 lspci$(EXEEXT): lspci-rsrc.o
140 setpci$(EXEEXT): setpci-rsrc.o
141 pcilmr$(EXEEXT): pcilmr-rsrc.o
145 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)#"
149 find . -name '*.[hc]' -exec ctags --append {} +
153 find . -name '*.[hc]' -exec etags --append {} +
156 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
157 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 *-rsrc.rc tags pcilmr$(EXEEXT)
163 # -c is ignored on Linux, but required on FreeBSD
164 $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
165 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
166 $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
167 $(INSTALL) -c -m 755 $(STRIP) pcilmr$(EXEEXT) $(DESTDIR)$(SBINDIR)
168 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
170 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
172 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
174 $(INSTALL) -c -m 644 lspci.8 setpci.8 pcilmr.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
175 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
176 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
178 ifeq ($(LIBEXT),dylib)
179 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
180 else ifeq ($(LIBEXT),so)
181 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
186 install: install-pcilib
189 install-pcilib: lib/$(PCILIB)
190 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
191 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
192 # DLL library must have executable flag on disk and be placed in same directory as where are EXE files
193 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
194 $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
196 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
199 install-lib: $(PCIINC_INS) install-pcilib
200 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
201 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
202 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
203 ifneq ($(PCIIMPLIB),$(PCILIB))
204 $(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
206 ifneq ($(PCIIMPDEF),)
207 $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
210 ifeq ($(LIBEXT),dylib)
211 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
212 ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
213 else ifeq ($(LIBEXT),so)
214 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
215 ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
220 rm -f $(DESTDIR)$(LSPCIDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/pcilmr$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
222 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
224 rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
226 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/pcilmr.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
227 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
228 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
229 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
230 rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
232 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
234 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
235 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
236 ifneq ($(PCIIMPLIB),$(PCILIB))
237 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
239 ifneq ($(PCIIMPDEF),)
240 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
243 ifneq ($(LIBEXT),dll)
244 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
245 ifeq ($(LIBEXT),dylib)
246 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
248 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
256 .PHONY: all clean distclean install install-lib uninstall force tags TAGS