]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
names-net: Avoid buffer overflow warnings by newer gcc
[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         printf '%s' "$*"
10 }
11
12 if [ -z "$VERSION" -o -z "$IDSDIR" ] ; then
13         echo >&2 "Please run the configure script from the top-level Makefile"
14         exit 1
15 fi
16
17 echo_n "Configuring libpci for your system..."
18 if [ -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$/i386/;s/^sun4u$/sparc64/;s/^i86pc$/i386/;s/^BePC$/i386/;s/^BeMac$/powerpc/;s/^BeBox$/powerpc/'`
29         fi
30         if [ "$sys" = "GNU/kFreeBSD" -o "$sys" = "DragonFly" ]
31         then
32                 sys=freebsd
33         fi
34         if [ "$sys" = "CYGWIN_NT-5.1" -o "$sys" = "CYGWIN_NT-6.0" ]
35         then
36                 sys=cygwin
37         fi
38         HOST=${3:-$cpu-$sys}
39 fi
40 [ -n "$RELEASE" ] && rel="${RELEASE}"
41 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
42 host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\2/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
43 cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
44 sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
45 echo " $host $rel $cpu $sys"
46
47 c=config.h
48 m=config.mk
49 echo >$c '#define PCI_CONFIG_H'
50 echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
51 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
52 echo >$m 'WITH_LIBS='
53
54 echo_n "Looking for access methods..."
55 LIBRESOLV=-lresolv
56 LIBEXT=so
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                 if [ "$realsys" != "GNU/kFreeBSD" ] ; then
90                         LIBRESOLV=
91                 fi
92                 ;;
93         openbsd)
94                 echo_n " obsd-device"
95                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
96                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
97                 LIBRESOLV=
98                 ;;
99
100         darwin*)
101                 echo_n " darwin"
102                 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
103                 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
104                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
105                 LIBRESOLV=
106                 LIBEXT=dylib
107                 ;;
108         aix)
109                 echo_n " aix-device"
110                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
111                 echo >>$m 'CFLAGS=-g'
112                 echo >>$m 'INSTALL=installbsd'
113                 echo >>$m 'DIRINSTALL=mkdir -p'
114                 ;;
115         netbsd)
116                 echo_n " nbsd-libpci"
117                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
118                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
119                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
120                 echo >>$m 'LIBNAME=libpciutils'
121                 echo >>$m 'WITH_LIBS+=-lpci'
122                 LIBRESOLV=
123                 ;;
124         gnu)
125                 echo_n " i386-ports"
126                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
127                 ;;
128         djgpp)
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         sylixos)
146                 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"'
147                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
148                 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE'
149                 IDSDIR="/etc/pci"
150                 LIBRESOLV=
151                 ;;
152         *)
153                 echo " Unfortunately, your OS is not supported by the PCI Library"
154                 exit 1
155                 ;;
156 esac
157
158 echo >>$m "LIBEXT="$LIBEXT
159 echo >>$c '#define PCI_HAVE_PM_DUMP'
160 echo " dump"
161
162 echo_n "Checking for zlib support... "
163 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
164         echo "$ZLIB (set manually)"
165 else
166         if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
167                 ZLIB=yes
168         else
169                 ZLIB=no
170         fi
171         echo "$ZLIB (auto-detected)"
172 fi
173 if [ "$ZLIB" = yes ] ; then
174         echo >>$c '#define PCI_COMPRESSED_IDS'
175         echo >>$c '#define PCI_IDS "pci.ids.gz"'
176         echo >>$m 'LIBZ=-lz'
177         echo >>$m 'WITH_LIBS+=$(LIBZ)'
178 else
179         echo >>$c '#define PCI_IDS "pci.ids"'
180 fi
181 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
182
183 echo_n "Checking for DNS support... "
184 if [ "$DNS" = yes -o "$DNS" = no ] ; then
185         echo "$DNS (set manually)"
186 else
187         if [ -f /usr/include/resolv.h ] ; then
188                 DNS=yes
189         else
190                 DNS=no
191         fi
192         echo "$DNS (auto-detected)"
193 fi
194 if [ "$DNS" = yes ] ; then
195         echo >>$c "#define PCI_USE_DNS"
196         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
197         echo >>$m "WITH_LIBS+=$LIBRESOLV"
198 fi
199
200 if [ "$sys" = linux ] ; then
201         echo_n "Checking for libkmod... "
202         LIBKMOD_DETECTED=
203         if [ -z "$PKG_CONFIG" ] ; then
204                 PKG_CONFIG=pkg-config
205         fi
206         if [ "$LIBKMOD" != no ] ; then
207                 if ! which $PKG_CONFIG >/dev/null ; then
208                         echo_n "($PKG_CONFIG not found) "
209                 elif $PKG_CONFIG libkmod ; then
210                         LIBKMOD_DETECTED=1
211                 fi
212         fi
213         if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
214                 echo "$LIBKMOD (set manually)"
215                 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
216                         echo "Requested use of libkmod, but it is not available. Giving up."
217                         exit 1
218                 fi
219         else
220                 if [ -n "$LIBKMOD_DETECTED" ] ; then
221                         LIBKMOD=yes
222                 else
223                         LIBKMOD=no
224                 fi
225                 echo "$LIBKMOD (auto-detected)"
226         fi
227         if [ "$LIBKMOD" = yes ] ; then
228                 echo >>$c "#define PCI_USE_LIBKMOD"
229                 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
230                 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
231         fi
232
233         echo_n "Checking for udev hwdb support... "
234         if [ "$HWDB" = yes -o "$HWDB" = no ] ; then
235                 echo "$HWDB (set manually)"
236         else
237                 if `which pkg-config >/dev/null && pkg-config --atleast-version=196 libudev` ; then
238                         HWDB=yes
239                 else
240                         HWDB=no
241                 fi
242                 echo "$HWDB (auto-detected)"
243         fi
244         if [ "$HWDB" = yes ] ; then
245                 echo >>$c '#define PCI_HAVE_HWDB'
246                 echo >>$m 'LIBUDEV=-ludev'
247                 echo >>$m 'WITH_LIBS+=$(LIBUDEV)'
248         fi
249 fi
250
251 echo "Checking whether to build a shared library... $SHARED (set manually)"
252 if [ "$SHARED" = no ] ; then
253         echo >>$m 'PCILIB=$(LIBNAME).a'
254         echo >>$m 'LDLIBS=$(WITH_LIBS)'
255         echo >>$m 'LIB_LDLIBS='
256 else
257         if [ "$LIBEXT" = so ]; then
258                 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
259         else
260                 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
261         fi
262         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
263         echo >>$m 'LDLIBS='
264         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
265         echo >>$c '#define PCI_SHARED_LIB'
266         if [ "$SHARED" = yes -a "$LIBEXT" = so ]; then
267                 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).$(LIBEXT)$(ABI_VERSION)'
268         fi
269 fi
270 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
271
272 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
273 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m