Debian Codegraph @

Makefile

raw
1 # Makefile for The PCI Utilities
2 # (c) 1998--2026 Martin Mares <[email protected]>
3
4 OPT=-O2
5 CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes
6
7 VERSION=3.15.0
8 DATE=2026-04-05
9
10 # Host OS and release (override if you are cross-compiling)
11 HOST=
12 RELEASE=
13 CROSS_COMPILE=
14
15 # Support for compressed pci.ids (yes/no, default: detect)
16 ZLIB=
17
18 # Support for resolving IDs by DNS (yes/no, default: detect)
19 DNS=
20
21 # Build libpci as a shared library (yes/no; or local for testing; requires GCC)
22 SHARED=no
23
24 # Use libkmod to resolve kernel modules on Linux (yes/no, default: detect)
25 LIBKMOD=
26
27 # Use libudev to resolve device names using hwdb on Linux (yes/no, default: detect)
28 HWDB=
29
30 # ABI version suffix in the name of the shared library
31 # (as we use proper symbol versioning, this seldom needs changing)
32 ABI_VERSION=3
33
34 # Installation directories
35 PREFIX=/usr/local
36 BINDIR=$(PREFIX)/bin
37 SBINDIR=$(PREFIX)/sbin
38 SHAREDIR=$(PREFIX)/share
39 IDSDIR=$(SHAREDIR)
40 MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi)
41 INCDIR=$(PREFIX)/include
42 LIBDIR=$(PREFIX)/lib
43 PKGCFDIR=$(LIBDIR)/pkgconfig
44
45 # Commands
46 INSTALL=install
47 DIRINSTALL=install -d
48 STRIP=-s
49 ifdef CROSS_COMPILE
50 STRIP+=--strip-program $(CROSS_COMPILE)strip
51 CC=$(CROSS_COMPILE)gcc
52 else
53 CC=cc
54 endif
55 AR=$(CROSS_COMPILE)ar
56 RANLIB=$(CROSS_COMPILE)ranlib
57 DLLTOOL=$(CROSS_COMPILE)dlltool
58 WINDRES=$(CROSS_COMPILE)windres
59
60 # Base name of the library (overridden on NetBSD, which has its own libpci)
61 LIBNAME=libpci
62
63 -include lib/config.mk
64
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
67
68 UTILINC=pciutils.h bitops.h $(PCIINC)
69
70 LMR=margin_hw.o margin.o margin_log.o margin_results.o margin_args.o
71 LMROBJS=$(addprefix lmr/,$(LMR))
72 LMRINC=lmr/lmr.h $(UTILINC)
73
74 export
75
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
77
78 lib/$(PCIIMPLIB): $(PCIINC) force
79 $(MAKE) -C lib all
80
81 force:
82
83 lib/config.h lib/config.mk:
84 cd lib && ./configure
85
86 COMMON=common.o
87 ifeq ($(COMPAT_GETOPT),yes)
88 PCIINC+=compat/getopt.h
89 COMMON+=compat/getopt.o
90 endif
91
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)
94
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)
103
104 setpci.o: setpci.c $(UTILINC)
105 common.o: common.c $(UTILINC)
106 compat/getopt.o: compat/getopt.c
107
108 lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
109 ls-kernel.o: override CFLAGS+=$(LIBKMOD_CFLAGS)
110
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)@"
113 chmod +x $@
114
115 # The example of use of libpci
116 example$(EXEEXT): example.o lib/$(PCIIMPLIB)
117 example.o: example.c $(PCIINC)
118
119 $(LMROBJS) pcilmr.o: override CFLAGS+=-I .
120 $(LMROBJS): %.o: %.c $(LMRINC)
121
122 pcilmr$(EXEEXT): pcilmr.o $(LMROBJS) $(COMMON) lib/$(PCIIMPLIB)
123 pcilmr.o: pcilmr.c $(LMRINC)
124
125 %$(EXEEXT): %.o
126 $(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
127
128 ifdef PCI_OS_WINDOWS
129 comma := ,
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),'
137 %-rsrc.o: %-rsrc.rc
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
142 endif
143
144 %.5: %.man tools/build-man
145 tools/build-man $< $@
146
147 %.7: %.man tools/build-man
148 tools/build-man $< $@
149
150 %.8: %.man tools/build-man
151 tools/build-man $< $@
152
153 clean:
154 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name core -o -name "*.orig"`
155 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)
156 rm -rf maint/dist
157
158 distclean: clean
159
160 install: all
161 # -c is ignored on Linux, but required on FreeBSD
162 $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
163 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
164 $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
165 $(INSTALL) -c -m 755 $(STRIP) pcilmr$(EXEEXT) $(DESTDIR)$(SBINDIR)
166 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
167 ifneq ($(IDSDIR),)
168 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
169 else
170 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
171 endif
172 $(INSTALL) -c -m 644 lspci.8 setpci.8 pcilmr.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
173 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
174 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
175 ifeq ($(SHARED),yes)
176 ifeq ($(LIBEXT),dylib)
177 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
178 else ifeq ($(LIBEXT),so)
179 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
180 endif
181 endif
182
183 ifeq ($(SHARED),yes)
184 install: install-pcilib
185 endif
186
187 install-pcilib: lib/$(PCILIB)
188 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
189 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
190 # DLL library must have executable flag on disk and be placed in same directory as where are EXE files
191 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
192 $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
193 else
194 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
195 endif
196
197 install-lib: $(PCIINC_INS) install-pcilib
198 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
199 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
200 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
201 ifneq ($(PCIIMPLIB),$(PCILIB))
202 $(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
203 endif
204 ifneq ($(PCIIMPDEF),)
205 $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
206 endif
207 ifeq ($(SHARED),yes)
208 ifeq ($(LIBEXT),dylib)
209 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
210 ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
211 else ifeq ($(LIBEXT),so)
212 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
213 ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
214 endif
215 endif
216
217 uninstall: all
218 rm -f $(DESTDIR)$(LSPCIDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/pcilmr$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
219 ifneq ($(IDSDIR),)
220 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
221 else
222 rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
223 endif
224 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/pcilmr.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
225 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
226 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
227 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
228 rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
229 else
230 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
231 endif
232 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
233 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
234 ifneq ($(PCIIMPLIB),$(PCILIB))
235 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
236 endif
237 ifneq ($(PCIIMPDEF),)
238 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
239 endif
240 ifeq ($(SHARED),yes)
241 ifneq ($(LIBEXT),dll)
242 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
243 ifeq ($(LIBEXT),dylib)
244 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
245 else
246 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
247 endif
248 endif
249 endif
250
251 pci.ids.gz: pci.ids
252 gzip -9n <$< >$@
253
254 .PHONY: all clean distclean install install-lib uninstall force tags TAGS