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