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" 72 echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS' 73 echo >>$c '#define PCI_HAVE_PM_LINUX_PROC' 74 echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H' 75 echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"' 76 echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"' 77 case $cpu in 78 i?86|x86_64) echo_n " i386-ports" 79 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 80 ;; 81 esac 82 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 83 LSPCIDIR=BINDIR 84 ;; 85 sunos) 86 case $cpu in 87 i?86) echo_n " i386-ports" 88 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF" 89 ;; 90 *) 91 echo " The PCI library does not support Solaris for this architecture: $cpu" 92 exit 1 93 ;; 94 esac 95 echo >>$c '#define PCI_HAVE_STDINT_H' 96 ;; 97 freebsd*|kfreebsd*) 98 echo_n " fbsd-device" 99 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE' 100 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"' 101 if [ "$sys" != "kfreebsd" ] ; then 102 LIBRESOLV= 103 fi 104 ;; 105 openbsd) 106 echo_n " obsd-device" 107 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE' 108 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"' 109 LIBRESOLV= 110 ;; 111 112 darwin*) 113 echo_n " darwin" 114 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE' 115 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit' 116 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 117 LIBRESOLV= 118 LIBEXT=dylib 119 SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include 120 ;; 121 aix) 122 echo_n " aix-device" 123 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE' 124 echo >>$m 'CFLAGS=-g' 125 echo >>$m 'INSTALL=installbsd' 126 echo >>$m 'DIRINSTALL=mkdir -p' 127 ;; 128 netbsd) 129 echo_n " nbsd-libpci" 130 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI' 131 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"' 132 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 133 echo >>$m 'LIBNAME=libpciutils' 134 echo >>$m 'WITH_LIBS+=-lpci' 135 LIBRESOLV= 136 ;; 137 gnu) 138 echo_n " hurd i386-ports" 139 echo >>$c '#define PCI_HAVE_PM_HURD_CONF' 140 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 141 ;; 142 djgpp) 143 echo_n " i386-ports" 144 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 145 EXEEXT=.exe 146 ;; 147 cygwin|windows) 148 echo_n " win32-cfgmgr32" 149 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 150 echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32' 151 # Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions 152 # also in other import libraries, not only in libcfgmgr32.a. 153 # So always set -lcfgmgr32 as a first library parameter which 154 # instruct linker to prefer symbols from cfgmgr32.dll. 155 echo >>$m 'WITH_LIBS+=-lcfgmgr32' 156 echo_n " i386-ports" 157 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 158 if [ "$sys" = "cygwin" ] ; then 159 # ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h 160 echo >>$m 'WITH_LIBS+=-lioperm' 161 elif [ "$sys" = "windows" ] ; then 162 # advapi32 is windows system library and used only by lib/i386-io-windows.h 163 echo >>$m 'WITH_LIBS+=-ladvapi32' 164 fi 165 EXEEXT=.exe 166 ;; 167 beos|haiku) 168 case $cpu in 169 i?86|x86_64) echo_n " i386-ports" 170 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' 171 ;; 172 esac 173 echo >>$c '#define PCI_HAVE_STDINT_H' 174 ;; 175 sylixos) 176 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"' 177 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' 178 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE' 179 IDSDIR="/etc/pci" 180 LIBRESOLV= 181 ;; 182 *) 183 echo " Unfortunately, your OS is not supported by the PCI Library" 184 exit 1 185 ;; 186esac 187 188echo >>$m "LIBEXT="$LIBEXT 189echo >>$m "EXEEXT="$EXEEXT 190echo >>$m "LSPCIDIR=\$($LSPCIDIR)" 191echo >>$c '#define PCI_HAVE_PM_DUMP' 192echo " dump" 193 194echo_n "Checking for zlib support... " 195if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then 196 echo "$ZLIB (set manually)" 197else 198 if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then 199 ZLIB=yes 200 else 201 ZLIB=no 202 fi 203 echo "$ZLIB (auto-detected)" 204fi 205if [ "$ZLIB" = yes ] ; then 206 echo >>$c '#define PCI_COMPRESSED_IDS' 207 echo >>$c '#define PCI_IDS "pci.ids.gz"' 208 echo >>$m 'LIBZ=-lz' 209 echo >>$m 'WITH_LIBS+=$(LIBZ)' 210else 211 echo >>$c '#define PCI_IDS "pci.ids"' 212fi 213echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\"" 214 215echo_n "Checking for DNS support... " 216if [ "$DNS" = yes -o "$DNS" = no ] ; then 217 echo "$DNS (set manually)" 218else 219 if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then 220 DNS=yes 221 else 222 DNS=no 223 fi 224 echo "$DNS (auto-detected)" 225fi 226if [ "$DNS" = yes ] ; then 227 echo >>$c "#define PCI_USE_DNS" 228 echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\"" 229 echo >>$m "WITH_LIBS+=$LIBRESOLV" 230fi 231 232if [ "$sys" = linux ] ; then 233 echo_n "Checking for libkmod... " 234 LIBKMOD_DETECTED= 235 if [ -z "$PKG_CONFIG" ] ; then 236 PKG_CONFIG=pkg-config 237 fi 238 if [ "$LIBKMOD" != no ] ; then 239 if ! which $PKG_CONFIG >/dev/null ; then 240 echo_n "($PKG_CONFIG not found) " 241 elif $PKG_CONFIG libkmod ; then 242 LIBKMOD_DETECTED=1 243 fi 244 fi 245 if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then 246 echo "$LIBKMOD (set manually)" 247 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then 248 echo "Requested use of libkmod, but it is not available. Giving up." 249 exit 1 250 fi 251 else 252 if [ -n "$LIBKMOD_DETECTED" ] ; then 253 LIBKMOD=yes 254 else 255 LIBKMOD=no 256 fi 257 echo "$LIBKMOD (auto-detected)" 258 fi 259 if [ "$LIBKMOD" = yes ] ; then 260 echo >>$c "#define PCI_USE_LIBKMOD" 261 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)" 262 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)" 263 fi 264 265 echo_n "Checking for udev hwdb support... " 266 if [ "$HWDB" = yes -o "$HWDB" = no ] ; then 267 echo "$HWDB (set manually)" 268 else 269 if `which pkg-config >/dev/null && pkg-config --atleast-version=196 libudev` ; then 270 HWDB=yes 271 else 272 HWDB=no 273 fi 274 echo "$HWDB (auto-detected)" 275 fi 276 if [ "$HWDB" = yes ] ; then 277 echo >>$c '#define PCI_HAVE_HWDB' 278 echo >>$m 'LIBUDEV=-ludev' 279 echo >>$m 'WITH_LIBS+=$(LIBUDEV)' 280 fi 281fi 282 283echo "Checking whether to build a shared library... $SHARED (set manually)" 284if [ "$SHARED" = no ] ; then 285 echo >>$m 'PCILIB=$(LIBNAME).a' 286 echo >>$m 'LDLIBS=$(WITH_LIBS)' 287 echo >>$m 'LIB_LDLIBS=' 288else 289 if [ "$LIBEXT" = so ]; then 290 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)' 291 else 292 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)' 293 fi 294 # We link the dependencies _to_ the library, so we do not need explicit deps in .pc 295 echo >>$m 'LDLIBS=' 296 echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)' 297 echo >>$c '#define PCI_SHARED_LIB' 298 if [ "$SHARED" = yes -a "$LIBEXT" = so ]; then 299 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).$(LIBEXT)$(ABI_VERSION)' 300 fi 301fi 302echo >>$m 'PCILIBPC=$(LIBNAME).pc' 303 304echo >>$c "#define PCILIB_VERSION \"$VERSION\"" 305sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m 306