]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
Fix inconsistent bus centric view between the sysfs and proc methods
[pciutils.git] / lib / configure
1 #!/bin/sh
2 # Configuration script for the PCI library
3 # (c) 1998--2008 Martin Mares <mj@ucw.cz>
4
5 echo_n() {
6         if [ -n "$BASH" ]
7         then
8                 echo -n "$*"
9         else
10                 echo "$*\c"
11         fi
12 }
13
14 if [ -z "$VERSION" -o -z "$IDSDIR" ] ; then
15         echo >&2 "Please run the configure script from the top-level Makefile"
16         exit 1
17 fi
18
19 echo_n "Configuring libpci for your system..."
20 if [ -z "$HOST" ] ; then
21         sys=`uname -s`
22         rel=`uname -r`
23         if [ "$sys" = "AIX" -a -x /usr/bin/oslevel -a -x /usr/sbin/lsattr ]
24         then
25                 rel=`/usr/bin/oslevel`
26                 proc=`/usr/sbin/lsdev -C -c processor -S available -F name | head -1`
27                 cpu=`/usr/sbin/lsattr -F value -l $proc -a type | sed 's/_.*//'`
28         else
29                 cpu=`uname -m | sed 's/^i.86$/i386/;s/^sun4u$/sparc64/;s/^i86pc$/i386/'`
30         fi
31         if [ "$sys" = "GNU/kFreeBSD" -o "$sys" = "DragonFly" ]
32         then
33                 sys=freebsd
34         fi
35         if [ "$sys" = "CYGWIN_NT-5.1" -o "$sys" = "CYGWIN_NT-6.0" ]
36         then
37                 sys=cygwin
38         fi
39         HOST=${3:-$cpu-$sys}
40 fi
41 [ -n "$RELEASE" ] && rel="${RELEASE}"
42 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
43 host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
44 cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
45 sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
46 echo " $host $rel $cpu $sys"
47
48 c=config.h
49 m=config.mk
50 echo >$c '#define PCI_CONFIG_H'
51 echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
52 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
53 echo >$m 'WITH_LIBS='
54
55 echo_n "Looking for access methods..."
56 LIBRESOLV=-lresolv
57
58 case $sys in
59         linux*)
60                 echo_n " sysfs proc"
61                 echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS'
62                 echo >>$c '#define PCI_HAVE_PM_LINUX_PROC'
63                 echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H'
64                 echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"'
65                 echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"'
66                 case $cpu in
67                                 i?86|x86_64)    echo_n " i386-ports"
68                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
69                                                 ;;
70                 esac
71                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
72                 ;;
73         sunos)
74                 case $cpu in
75                                 i?86)           echo_n " i386-ports"
76                                                 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
77                                                 ;;
78                                 *)
79                                                 echo " The PCI library does not support Solaris for this architecture: $cpu"
80                                                 exit 1
81                                                 ;;
82                 esac
83                 echo >>$c '#define PCI_HAVE_STDINT_H'
84                 ;;
85         freebsd)
86                 echo_n " fbsd-device"
87                 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
88                 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
89                 LIBRESOLV=
90                 ;;
91         openbsd)
92                 echo_n " obsd-device"
93                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
94                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
95                 LIBRESOLV=
96                 ;;
97         aix)
98                 echo_n " aix-device"
99                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
100                 echo >>$m 'CFLAGS=-g'
101                 echo >>$m 'INSTALL=installbsd'
102                 echo >>$m 'DIRINSTALL=mkdir -p'
103                 ;;
104         netbsd)
105                 echo_n " nbsd-libpci"
106                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
107                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
108                 echo >>$m 'LIBNAME=libpciutils'
109                 echo >>$m 'WITH_LIBS+=-lpci'
110                 LIBRESOLV=
111                 ;;
112         gnu)
113                 echo_n " i386-ports"
114                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
115                 ;;
116         cygwin)
117                 echo_n " i386-ports"
118                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
119                 echo >>$m 'WITH_LIBS+=-lioperm'
120                 ;;
121         *)
122                 echo " Unfortunately, your OS is not supported by the PCI Library"
123                 exit 1
124                 ;;
125 esac
126
127 echo >>$c '#define PCI_HAVE_PM_DUMP'
128 echo " dump"
129
130 echo_n "Checking for zlib support... "
131 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
132         echo "$ZLIB (set manually)"
133 else
134         if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
135                 ZLIB=yes
136         else
137                 ZLIB=no
138         fi
139         echo "$ZLIB (auto-detected)"
140 fi
141 if [ "$ZLIB" = yes ] ; then
142         echo >>$c '#define PCI_COMPRESSED_IDS'
143         echo >>$c '#define PCI_IDS "pci.ids.gz"'
144         echo >>$m 'LIBZ=-lz'
145         echo >>$m 'WITH_LIBS+=$(LIBZ)'
146 else
147         echo >>$c '#define PCI_IDS "pci.ids"'
148 fi
149 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
150
151 echo_n "Checking for DNS support... "
152 if [ "$DNS" = yes -o "$DNS" = no ] ; then
153         echo "$DNS (set manually)"
154 else
155         if [ -f /usr/include/resolv.h ] ; then
156                 DNS=yes
157         else
158                 DNS=no
159         fi
160         echo "$DNS (auto-detected)"
161 fi
162 if [ "$DNS" = yes ] ; then
163         echo >>$c "#define PCI_USE_DNS"
164         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
165         echo >>$m "WITH_LIBS+=$LIBRESOLV"
166 fi
167
168 echo "Checking whether to build a shared library... $SHARED (set manually)"
169 if [ "$SHARED" = no ] ; then
170         echo >>$m 'PCILIB=$(LIBNAME).a'
171         echo >>$m 'LDLIBS=$(WITH_LIBS)'
172         echo >>$m 'LIB_LDLIBS='
173 else
174         echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)'
175         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
176         echo >>$m 'LDLIBS='
177         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
178         echo >>$c '#define PCI_SHARED_LIB'
179         if [ "$SHARED" = yes ] ; then
180                 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
181         fi
182 fi
183 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
184
185 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
186 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m