]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
lspci: Decode PCIe DevCtl2 ID-Based Ordering Enables
[pciutils.git] / lib / configure
1 #!/bin/sh
2 # Configuration script for the PCI library
3 # (c) 1998--2013 Martin Mares <mj@ucw.cz>
4
5 LC_ALL=C
6 export LC_ALL
7
8 echo_n() {
9         printf '%s' "$*"
10 }
11
12 if [ -z "$VERSION" ] ; then
13         echo >&2 "Please run the configure script from the top-level Makefile"
14         exit 1
15 fi
16
17 echo_n "Configuring libpci for your system..."
18 if [ -z "$HOST" ] ; then
19         sys=`uname -s`
20         rel=`uname -r`
21         realsys="$sys"
22         if [ "$sys" = "AIX" -a -x /usr/bin/oslevel -a -x /usr/sbin/lsattr ]
23         then
24                 rel=`/usr/bin/oslevel`
25                 proc=`/usr/sbin/lsdev -C -c processor -S available -F name | head -1`
26                 cpu=`/usr/sbin/lsattr -F value -l $proc -a type | sed 's/_.*//'`
27         else
28                 cpu=`uname -m | sed 's/^i.86-AT386/i386/;s/^i.86$/i386/;s/^sun4u$/sparc64/;s/^i86pc$/i386/;s/^BePC$/i386/;s/^BeMac$/powerpc/;s/^BeBox$/powerpc/'`
29         fi
30         if [ "$sys" = "DragonFly" ]
31         then
32                 sys=freebsd
33         fi
34         if [ "$sys" = "GNU/kFreeBSD" ]
35         then
36                 sys=kfreebsd
37         fi
38         if [ "$sys" = "GNU" ]
39         then
40                 sys=gnu
41         fi
42         if [ "$sys" = "CYGWIN_NT-5.1" -o "$sys" = "CYGWIN_NT-6.0" ]
43         then
44                 sys=cygwin
45         fi
46         HOST=${3:-$cpu-$sys}
47 fi
48 [ -n "$RELEASE" ] && rel="${RELEASE}"
49 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
50 host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\2/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
51 cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
52 sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
53 echo " $host $rel $cpu $sys"
54
55 c=config.h
56 m=config.mk
57 echo >$c '#define PCI_CONFIG_H'
58 echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
59 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
60 echo >$m 'WITH_LIBS='
61
62 echo_n "Looking for access methods..."
63 LIBRESOLV=-lresolv
64 LIBEXT=so
65 EXEEXT=
66 SYSINCLUDE=/usr/include
67 LSPCIDIR=SBINDIR
68
69 case $sys in
70         linux*)
71                 echo_n " sysfs proc mem-ports ecam"
72                 echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS'
73                 echo >>$c '#define PCI_HAVE_PM_LINUX_PROC'
74                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
75                 echo >>$c '#define PCI_HAVE_PM_ECAM'
76                 echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H'
77                 echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"'
78                 echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"'
79                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
80                 echo >>$c '#define PCI_PATH_ACPI_MCFG "/sys/firmware/acpi/tables/MCFG"'
81                 echo >>$c '#define PCI_PATH_EFI_SYSTAB "/sys/firmware/efi/systab"'
82                 case $cpu in
83                                 i?86|x86_64)    echo_n " i386-ports"
84                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
85                                                 ;;
86                 esac
87                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
88                 LSPCIDIR=BINDIR
89                 ;;
90         sunos)
91                 case $cpu in
92                                 i?86)           echo_n " i386-ports"
93                                                 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
94                                                 ;;
95                                 *)
96                                                 echo " The PCI library does not support Solaris for this architecture: $cpu"
97                                                 exit 1
98                                                 ;;
99                 esac
100                 echo >>$c '#define PCI_HAVE_STDINT_H'
101                 ;;
102         freebsd*|kfreebsd*)
103                 echo_n " fbsd-device mem-ports ecam"
104                 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
105                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
106                 echo >>$c '#define PCI_HAVE_PM_ECAM'
107                 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
108                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
109                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
110                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
111                 if [ "$sys" != "kfreebsd" ] ; then
112                         LIBRESOLV=
113                 fi
114                 ;;
115         openbsd)
116                 echo_n " obsd-device mem-ports ecam"
117                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
118                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
119                 echo >>$c '#define PCI_HAVE_PM_ECAM'
120                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
121                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
122                 echo >>$c '#define PCI_PATH_ACPI_MCFG "/var/db/acpi/MCFG.*"'
123                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
124                 LIBRESOLV=
125                 ;;
126
127         darwin*)
128                 echo_n " darwin"
129                 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
130                 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
131                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
132                 LIBRESOLV=
133                 LIBEXT=dylib
134                 SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include
135                 ;;
136         aix)
137                 echo_n " aix-device"
138                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
139                 echo >>$m 'CFLAGS=-g'
140                 echo >>$m 'INSTALL=installbsd'
141                 echo >>$m 'DIRINSTALL=mkdir -p'
142                 ;;
143         netbsd)
144                 echo_n " nbsd-libpci mem-ports ecam"
145                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
146                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
147                 echo >>$c '#define PCI_HAVE_PM_ECAM'
148                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
149                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
150                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
151                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
152                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
153                 echo >>$m 'LIBNAME=libpciutils'
154                 echo >>$m 'WITH_LIBS+=-lpci'
155                 LIBRESOLV=
156                 ;;
157         gnu)
158                 echo_n " hurd i386-ports"
159                 echo >>$c '#define PCI_HAVE_PM_HURD_CONF'
160                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
161                 ;;
162         djgpp)
163                 echo_n " i386-ports"
164                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
165                 EXEEXT=.exe
166                 ;;
167         cygwin|windows)
168                 echo_n " win32-cfgmgr32 win32-kldbg win32-sysdbg"
169                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
170                 echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32'
171                 echo >>$c '#define PCI_HAVE_PM_WIN32_KLDBG'
172                 echo >>$c '#define PCI_HAVE_PM_WIN32_SYSDBG'
173                 # Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions
174                 # also in other import libraries, not only in libcfgmgr32.a.
175                 # So always set -lcfgmgr32 as a first library parameter which
176                 # instruct linker to prefer symbols from cfgmgr32.dll.
177                 echo >>$m 'WITH_LIBS+=-lcfgmgr32'
178                 case $cpu in i?86|x86_64)
179                 echo_n " i386-ports"
180                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
181                 if [ "$sys" = "cygwin" ] ; then
182                         # ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h
183                         echo >>$m 'WITH_LIBS+=-lioperm'
184                 elif [ "$sys" = "windows" ] ; then
185                         # advapi32 is windows system library and used only by lib/i386-io-windows.h
186                         echo >>$m 'WITH_LIBS+=-ladvapi32'
187                 fi
188                 ;; esac
189                 EXEEXT=.exe
190                 LIBEXT=dll
191                 ;;
192         beos|haiku)
193                 case $cpu in
194                                 i?86|x86_64)    echo_n " i386-ports"
195                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
196                                                 ;;
197                 esac
198                 echo >>$c '#define PCI_HAVE_STDINT_H'
199                 ;;
200         sylixos)
201                 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"'
202                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
203                 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE'
204                 IDSDIR="/etc/pci"
205                 LIBRESOLV=
206                 ;;
207         *)
208                 echo " Unfortunately, your OS is not supported by the PCI Library"
209                 exit 1
210                 ;;
211 esac
212
213 echo >>$m "LIBEXT="$LIBEXT
214 echo >>$m "EXEEXT="$EXEEXT
215 echo >>$m "LSPCIDIR=\$($LSPCIDIR)"
216 echo >>$c '#define PCI_HAVE_PM_DUMP'
217 echo " dump"
218
219 echo_n "Checking for zlib support... "
220 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
221         echo "$ZLIB (set manually)"
222 else
223         if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then
224                 ZLIB=yes
225         else
226                 ZLIB=no
227         fi
228         echo "$ZLIB (auto-detected)"
229 fi
230 if [ "$ZLIB" = yes ] ; then
231         echo >>$c '#define PCI_COMPRESSED_IDS'
232         echo >>$c '#define PCI_IDS "pci.ids.gz"'
233         echo >>$m 'LIBZ=-lz'
234         echo >>$m 'WITH_LIBS+=$(LIBZ)'
235 else
236         echo >>$c '#define PCI_IDS "pci.ids"'
237 fi
238 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
239
240 echo_n "Checking for DNS support... "
241 if [ "$DNS" = yes -o "$DNS" = no ] ; then
242         echo "$DNS (set manually)"
243 else
244         if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then
245                 DNS=yes
246         else
247                 DNS=no
248         fi
249         echo "$DNS (auto-detected)"
250 fi
251 if [ "$DNS" = yes ] ; then
252         echo >>$c "#define PCI_USE_DNS"
253         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
254         echo >>$m "WITH_LIBS+=$LIBRESOLV"
255 fi
256
257 if [ "$sys" = linux ] ; then
258         echo_n "Checking for libkmod... "
259         LIBKMOD_DETECTED=
260         if [ -z "$PKG_CONFIG" ] ; then
261                 PKG_CONFIG=pkg-config
262         fi
263         if [ "$LIBKMOD" != no ] ; then
264                 if ! command -v $PKG_CONFIG >/dev/null ; then
265                         echo_n "($PKG_CONFIG not found) "
266                 elif $PKG_CONFIG libkmod ; then
267                         LIBKMOD_DETECTED=1
268                 fi
269         fi
270         if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
271                 echo "$LIBKMOD (set manually)"
272                 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
273                         echo "Requested use of libkmod, but it is not available. Giving up."
274                         exit 1
275                 fi
276         else
277                 if [ -n "$LIBKMOD_DETECTED" ] ; then
278                         LIBKMOD=yes
279                 else
280                         LIBKMOD=no
281                 fi
282                 echo "$LIBKMOD (auto-detected)"
283         fi
284         if [ "$LIBKMOD" = yes ] ; then
285                 echo >>$c "#define PCI_USE_LIBKMOD"
286                 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
287                 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
288         fi
289
290         echo_n "Checking for udev hwdb support... "
291         if [ "$HWDB" = yes -o "$HWDB" = no ] ; then
292                 echo "$HWDB (set manually)"
293         else
294                 if `command -v $PKG_CONFIG >/dev/null && $PKG_CONFIG --atleast-version=196 libudev` ; then
295                         HWDB=yes
296                 else
297                         HWDB=no
298                 fi
299                 echo "$HWDB (auto-detected)"
300         fi
301         if [ "$HWDB" = yes ] ; then
302                 echo >>$c '#define PCI_HAVE_HWDB'
303                 echo >>$m 'LIBUDEV=-ludev'
304                 echo >>$m 'WITH_LIBS+=$(LIBUDEV)'
305         fi
306 fi
307
308 echo "Checking whether to build a shared library... $SHARED (set manually)"
309 if [ "$SHARED" = no ] ; then
310         echo >>$m 'PCILIB=$(LIBNAME).a'
311         echo >>$m 'LDLIBS=$(WITH_LIBS)'
312         echo >>$m 'LIB_LDLIBS='
313 else
314         if [ "$LIBEXT" = so ]; then
315                 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
316         elif [ "$LIBEXT" = dll ]; then
317                 echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)'
318         else
319                 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
320         fi
321         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
322         echo >>$m 'LDLIBS='
323         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
324         echo >>$c '#define PCI_SHARED_LIB'
325         if [ "$LIBEXT" = so ]; then
326                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-soname,$(LIBNAME).$(LIBEXT).$(ABI_VERSION)'
327                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver'
328         elif [ "$LIBEXT" = dylib ]; then
329                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)'
330         elif [ "$LIBEXT" = dll ]; then
331                 echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def'
332                 # GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21)
333                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols'
334         fi
335 fi
336 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
337
338 if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then
339         echo >>$m 'PCIIMPLIB=$(PCILIB).a'
340 else
341         echo >>$m 'PCIIMPLIB=$(PCILIB)'
342 fi
343
344 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
345 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m