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