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