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