]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
7890c4c71a6e5b2ec9a010acaf50aa8d9393dde2
[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         if [ -n "$BASH" ]
10         then
11                 echo -n "$*"
12         else
13                 echo "$*\c"
14         fi
15 }
16
17 if [ -z "$VERSION" -o -z "$IDSDIR" ] ; then
18         echo >&2 "Please run the configure script from the top-level Makefile"
19         exit 1
20 fi
21
22 echo_n "Configuring libpci for your system..."
23 if [ -z "$HOST" ] ; then
24         sys=`uname -s`
25         rel=`uname -r`
26         realsys="$sys"
27         if [ "$sys" = "AIX" -a -x /usr/bin/oslevel -a -x /usr/sbin/lsattr ]
28         then
29                 rel=`/usr/bin/oslevel`
30                 proc=`/usr/sbin/lsdev -C -c processor -S available -F name | head -1`
31                 cpu=`/usr/sbin/lsattr -F value -l $proc -a type | sed 's/_.*//'`
32         else
33                 cpu=`uname -m | sed 's/^i.86$/i386/;s/^sun4u$/sparc64/;s/^i86pc$/i386/;s/^BePC$/i386/;s/^BeMac$/powerpc/;s/^BeBox$/powerpc/'`
34         fi
35         if [ "$sys" = "GNU/kFreeBSD" -o "$sys" = "DragonFly" ]
36         then
37                 sys=freebsd
38         fi
39         if [ "$sys" = "CYGWIN_NT-5.1" -o "$sys" = "CYGWIN_NT-6.0" ]
40         then
41                 sys=cygwin
42         fi
43         HOST=${3:-$cpu-$sys}
44 fi
45 [ -n "$RELEASE" ] && rel="${RELEASE}"
46 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
47 host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
48 cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
49 sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
50 echo " $host $rel $cpu $sys"
51
52 c=config.h
53 m=config.mk
54 echo >$c '#define PCI_CONFIG_H'
55 echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
56 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
57 echo >$m 'WITH_LIBS='
58
59 echo_n "Looking for access methods..."
60 LIBRESOLV=-lresolv
61 LIBEXT=so
62
63 case $sys in
64         linux*)
65                 echo_n " sysfs proc"
66                 echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS'
67                 echo >>$c '#define PCI_HAVE_PM_LINUX_PROC'
68                 echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H'
69                 echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"'
70                 echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"'
71                 case $cpu in
72                                 i?86|x86_64)    echo_n " i386-ports"
73                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
74                                                 ;;
75                 esac
76                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
77                 ;;
78         sunos)
79                 case $cpu in
80                                 i?86)           echo_n " i386-ports"
81                                                 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
82                                                 ;;
83                                 *)
84                                                 echo " The PCI library does not support Solaris for this architecture: $cpu"
85                                                 exit 1
86                                                 ;;
87                 esac
88                 echo >>$c '#define PCI_HAVE_STDINT_H'
89                 ;;
90         freebsd*)
91                 echo_n " fbsd-device"
92                 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
93                 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
94                 if [ "$realsys" != "GNU/kFreeBSD" ] ; then
95                         LIBRESOLV=
96                 fi
97                 ;;
98         openbsd)
99                 echo_n " obsd-device"
100                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
101                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
102                 LIBRESOLV=
103                 ;;
104
105         darwin*)
106                 echo_n " darwin"
107                 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
108                 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
109                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
110                 LIBRESOLV=
111                 LIBEXT=dylib
112                 ;;
113         aix)
114                 echo_n " aix-device"
115                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
116                 echo >>$m 'CFLAGS=-g'
117                 echo >>$m 'INSTALL=installbsd'
118                 echo >>$m 'DIRINSTALL=mkdir -p'
119                 ;;
120         netbsd)
121                 echo_n " nbsd-libpci"
122                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
123                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
124                 echo >>$m 'LIBNAME=libpciutils'
125                 echo >>$m 'WITH_LIBS+=-lpci'
126                 LIBRESOLV=
127                 ;;
128         gnu)
129                 echo_n " i386-ports"
130                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
131                 ;;
132         cygwin)
133                 echo_n " i386-ports"
134                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
135                 echo >>$m 'WITH_LIBS+=-lioperm'
136                 ;;
137         beos|haiku)
138                 case $cpu in
139                                 i?86|x86_64)    echo_n " i386-ports"
140                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
141                                                 ;;
142                 esac
143                 echo >>$c '#define PCI_HAVE_STDINT_H'
144                 ;;
145         *)
146                 echo " Unfortunately, your OS is not supported by the PCI Library"
147                 exit 1
148                 ;;
149 esac
150
151 echo >>$m "LIBEXT="$LIBEXT
152 echo >>$c '#define PCI_HAVE_PM_DUMP'
153 echo " dump"
154
155 echo_n "Checking for zlib support... "
156 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
157         echo "$ZLIB (set manually)"
158 else
159         if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
160                 ZLIB=yes
161         else
162                 ZLIB=no
163         fi
164         echo "$ZLIB (auto-detected)"
165 fi
166 if [ "$ZLIB" = yes ] ; then
167         echo >>$c '#define PCI_COMPRESSED_IDS'
168         echo >>$c '#define PCI_IDS "pci.ids.gz"'
169         echo >>$m 'LIBZ=-lz'
170         echo >>$m 'WITH_LIBS+=$(LIBZ)'
171 else
172         echo >>$c '#define PCI_IDS "pci.ids"'
173 fi
174 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
175
176 echo_n "Checking for DNS support... "
177 if [ "$DNS" = yes -o "$DNS" = no ] ; then
178         echo "$DNS (set manually)"
179 else
180         if [ -f /usr/include/resolv.h ] ; then
181                 DNS=yes
182         else
183                 DNS=no
184         fi
185         echo "$DNS (auto-detected)"
186 fi
187 if [ "$DNS" = yes ] ; then
188         echo >>$c "#define PCI_USE_DNS"
189         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
190         echo >>$m "WITH_LIBS+=$LIBRESOLV"
191 fi
192
193 if [ "$sys" = linux ] ; then
194         echo_n "Checking for libkmod... "
195         LIBKMOD_DETECTED=
196         if [ -z "$PKG_CONFIG" ] ; then
197                 PKG_CONFIG=pkg-config
198         fi
199         if [ "$LIBKMOD" != no ] ; then
200                 if ! which $PKG_CONFIG >/dev/null ; then
201                         echo_n "($PKG_CONFIG not found) "
202                 elif $PKG_CONFIG libkmod ; then
203                         LIBKMOD_DETECTED=1
204                 fi
205         fi
206         if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
207                 echo "$LIBKMOD (set manually)"
208                 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
209                         echo "Requested use of libkmod, but it is not available. Giving up."
210                         exit 1
211                 fi
212         else
213                 if [ -n "$LIBKMOD_DETECTED" ] ; then
214                         LIBKMOD=yes
215                 else
216                         LIBKMOD=no
217                 fi
218                 echo "$LIBKMOD (auto-detected)"
219         fi
220         if [ "$LIBKMOD" = yes ] ; then
221                 echo >>$c "#define PCI_USE_LIBKMOD"
222                 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
223                 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
224         fi
225 fi
226
227 echo "Checking whether to build a shared library... $SHARED (set manually)"
228 if [ "$SHARED" = no ] ; then
229         echo >>$m 'PCILIB=$(LIBNAME).a'
230         echo >>$m 'LDLIBS=$(WITH_LIBS)'
231         echo >>$m 'LIB_LDLIBS='
232 else
233         if [ "$LIBEXT" = so ]; then
234                 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
235         else
236                 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
237         fi
238         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
239         echo >>$m 'LDLIBS='
240         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
241         echo >>$c '#define PCI_SHARED_LIB'
242         if [ "$SHARED" = yes -a "$LIBEXT" = so ]; then
243                 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).$(LIBEXT)$(ABI_VERSION)'
244         fi
245 fi
246 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
247
248 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
249 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m