1 # Makefile for The PCI Utilities
2 # (c) 1998--2023 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 lib/bitops.h
66 PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
68 LMR=margin_hw.o margin.o margin_log.o margin_results.o
69 LMROBJS=$(addprefix lmr/,$(LMR))
74 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 pcilmr.8
76 lib/$(PCIIMPLIB): $(PCIINC) force
81 lib/config.h lib/config.mk:
85 ifeq ($(COMPAT_GETOPT),yes)
86 PCIINC+=compat/getopt.h
87 COMMON+=compat/getopt.o
90 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)
91 setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
93 LSPCIINC=lspci.h pciutils.h $(PCIINC)
94 lspci.o: lspci.c $(LSPCIINC)
95 ls-vpd.o: ls-vpd.c $(LSPCIINC)
96 ls-caps.o: ls-caps.c $(LSPCIINC)
97 ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
98 ls-kernel.o: ls-kernel.c $(LSPCIINC)
99 ls-tree.o: ls-tree.c $(LSPCIINC)
100 ls-map.o: ls-map.c $(LSPCIINC)
102 setpci.o: setpci.c pciutils.h $(PCIINC)
103 common.o: common.c pciutils.h $(PCIINC)
104 compat/getopt.o: compat/getopt.c
106 lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
107 ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS)
109 update-pciids: update-pciids.sh
110 sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@;s@VERSION=.*@VERSION=$(VERSION)@"
113 # The example of use of libpci
114 example$(EXEEXT): example.o lib/$(PCIIMPLIB)
115 example.o: example.c $(PCIINC)
117 $(LMROBJS) pcilmr.o: CFLAGS+=-I .
118 $(LMROBJS): %.o: %.c $(LMRINC) $(PCIINC) pciutils.h
120 pcilmr: pcilmr.o lib/$(PCIIMPLIB) $(LMROBJS) $(COMMON)
121 pcilmr.o: pcilmr.c $(LMRINC) $(PCIINC) pciutils.h
124 $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
128 %-rsrc.rc: lib/winrsrc.rc.in
129 sed <$< >$@ -e 's,@PCILIB_VERSION@,$(PCILIB_VERSION),' \
130 -e 's,@PCILIB_VERSION_WINRC@,$(subst .,\$(comma),$(PCILIB_VERSION).0),' \
131 -e 's,@FILENAME@,$(subst -rsrc.rc,$(EXEEXT),$@),' \
132 -e 's,@DESCRIPTION@,$(subst -rsrc.rc,,$@),' \
133 -e 's,@LIBRARY_BUILD@,0,' \
134 -e 's,@DEBUG_BUILD@,$(if $(findstring -g,$(CFLAGS)),1,0),'
136 $(WINDRES) --input=$< --output=$@ --input-format=rc --output-format=coff
137 lspci$(EXEEXT): lspci-rsrc.o
138 setpci$(EXEEXT): setpci-rsrc.o
142 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)#"
146 find . -name '*.[hc]' -exec ctags --append {} +
150 find . -name '*.[hc]' -exec etags --append {} +
153 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
154 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
160 # -c is ignored on Linux, but required on FreeBSD
161 $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
162 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
163 $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
164 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
166 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
168 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
170 $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
171 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
172 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
174 ifeq ($(LIBEXT),dylib)
175 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
176 else ifeq ($(LIBEXT),so)
177 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
182 install: install-pcilib
185 install-pcilib: lib/$(PCILIB)
186 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
187 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
188 # DLL library must have executable flag on disk and be placed in same directory as where are EXE files
189 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
190 $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
192 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
195 install-lib: $(PCIINC_INS) install-pcilib
196 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
197 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
198 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
199 ifneq ($(PCIIMPLIB),$(PCILIB))
200 $(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
202 ifneq ($(PCIIMPDEF),)
203 $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
206 ifeq ($(LIBEXT),dylib)
207 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
208 ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
209 else ifeq ($(LIBEXT),so)
210 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
211 ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
216 rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
218 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
220 rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
222 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
223 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
224 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
225 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
226 rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
228 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
230 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
231 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
232 ifneq ($(PCIIMPLIB),$(PCILIB))
233 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
235 ifneq ($(PCIIMPDEF),)
236 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
239 ifneq ($(LIBEXT),dll)
240 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
241 ifeq ($(LIBEXT),dylib)
242 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
244 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
252 .PHONY: all clean distclean install install-lib uninstall force tags TAGS