]> git.ipfire.org Git - thirdparty/pciutils.git/blob - Makefile
Makefile: Additions to CFLAGS require an override
[thirdparty/pciutils.git] / Makefile
1 # Makefile for The PCI Utilities
2 # (c) 1998--2023 Martin Mares <mj@ucw.cz>
3
4 OPT=-O2
5 CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes
6
7 VERSION=3.10.0
8 DATE=2023-05-01
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 ID's 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 lib/bitops.h
66 PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h
67
68 LMR=margin_hw.o margin.o margin_log.o margin_results.o
69 LMROBJS=$(addprefix lmr/,$(LMR))
70 LMRINC=lmr/lmr.h
71
72 export
73
74 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 pcilmr.8
75
76 lib/$(PCIIMPLIB): $(PCIINC) force
77 $(MAKE) -C lib all
78
79 force:
80
81 lib/config.h lib/config.mk:
82 cd lib && ./configure
83
84 COMMON=common.o
85 ifeq ($(COMPAT_GETOPT),yes)
86 PCIINC+=compat/getopt.h
87 COMMON+=compat/getopt.o
88 endif
89
90 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)
91 setpci$(EXEEXT): setpci.o $(COMMON) lib/$(PCIIMPLIB)
92
93 LSPCIINC=lspci.h pciutils.h $(PCIINC)
94 lspci.o: lspci.c $(LSPCIINC)
95 ls-vpd.o: ls-vpd.c $(LSPCIINC)
96 ls-caps.o: ls-caps.c $(LSPCIINC)
97 ls-ecaps.o: ls-ecaps.c $(LSPCIINC)
98 ls-kernel.o: ls-kernel.c $(LSPCIINC)
99 ls-tree.o: ls-tree.c $(LSPCIINC)
100 ls-map.o: ls-map.c $(LSPCIINC)
101
102 setpci.o: setpci.c pciutils.h $(PCIINC)
103 common.o: common.c pciutils.h $(PCIINC)
104 compat/getopt.o: compat/getopt.c
105
106 lspci$(EXEEXT): LDLIBS+=$(LIBKMOD_LIBS)
107 ls-kernel.o: override CFLAGS+=$(LIBKMOD_CFLAGS)
108
109 update-pciids: update-pciids.sh
110 sed <$< >$@ "s@^DEST=.*@DEST=$(if $(IDSDIR),$(IDSDIR)/,)$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@;s@VERSION=.*@VERSION=$(VERSION)@"
111 chmod +x $@
112
113 # The example of use of libpci
114 example$(EXEEXT): example.o lib/$(PCIIMPLIB)
115 example.o: example.c $(PCIINC)
116
117 $(LMROBJS) pcilmr.o: override CFLAGS+=-I .
118 $(LMROBJS): %.o: %.c $(LMRINC) $(PCIINC) pciutils.h
119
120 pcilmr: pcilmr.o $(LMROBJS) $(COMMON) lib/$(PCIIMPLIB)
121 pcilmr.o: pcilmr.c $(LMRINC) $(PCIINC) pciutils.h
122
123 %$(EXEEXT): %.o
124 $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
125
126 ifdef PCI_OS_WINDOWS
127 comma := ,
128 %-rsrc.rc: lib/winrsrc.rc.in
129 sed <$< >$@ -e 's,@PCILIB_VERSION@,$(PCILIB_VERSION),' \
130 -e 's,@PCILIB_VERSION_WINRC@,$(subst .,\$(comma),$(PCILIB_VERSION).0),' \
131 -e 's,@FILENAME@,$(subst -rsrc.rc,$(EXEEXT),$@),' \
132 -e 's,@DESCRIPTION@,$(subst -rsrc.rc,,$@),' \
133 -e 's,@LIBRARY_BUILD@,0,' \
134 -e 's,@DEBUG_BUILD@,$(if $(findstring -g,$(CFLAGS)),1,0),'
135 %-rsrc.o: %-rsrc.rc
136 $(WINDRES) --input=$< --output=$@ --input-format=rc --output-format=coff
137 lspci$(EXEEXT): lspci-rsrc.o
138 setpci$(EXEEXT): setpci-rsrc.o
139 endif
140
141 %.8 %.7 %.5: %.man
142 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)#"
143
144 ctags:
145 rm -f tags
146 find . -name '*.[hc]' -exec ctags --append {} +
147
148 TAGS:
149 rm -f TAGS
150 find . -name '*.[hc]' -exec etags --append {} +
151
152 clean:
153 rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
154 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
155 rm -rf maint/dist
156
157 distclean: clean
158
159 install: all
160 # -c is ignored on Linux, but required on FreeBSD
161 $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)$(MANDIR)/man5
162 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR)
163 $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)
164 $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR)
165 ifneq ($(IDSDIR),)
166 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR)
167 else
168 $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(SBINDIR)
169 endif
170 $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8
171 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7
172 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5
173 ifeq ($(SHARED),yes)
174 ifeq ($(LIBEXT),dylib)
175 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
176 else ifeq ($(LIBEXT),so)
177 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
178 endif
179 endif
180
181 ifeq ($(SHARED),yes)
182 install: install-pcilib
183 endif
184
185 install-pcilib: lib/$(PCILIB)
186 $(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
187 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
188 # DLL library must have executable flag on disk and be placed in same directory as where are EXE files
189 $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
190 $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
191 else
192 $(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
193 endif
194
195 install-lib: $(PCIINC_INS) install-pcilib
196 $(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
197 $(INSTALL) -c -m 644 $(PCIINC_INS) $(DESTDIR)$(INCDIR)/pci
198 $(INSTALL) -c -m 644 lib/$(PCILIBPC) $(DESTDIR)$(PKGCFDIR)
199 ifneq ($(PCIIMPLIB),$(PCILIB))
200 $(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
201 endif
202 ifneq ($(PCIIMPDEF),)
203 $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
204 endif
205 ifeq ($(SHARED),yes)
206 ifeq ($(LIBEXT),dylib)
207 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
208 ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
209 else ifeq ($(LIBEXT),so)
210 ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
211 ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
212 endif
213 endif
214
215 uninstall: all
216 rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids
217 ifneq ($(IDSDIR),)
218 rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS)
219 else
220 rm -f $(DESTDIR)$(SBINDIR)/$(PCI_IDS)
221 endif
222 rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
223 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
224 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
225 ifeq ($(SHARED)_$(LIBEXT),yes_dll)
226 rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
227 else
228 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
229 endif
230 rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
231 rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
232 ifneq ($(PCIIMPLIB),$(PCILIB))
233 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
234 endif
235 ifneq ($(PCIIMPDEF),)
236 rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
237 endif
238 ifeq ($(SHARED),yes)
239 ifneq ($(LIBEXT),dll)
240 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
241 ifeq ($(LIBEXT),dylib)
242 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
243 else
244 rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
245 endif
246 endif
247 endif
248
249 pci.ids.gz: pci.ids
250 gzip -9n <$< >$@
251
252 .PHONY: all clean distclean install install-lib uninstall force tags TAGS