1#!/bin/sh 2# Configuration script for the PCI library 3# (c) 1998--2013 Martin Mares <[email protected]> 4 5LC_ALL=C 6export LC_ALL 7 8echo_n() { 9 printf '%s' "$*" 10} 11 12if [ -z "$VERSION" ] ; then 13 echo >&2 "Please run the configure script from the top-level Makefile" 14 exit 1 15fi 16 17echo_n "Configuring libpci for your system..." 18if [ -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} 47fi 48[ -n "$RELEASE" ] && rel="${RELEASE}" 49# CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless. 50host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\2/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'` 51cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` 52sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` 53echo " $host $rel $cpu $sys" 54 55c=config.h 56m=config.mk 57echo >$c '#define PCI_CONFIG_H' 58echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`" 59echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`" 60echo >$m 'WITH_LIBS=' 61 62echo_n "Looking for access methods..." 63LIBRESOLV=-lresolv 64LIBEXT=so 65EXEEXT= 66SYSINCLUDE=/usr/include 67LSPCIDIR=SBINDIR 68 69case $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 case $cpu in 125 i386|amd64) echo_n " i386-ports" 126 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 127 echo >>$m 'WITH_LIBS+=-l'$cpu 128 ;; 129 esac 130 LIBRESOLV= 131 ;; 132 133 darwin*) 134 echo_n " darwin" 135 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE' 136 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit' 137 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 138 LIBRESOLV= 139 LIBEXT=dylib 140 SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include 141 ;; 142 aix) 143 echo_n " aix-device" 144 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE' 145 echo >>$m 'CFLAGS=-g' 146 echo >>$m 'INSTALL=installbsd' 147 echo >>$m 'DIRINSTALL=mkdir -p' 148 ;; 149 netbsd) 150 echo_n " nbsd-libpci mem-ports ecam" 151 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI' 152 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF' 153 echo >>$c '#define PCI_HAVE_PM_ECAM' 154 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"' 155 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"' 156 echo >>$c '#define PCI_PATH_ACPI_MCFG ""' 157 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""' 158 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 159 echo >>$m 'LIBNAME=libpciutils' 160 echo >>$m 'WITH_LIBS+=-lpci' 161 LIBRESOLV= 162 ;; 163 gnu) 164 echo_n " hurd i386-ports" 165 echo >>$c '#define PCI_HAVE_PM_HURD_CONF' 166 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 167 ;; 168 djgpp) 169 echo_n " i386-ports" 170 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 171 EXEEXT=.exe 172 ;; 173 cygwin|windows) 174 echo_n " win32-cfgmgr32 win32-kldbg win32-sysdbg" 175 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 176 echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32' 177 echo >>$c '#define PCI_HAVE_PM_WIN32_KLDBG' 178 echo >>$c '#define PCI_HAVE_PM_WIN32_SYSDBG' 179 # Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions 180 # also in other import libraries, not only in libcfgmgr32.a. 181 # So always set -lcfgmgr32 as a first library parameter which 182 # instruct linker to prefer symbols from cfgmgr32.dll. 183 echo >>$m 'WITH_LIBS+=-lcfgmgr32' 184 case $cpu in i?86|x86_64) 185 echo_n " i386-ports" 186 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 187 if [ "$sys" = "cygwin" ] ; then 188 # ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h 189 echo >>$m 'WITH_LIBS+=-lioperm' 190 elif [ "$sys" = "windows" ] ; then 191 # advapi32 is windows system library and used only by lib/i386-io-windows.h 192 echo >>$m 'WITH_LIBS+=-ladvapi32' 193 fi 194 ;; esac 195 EXEEXT=.exe 196 LIBEXT=dll 197 ;; 198 beos|haiku) 199 case $cpu in 200 i?86|x86_64) echo_n " i386-ports" 201 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 202 ;; 203 esac 204 echo >>$c '#define PCI_HAVE_STDINT_H' 205 ;; 206 sylixos) 207 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"' 208 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 209 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE' 210 IDSDIR="/etc/pci" 211 LIBRESOLV= 212 ;; 213 *) 214 echo " Unfortunately, your OS is not supported by the PCI Library" 215 exit 1 216 ;; 217esac 218 219echo >>$m "LIBEXT="$LIBEXT 220echo >>$m "EXEEXT="$EXEEXT 221echo >>$m "LSPCIDIR=\$($LSPCIDIR)" 222echo >>$c '#define PCI_HAVE_PM_DUMP' 223echo " dump" 224 225echo_n "Checking for zlib support... " 226if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then 227 echo "$ZLIB (set manually)" 228else 229 if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then 230 ZLIB=yes 231 else 232 ZLIB=no 233 fi 234 echo "$ZLIB (auto-detected)" 235fi 236if [ "$ZLIB" = yes ] ; then 237 echo >>$c '#define PCI_COMPRESSED_IDS' 238 echo >>$c '#define PCI_IDS "pci.ids.gz"' 239 echo >>$m 'LIBZ=-lz' 240 echo >>$m 'WITH_LIBS+=$(LIBZ)' 241else 242 echo >>$c '#define PCI_IDS "pci.ids"' 243fi 244echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\"" 245 246echo_n "Checking for DNS support... " 247if [ "$DNS" = yes -o "$DNS" = no ] ; then 248 echo "$DNS (set manually)" 249else 250 if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then 251 DNS=yes 252 else 253 DNS=no 254 fi 255 echo "$DNS (auto-detected)" 256fi 257if [ "$DNS" = yes ] ; then 258 echo >>$c "#define PCI_USE_DNS" 259 echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\"" 260 echo >>$m "WITH_LIBS+=$LIBRESOLV" 261fi 262 263if [ "$sys" = linux ] ; then 264 echo_n "Checking for libkmod... " 265 LIBKMOD_DETECTED= 266 if [ -z "$PKG_CONFIG" ] ; then 267 PKG_CONFIG=pkg-config 268 fi 269 if [ "$LIBKMOD" != no ] ; then 270 if ! command -v $PKG_CONFIG >/dev/null ; then 271 echo_n "($PKG_CONFIG not found) " 272 elif $PKG_CONFIG libkmod ; then 273 LIBKMOD_DETECTED=1 274 fi 275 fi 276 if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then 277 echo "$LIBKMOD (set manually)" 278 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then 279 echo "Requested use of libkmod, but it is not available. Giving up." 280 exit 1 281 fi 282 else 283 if [ -n "$LIBKMOD_DETECTED" ] ; then 284 LIBKMOD=yes 285 else 286 LIBKMOD=no 287 fi 288 echo "$LIBKMOD (auto-detected)" 289 fi 290 if [ "$LIBKMOD" = yes ] ; then 291 echo >>$c "#define PCI_USE_LIBKMOD" 292 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)" 293 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)" 294 fi 295 296 echo_n "Checking for udev hwdb support... " 297 if [ "$HWDB" = yes -o "$HWDB" = no ] ; then 298 echo "$HWDB (set manually)" 299 else 300 if `command -v $PKG_CONFIG >/dev/null && $PKG_CONFIG --atleast-version=196 libudev` ; then 301 HWDB=yes 302 else 303 HWDB=no 304 fi 305 echo "$HWDB (auto-detected)" 306 fi 307 if [ "$HWDB" = yes ] ; then 308 echo >>$c '#define PCI_HAVE_HWDB' 309 echo >>$m 'LIBUDEV=-ludev' 310 echo >>$m 'WITH_LIBS+=$(LIBUDEV)' 311 fi 312fi 313 314echo "Checking whether to build a shared library... $SHARED (set manually)" 315if [ "$SHARED" = no ] ; then 316 echo >>$m 'PCILIB=$(LIBNAME).a' 317 echo >>$m 'LDLIBS=$(WITH_LIBS)' 318 echo >>$m 'LIB_LDLIBS=' 319else 320 if [ "$LIBEXT" = so ]; then 321 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)' 322 elif [ "$LIBEXT" = dll ]; then 323 echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)' 324 else 325 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)' 326 fi 327 # We link the dependencies _to_ the library, so we do not need explicit deps in .pc 328 echo >>$m 'LDLIBS=' 329 echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)' 330 echo >>$c '#define PCI_SHARED_LIB' 331 if [ "$LIBEXT" = so ]; then 332 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-soname,$(LIBNAME).$(LIBEXT).$(ABI_VERSION)' 333 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver' 334 elif [ "$LIBEXT" = dylib ]; then 335 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)' 336 elif [ "$LIBEXT" = dll ]; then 337 echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def' 338 # GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21) 339 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols' 340 fi 341fi 342echo >>$m 'PCILIBPC=$(LIBNAME).pc' 343 344if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then 345 echo >>$m 'PCIIMPLIB=$(PCILIB).a' 346else 347 echo >>$m 'PCIIMPLIB=$(PCILIB)' 348fi 349 350echo >>$c "#define PCILIB_VERSION \"$VERSION\"" 351sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m 352