]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
Import initial Darwin Support from Apple
[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
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*)
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 [ "$realsys" != "GNU/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-device"
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                 ;;
111         aix)
112                 echo_n " aix-device"
113                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
114                 echo >>$m 'CFLAGS=-g'
115                 echo >>$m 'INSTALL=installbsd'
116                 echo >>$m 'DIRINSTALL=mkdir -p'
117                 ;;
118         netbsd)
119                 echo_n " nbsd-libpci"
120                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
121                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
122                 echo >>$m 'LIBNAME=libpciutils'
123                 echo >>$m 'WITH_LIBS+=-lpci'
124                 LIBRESOLV=
125                 ;;
126         gnu)
127                 echo_n " i386-ports"
128                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
129                 ;;
130         cygwin)
131                 echo_n " i386-ports"
132                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
133                 echo >>$m 'WITH_LIBS+=-lioperm'
134                 ;;
135         beos|haiku)
136                 case $cpu in
137                                 i?86|x86_64)    echo_n " i386-ports"
138                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
139                                                 ;;
140                 esac
141                 echo >>$c '#define PCI_HAVE_STDINT_H'
142                 ;;
143         *)
144                 echo " Unfortunately, your OS is not supported by the PCI Library"
145                 exit 1
146                 ;;
147 esac
148
149 echo >>$c '#define PCI_HAVE_PM_DUMP'
150 echo " dump"
151
152 echo_n "Checking for zlib support... "
153 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
154         echo "$ZLIB (set manually)"
155 else
156         if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
157                 ZLIB=yes
158         else
159                 ZLIB=no
160         fi
161         echo "$ZLIB (auto-detected)"
162 fi
163 if [ "$ZLIB" = yes ] ; then
164         echo >>$c '#define PCI_COMPRESSED_IDS'
165         echo >>$c '#define PCI_IDS "pci.ids.gz"'
166         echo >>$m 'LIBZ=-lz'
167         echo >>$m 'WITH_LIBS+=$(LIBZ)'
168 else
169         echo >>$c '#define PCI_IDS "pci.ids"'
170 fi
171 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
172
173 echo_n "Checking for DNS support... "
174 if [ "$DNS" = yes -o "$DNS" = no ] ; then
175         echo "$DNS (set manually)"
176 else
177         if [ -f /usr/include/resolv.h ] ; then
178                 DNS=yes
179         else
180                 DNS=no
181         fi
182         echo "$DNS (auto-detected)"
183 fi
184 if [ "$DNS" = yes ] ; then
185         echo >>$c "#define PCI_USE_DNS"
186         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
187         echo >>$m "WITH_LIBS+=$LIBRESOLV"
188 fi
189
190 if [ "$sys" = linux ] ; then
191         echo_n "Checking for libkmod... "
192         LIBKMOD_DETECTED=
193         if [ -z "$PKG_CONFIG" ] ; then
194                 PKG_CONFIG=pkg-config
195         fi
196         if [ "$LIBKMOD" != no ] ; then
197                 if ! which $PKG_CONFIG >/dev/null ; then
198                         echo_n "($PKG_CONFIG not found) "
199                 elif $PKG_CONFIG libkmod ; then
200                         LIBKMOD_DETECTED=1
201                 fi
202         fi
203         if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
204                 echo "$LIBKMOD (set manually)"
205                 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
206                         echo "Requested use of libkmod, but it is not available. Giving up."
207                         exit 1
208                 fi
209         else
210                 if [ -n "$LIBKMOD_DETECTED" ] ; then
211                         LIBKMOD=yes
212                 else
213                         LIBKMOD=no
214                 fi
215                 echo "$LIBKMOD (auto-detected)"
216         fi
217         if [ "$LIBKMOD" = yes ] ; then
218                 echo >>$c "#define PCI_USE_LIBKMOD"
219                 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
220                 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
221         fi
222 fi
223
224 echo "Checking whether to build a shared library... $SHARED (set manually)"
225 if [ "$SHARED" = no ] ; then
226         echo >>$m 'PCILIB=$(LIBNAME).a'
227         echo >>$m 'LDLIBS=$(WITH_LIBS)'
228         echo >>$m 'LIB_LDLIBS='
229 else
230         echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)'
231         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
232         echo >>$m 'LDLIBS='
233         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
234         echo >>$c '#define PCI_SHARED_LIB'
235         if [ "$SHARED" = yes ] ; then
236                 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
237         fi
238 fi
239 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
240
241 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
242 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m