xref: /pciutils/Makefile (revision 2a7d585d)
1# Makefile for The PCI Utilities
2# (c) 1998--2020 Martin Mares <[email protected]>
3
4OPT=-O2
5CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes
6
7VERSION=3.7.0
8DATE=2020-05-31
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
36SBINDIR=$(PREFIX)/sbin
37SHAREDIR=$(PREFIX)/share
38IDSDIR=$(SHAREDIR)
39MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi)
40INCDIR=$(PREFIX)/include
41LIBDIR=$(PREFIX)/lib
42PKGCFDIR=$(LIBDIR)/pkgconfig
43
44# Commands
45INSTALL=install
46DIRINSTALL=install -d
47STRIP=-s
48CC=$(CROSS_COMPILE)gcc
49AR=$(CROSS_COMPILE)ar
50RANLIB=$(CROSS_COMPILE)ranlib
51
52# Base name of the library (overridden on NetBSD, which has its own libpci)
53LIBNAME=libpci
54
55-include lib/config.mk
56
57PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
58PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
59
60export
61
62all: lib/$(PCILIB) lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS)
63
64lib/$(PCILIB): $(PCIINC) force
65	$(MAKE) -C lib all
66
67force:
68
69lib/config.h lib/config.mk:
70	cd lib && ./configure
71
72COMMON=common.o
73ifeq ($(COMPAT_GETOPT),yes)
74COMMON+=compat/getopt.o
75endif
76
77lspci$(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/$(PCILIB)
78setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCILIB)
79
80LSPCIINC=lspci.h pciutils.h $(PCIINC)
81lspci.o: lspci.c $(LSPCIINC)
82ls-vpd.o: ls-vpd.c $(LSPCIINC)
83ls-caps.o: ls-caps.c $(LSPCIINC)
84ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
85ls-kernel.o: ls-kernel.c $(LSPCIINC)
86ls-tree.o: ls-tree.c $(LSPCIINC)
87ls-map.o: ls-map.c $(LSPCIINC)
88
89setpci.o: setpci.c pciutils.h $(PCIINC)
90common.o: common.c pciutils.h $(PCIINC)
91compat/getopt.o: compat/getopt.c
92
93lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
94ls-kernel.o: CFLAGS+=$(LIBKMOD_CFLAGS)
95
96update-pciids: update-pciids.sh
97	sed <$< >$@ "s@^DEST=.*@DEST=$(IDSDIR)/$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@"
98	chmod +x $@
99
100# The example of use of libpci
101example$(EXEEXT): example.o lib/$(PCILIB)
102example.o: example.c $(PCIINC)
103
104%$(EXEEXT): %.o
105	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
106
107%.8 %.7 %.5: %.man
108	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)#"
109
110ctags:
111	rm -f tags
112	find . -name '*.[hc]' -exec ctags --append {} +
113
114TAGS:
115	rm -f TAGS
116	find . -name '*.[hc]' -exec etags --append {} +
117
118clean:
119	rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
120	rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags
121	rm -rf maint/dist
122
123distclean: clean
124
125install: all
126# -c is ignored on Linux, but required on FreeBSD
127	$(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)/$(MANDIR)/man5
128	$(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
129	$(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
130	$(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
131	$(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
132	$(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
133	$(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
134ifeq ($(SHARED),yes)
135ifeq ($(LIBEXT),dylib)
136	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT)
137else
138	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION)
139endif
140endif
141
142ifeq ($(SHARED),yes)
143install: install-pcilib
144endif
145
146install-pcilib: lib/$(PCILIB)
147	$(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
148	$(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
149
150install-lib: $(PCIINC_INS) install-pcilib
151	$(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
152	$(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
153	$(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
154ifeq ($(SHARED),yes)
155ifeq ($(LIBEXT),dylib)
156	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT)
157	ln -sf $(LIBNAME)$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
158else
159	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION)
160	ln -sf $(LIBNAME).$(LIBEXT)$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
161endif
162endif
163
164uninstall: all
165	rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
166	rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
167	rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
168	rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
169	rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
170	rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
171	rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
172	rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
173ifeq ($(SHARED),yes)
174	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
175ifeq ($(LIBEXT),dylib)
176	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME)$(ABI_VERSION).$(LIBEXT)
177else
178	rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)$(ABI_VERSION)
179endif
180endif
181
182pci.ids.gz: pci.ids
183	gzip -9n <$< >$@
184
185.PHONY: all clean distclean install install-lib uninstall force tags TAGS
186