xref: /pciutils/Makefile (revision d0130eb3)
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.8.0
8DATE=2022-04-18
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
56
57# Base name of the library (overridden on NetBSD, which has its own libpci)
58LIBNAME=libpci
59
60-include lib/config.mk
61
62PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
63PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
64
65export
66
67all: lib/$(PCIIMPLIB) lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS)
68
69lib/$(PCIIMPLIB): $(PCIINC) force
70	$(MAKE) -C lib all
71
72force:
73
74lib/config.h lib/config.mk:
75	cd lib && ./configure
76
77COMMON=common.o
78ifeq ($(COMPAT_GETOPT),yes)
79PCIINC+=compat/getopt.h
80COMMON+=compat/getopt.o
81endif
82
83lspci$(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)
84setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
85
86LSPCIINC=lspci.h pciutils.h $(PCIINC)
87lspci.o: lspci.c $(LSPCIINC)
88ls-vpd.o: ls-vpd.c $(LSPCIINC)
89ls-caps.o: ls-caps.c $(LSPCIINC)
90ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
91ls-kernel.o: ls-kernel.c $(LSPCIINC)
92ls-tree.o: ls-tree.c $(LSPCIINC)
93ls-map.o: ls-map.c $(LSPCIINC)
94
95setpci.o: setpci.c pciutils.h $(PCIINC)
96common.o: common.c pciutils.h $(PCIINC)
97compat/getopt.o: compat/getopt.c
98
99lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
100ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS)
101
102update-pciids: update-pciids.sh
103	sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@"
104	chmod +x $@
105
106# The example of use of libpci
107example$(EXEEXT): example.o lib/$(PCIIMPLIB)
108example.o: example.c $(PCIINC)
109
110%$(EXEEXT): %.o
111	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
112
113%.8 %.7 %.5: %.man
114	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)#"
115
116ctags:
117	rm -f tags
118	find . -name '*.[hc]' -exec ctags --append {} +
119
120TAGS:
121	rm -f TAGS
122	find . -name '*.[hc]' -exec etags --append {} +
123
124clean:
125	rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
126	rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags
127	rm -rf maint/dist
128
129distclean: clean
130
131install: all
132# -c is ignored on Linux, but required on FreeBSD
133	$(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
134	$(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
135	$(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
136	$(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
137ifneq ($(IDSDIR),)
138	$(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
139else
140	$(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
141endif
142	$(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
143	$(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
144	$(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
145ifeq ($(SHARED),yes)
146ifeq ($(LIBEXT),dylib)
147	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
148else
149	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
150endif
151endif
152
153ifeq ($(SHARED),yes)
154install: install-pcilib
155endif
156
157install-pcilib: lib/$(PCILIB)
158	$(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
159	$(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
160
161install-lib: $(PCIINC_INS) install-pcilib
162	$(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
163	$(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
164	$(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
165ifneq ($(PCIIMPLIB),$(PCILIB))
166	$(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
167endif
168ifeq ($(SHARED),yes)
169ifeq ($(LIBEXT),dylib)
170	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
171	ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
172else
173	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
174	ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
175endif
176endif
177
178uninstall: all
179	rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
180ifneq ($(IDSDIR),)
181	rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
182else
183	rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
184endif
185	rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
186	rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
187	rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
188	rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
189	rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
190	rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
191ifneq ($(PCIIMPLIB),$(PCILIB))
192	rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
193endif
194ifeq ($(SHARED),yes)
195	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
196ifeq ($(LIBEXT),dylib)
197	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
198else
199	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
200endif
201endif
202
203pci.ids.gz: pci.ids
204	gzip -9n <$< >$@
205
206.PHONY: all clean distclean install install-lib uninstall force tags TAGS
207