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