xref: /pciutils/Makefile (revision 3d7466ef)
1# Makefile for The PCI Utilities
2# (c) 1998--2022 Martin Mares <[email protected]>
3
4OPT=-O2
5CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes
6
7VERSION=3.9.0
8DATE=2022-11-20
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
36BINDIR=$(PREFIX)/bin
37SBINDIR=$(PREFIX)/sbin
38SHAREDIR=$(PREFIX)/share
39IDSDIR=$(SHAREDIR)
40MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi)
41INCDIR=$(PREFIX)/include
42LIBDIR=$(PREFIX)/lib
43PKGCFDIR=$(LIBDIR)/pkgconfig
44
45# Commands
46INSTALL=install
47DIRINSTALL=install -d
48ifdef CROSS_COMPILE
49STRIP=--strip-program $(CROSS_COMPILE)-strip
50CC=$(CROSS_COMPILE)gcc
51else
52STRIP=-s
53CC=cc
54endif
55AR=$(CROSS_COMPILE)ar
56RANLIB=$(CROSS_COMPILE)ranlib
57DLLTOOL=$(CROSS_COMPILE)dlltool
58WINDRES=$(CROSS_COMPILE)windres
59
60# Base name of the library (overridden on NetBSD, which has its own libpci)
61LIBNAME=libpci
62
63-include lib/config.mk
64
65PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
66PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
67
68export
69
70all: 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
72lib/$(PCIIMPLIB): $(PCIINC) force
73	$(MAKE) -C lib all
74
75force:
76
77lib/config.h lib/config.mk:
78	cd lib && ./configure
79
80COMMON=common.o
81ifeq ($(COMPAT_GETOPT),yes)
82PCIINC+=compat/getopt.h
83COMMON+=compat/getopt.o
84endif
85
86lspci$(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)
87setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
88
89LSPCIINC=lspci.h pciutils.h $(PCIINC)
90lspci.o: lspci.c $(LSPCIINC)
91ls-vpd.o: ls-vpd.c $(LSPCIINC)
92ls-caps.o: ls-caps.c $(LSPCIINC)
93ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
94ls-kernel.o: ls-kernel.c $(LSPCIINC)
95ls-tree.o: ls-tree.c $(LSPCIINC)
96ls-map.o: ls-map.c $(LSPCIINC)
97
98setpci.o: setpci.c pciutils.h $(PCIINC)
99common.o: common.c pciutils.h $(PCIINC)
100compat/getopt.o: compat/getopt.c
101
102lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
103ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS)
104
105update-pciids: update-pciids.sh
106	sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@"
107	chmod +x $@
108
109# The example of use of libpci
110example$(EXEEXT): example.o lib/$(PCIIMPLIB)
111example.o: example.c $(PCIINC)
112
113%$(EXEEXT): %.o
114	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
115
116ifdef PCI_OS_WINDOWS
117comma := ,
118%-rsrc.rc: lib/winrsrc.rc.in
119	sed <$< >$@ -e 's,@PCILIB_VERSION@,$(PCILIB_VERSION),' \
120		-e 's,@PCILIB_VERSION_WINRC@,$(subst .,\$(comma),$(PCILIB_VERSION).0),' \
121		-e 's,@FILENAME@,$(subst -rsrc.rc,$(EXEEXT),$@),' \
122		-e 's,@DESCRIPTION@,$(subst -rsrc.rc,,$@),' \
123		-e 's,@LIBRARY_BUILD@,0,' \
124		-e 's,@DEBUG_BUILD@,$(if $(findstring -g,$(CFLAGS)),1,0),'
125%-rsrc.o: %-rsrc.rc
126	$(WINDRES) --input=$< --output=$@ --input-format=rc --output-format=coff
127lspci$(EXEEXT): lspci-rsrc.o
128setpci$(EXEEXT): setpci-rsrc.o
129endif
130
131%.8 %.7 %.5: %.man
132	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)#"
133
134ctags:
135	rm -f tags
136	find . -name '*.[hc]' -exec ctags --append {} +
137
138TAGS:
139	rm -f TAGS
140	find . -name '*.[hc]' -exec etags --append {} +
141
142clean:
143	rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
144	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
145	rm -rf maint/dist
146
147distclean: clean
148
149install: all
150# -c is ignored on Linux, but required on FreeBSD
151	$(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
152	$(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
153	$(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
154	$(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
155ifneq ($(IDSDIR),)
156	$(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
157else
158	$(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
159endif
160	$(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
161	$(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
162	$(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
163ifeq ($(SHARED),yes)
164ifeq ($(LIBEXT),dylib)
165	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
166else ifeq ($(LIBEXT),so)
167	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
168endif
169endif
170
171ifeq ($(SHARED),yes)
172install: install-pcilib
173endif
174
175install-pcilib: lib/$(PCILIB)
176	$(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
177ifeq ($(SHARED)_$(LIBEXT),yes_dll)
178# DLL library must have executable flag on disk and be placed in same directory as where are EXE files
179	$(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
180	$(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
181else
182	$(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
183endif
184
185install-lib: $(PCIINC_INS) install-pcilib
186	$(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
187	$(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
188	$(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
189ifneq ($(PCIIMPLIB),$(PCILIB))
190	$(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
191endif
192ifneq ($(PCIIMPDEF),)
193	$(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
194endif
195ifeq ($(SHARED),yes)
196ifeq ($(LIBEXT),dylib)
197	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
198	ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
199else ifeq ($(LIBEXT),so)
200	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
201	ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
202endif
203endif
204
205uninstall: all
206	rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
207ifneq ($(IDSDIR),)
208	rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
209else
210	rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
211endif
212	rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
213	rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
214	rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
215ifeq ($(SHARED)_$(LIBEXT),yes_dll)
216	rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
217else
218	rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
219endif
220	rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
221	rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
222ifneq ($(PCIIMPLIB),$(PCILIB))
223	rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
224endif
225ifneq ($(PCIIMPDEF),)
226	rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
227endif
228ifeq ($(SHARED),yes)
229ifneq ($(LIBEXT),dll)
230	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
231ifeq ($(LIBEXT),dylib)
232	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
233else
234	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
235endif
236endif
237endif
238
239pci.ids.gz: pci.ids
240	gzip -9n <$< >$@
241
242.PHONY: all clean distclean install install-lib uninstall force tags TAGS
243