2 # Configuration script for the PCI library
3 # (c) 1998--2013 Martin Mares <mj@ucw.cz>
12 if [ -z "$VERSION" ] ; then
13 echo >&2 "Please run the configure script from the top-level Makefile"
17 echo_n "Configuring libpci for your system..."
18 if [ -z "$HOST" ] ; then
22 if [ "$sys" = "AIX" -a -x /usr/bin/oslevel -a -x /usr/sbin/lsattr ]
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/_.*//'`
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/'`
30 if [ "$sys" = "DragonFly" ]
34 if [ "$sys" = "GNU/kFreeBSD" ]
42 if [ "$sys" = "CYGWIN_NT-5.1" -o "$sys" = "CYGWIN_NT-6.0" ]
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"
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]'`"
62 echo_n "Looking for access methods..."
66 SYSINCLUDE=/usr/include
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"'
83 i?86|x86_64) echo_n " i386-ports"
84 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
87 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
91 echo_n " mem-ports ecam"
93 i?86) echo_n " i386-ports"
94 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
97 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
98 echo >>$c '#define PCI_HAVE_PM_ECAM'
99 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/xsvc"'
100 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
101 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
104 echo_n " fbsd-device mem-ports ecam"
105 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
106 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
107 echo >>$c '#define PCI_HAVE_PM_ECAM'
108 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
109 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
110 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
111 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
112 if [ "$sys" != "kfreebsd" ] ; then
117 echo_n " obsd-device mem-ports ecam"
118 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
119 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
120 echo >>$c '#define PCI_HAVE_PM_ECAM'
121 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
122 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
123 echo >>$c '#define PCI_PATH_ACPI_MCFG "/var/db/acpi/MCFG.*"'
124 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
126 i386|amd64) echo_n " i386-ports"
127 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
128 echo >>$m 'WITH_LIBS+=-l'$cpu
136 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
137 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
138 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
141 SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include
145 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
146 echo >>$m 'CFLAGS=-g'
147 echo >>$m 'INSTALL=installbsd'
148 echo >>$m 'DIRINSTALL=mkdir -p'
151 echo_n " nbsd-libpci mem-ports ecam"
152 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
153 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
154 echo >>$c '#define PCI_HAVE_PM_ECAM'
155 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
156 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
157 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
158 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
159 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
160 echo >>$m 'LIBNAME=libpciutils'
161 echo >>$m 'WITH_LIBS+=-lpci'
165 echo_n " hurd i386-ports"
166 echo >>$c '#define PCI_HAVE_PM_HURD_CONF'
167 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
170 echo_n " i386-ports mem-ports ecam"
171 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
172 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
173 echo >>$c '#define PCI_HAVE_PM_ECAM'
174 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
175 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
179 echo_n " win32-cfgmgr32 win32-kldbg win32-sysdbg mem-ports ecam"
180 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
181 echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32'
182 echo >>$c '#define PCI_HAVE_PM_WIN32_KLDBG'
183 echo >>$c '#define PCI_HAVE_PM_WIN32_SYSDBG'
184 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
185 echo >>$c '#define PCI_HAVE_PM_ECAM'
186 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "\\\\Device\\\\PhysicalMemory"'
187 echo >>$c '#define PCI_PATH_ACPI_MCFG "GetSystemFirmwareTable()"'
188 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
189 # Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions
190 # also in other import libraries, not only in libcfgmgr32.a.
191 # So always set -lcfgmgr32 as a first library parameter which
192 # instruct linker to prefer symbols from cfgmgr32.dll.
193 echo >>$m 'WITH_LIBS+=-lcfgmgr32'
194 case $cpu in i?86|x86_64)
196 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
197 if [ "$sys" = "cygwin" ] ; then
198 # ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h
199 echo >>$m 'WITH_LIBS+=-lioperm'
200 elif [ "$sys" = "windows" ] ; then
201 # advapi32 is windows system library and used only by lib/i386-io-windows.h
202 echo >>$m 'WITH_LIBS+=-ladvapi32'
209 echo_n " mem-ports ecam"
211 i?86|x86_64) echo_n " i386-ports"
212 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
215 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
216 echo >>$c '#define PCI_HAVE_PM_ECAM'
217 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/misc/mem"'
218 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
219 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
220 if [ "$sys" != "beos" ] ; then
225 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"'
226 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
227 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE'
232 echo_n " aos-expansion"
233 echo >>$c '#define PCI_HAVE_STDINT_H'
234 echo >>$c '#define PCI_HAVE_PM_AOS_EXPANSION'
239 echo " Unfortunately, your OS is not supported by the PCI Library"
244 echo >>$m "LIBEXT="$LIBEXT
245 echo >>$m "EXEEXT="$EXEEXT
246 echo >>$m "LSPCIDIR=\$($LSPCIDIR)"
247 echo >>$c '#define PCI_HAVE_PM_DUMP'
250 echo_n "Checking for zlib support... "
251 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
252 echo "$ZLIB (set manually)"
254 if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then
259 echo "$ZLIB (auto-detected)"
261 if [ "$ZLIB" = yes ] ; then
262 echo >>$c '#define PCI_COMPRESSED_IDS'
263 echo >>$c '#define PCI_IDS "pci.ids.gz"'
265 echo >>$m 'WITH_LIBS+=$(LIBZ)'
267 echo >>$c '#define PCI_IDS "pci.ids"'
269 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
271 echo_n "Checking for DNS support... "
272 if [ "$DNS" = yes -o "$DNS" = no ] ; then
273 echo "$DNS (set manually)"
275 if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then
280 echo "$DNS (auto-detected)"
282 if [ "$DNS" = yes ] ; then
283 echo >>$c "#define PCI_USE_DNS"
284 echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
285 echo >>$m "WITH_LIBS+=$LIBRESOLV"
288 if [ "$sys" = linux ] ; then
289 echo_n "Checking for libkmod... "
291 if [ -z "$PKG_CONFIG" ] ; then
292 PKG_CONFIG=pkg-config
294 if [ "$LIBKMOD" != no ] ; then
295 if ! command -v $PKG_CONFIG >/dev/null ; then
296 echo_n "($PKG_CONFIG not found) "
297 elif $PKG_CONFIG libkmod ; then
301 if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
302 echo "$LIBKMOD (set manually)"
303 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
304 echo "Requested use of libkmod, but it is not available. Giving up."
308 if [ -n "$LIBKMOD_DETECTED" ] ; then
313 echo "$LIBKMOD (auto-detected)"
315 if [ "$LIBKMOD" = yes ] ; then
316 echo >>$c "#define PCI_USE_LIBKMOD"
317 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
318 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
321 echo_n "Checking for udev hwdb support... "
322 if [ "$HWDB" = yes -o "$HWDB" = no ] ; then
323 echo "$HWDB (set manually)"
325 if `command -v $PKG_CONFIG >/dev/null && $PKG_CONFIG --atleast-version=196 libudev` ; then
330 echo "$HWDB (auto-detected)"
332 if [ "$HWDB" = yes ] ; then
333 echo >>$c '#define PCI_HAVE_HWDB'
334 echo >>$m 'LIBUDEV=-ludev'
335 echo >>$m 'WITH_LIBS+=$(LIBUDEV)'
339 echo "Checking whether to build a shared library... $SHARED (set manually)"
340 if [ "$SHARED" = no ] ; then
341 echo >>$m 'PCILIB=$(LIBNAME).a'
342 echo >>$m 'LDLIBS=$(WITH_LIBS)'
343 echo >>$m 'LIB_LDLIBS='
345 if [ "$LIBEXT" = so ]; then
346 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
347 elif [ "$LIBEXT" = dll ]; then
348 echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)'
350 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
352 # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
354 echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
355 echo >>$c '#define PCI_SHARED_LIB'
356 if [ "$LIBEXT" = so ]; then
357 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-soname,$(LIBNAME).$(LIBEXT).$(ABI_VERSION)'
358 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver'
359 elif [ "$LIBEXT" = dylib ]; then
360 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)'
361 elif [ "$LIBEXT" = dll ]; then
362 echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def'
363 # GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21)
364 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols'
367 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
369 if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then
370 echo >>$m 'PCIIMPLIB=$(PCILIB).a'
372 echo >>$m 'PCIIMPLIB=$(PCILIB)'
375 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
376 echo >>$c "#define PCILIB_DATE_AMIGAOS \"`echo $DATE | sed 's/\(....\)-\(..\)-\(..\)/\3.\2.\1/'`\""
377 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m