]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
521cd7100cd4b7e034f5f811902be9d6a329b3ba
[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" ]
36         then
37                 sys=cygwin
38         fi
39         HOST=${3:-$cpu-$sys}
40 fi
41 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
42 host=`echo $HOST | sed '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"
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
57 case $sys in
58         linux*)
59                 echo_n " sysfs proc"
60                 echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS'
61                 echo >>$c '#define PCI_HAVE_PM_LINUX_PROC'
62                 echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H'
63                 echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"'
64                 echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"'
65                 case $cpu in
66                                 i386|x86_64)    echo_n " i386-ports"
67                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
68                                                 ;;
69                 esac
70                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
71                 ;;
72         sunos)
73                 case $cpu in
74                                 i386)           echo_n " i386-ports"
75                                                 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
76                                                 ;;
77                                 *)
78                                                 echo " The PCI library does not support Solaris for this architecture: $cpu"
79                                                 exit 1
80                                                 ;;
81                 esac
82                 echo >>$c '#define PCI_HAVE_STDINT_H'
83                 ;;
84         freebsd)
85                 echo_n " fbsd-device"
86                 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
87                 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
88                 LIBRESOLV=
89                 ;;
90         openbsd)
91                 echo_n " obsd-device"
92                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
93                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
94                 LIBRESOLV=
95                 ;;
96         aix)
97                 echo_n " aix-device"
98                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
99                 echo >>$m 'CFLAGS=-g'
100                 echo >>$m 'INSTALL=installbsd'
101                 echo >>$m 'DIRINSTALL=mkdir -p'
102                 ;;
103         netbsd)
104                 echo_n " nbsd-libpci"
105                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
106                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
107                 echo >>$m 'LIBNAME=libpciutils'
108                 echo >>$m 'WITH_LIBS+=-lpci'
109                 LIBRESOLV=
110                 ;;
111         gnu)
112                 echo_n " i386-ports"
113                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
114                 ;;
115         cygwin)
116                 echo_n " i386-ports"
117                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
118                 echo >>$m 'LDLIBS+=-lioperm'
119                 ;;
120         *)
121                 echo " Unfortunately, your OS is not supported by the PCI Library"
122                 exit 1
123                 ;;
124 esac
125
126 echo >>$c '#define PCI_HAVE_PM_DUMP'
127 echo " dump"
128
129 echo_n "Checking for zlib support... "
130 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
131         echo "$ZLIB (set manually)"
132 else
133         if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
134                 ZLIB=yes
135         else
136                 ZLIB=no
137         fi
138         echo "$ZLIB (auto-detected)"
139 fi
140 if [ "$ZLIB" = yes ] ; then
141         echo >>$c '#define PCI_COMPRESSED_IDS'
142         echo >>$c '#define PCI_IDS "pci.ids.gz"'
143         echo >>$m 'LIBZ=-lz'
144         echo >>$m 'WITH_LIBS+=$(LIBZ)'
145 else
146         echo >>$c '#define PCI_IDS "pci.ids"'
147 fi
148 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
149
150 echo_n "Checking for DNS support... "
151 if [ "$DNS" = yes -o "$DNS" = no ] ; then
152         echo "$DNS (set manually)"
153 else
154         if [ -f /usr/include/resolv.h ] ; then
155                 DNS=yes
156         else
157                 DNS=no
158         fi
159         echo "$DNS (auto-detected)"
160 fi
161 if [ "$DNS" = yes ] ; then
162         echo >>$c "#define PCI_USE_DNS"
163         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
164         echo >>$m "WITH_LIBS+=$LIBRESOLV"
165 fi
166
167 echo "Checking whether to build a shared library... $SHARED (set manually)"
168 if [ "$SHARED" = no ] ; then
169         echo >>$m 'PCILIB=$(LIBNAME).a'
170         echo >>$m 'LDLIBS=$(WITH_LIBS)'
171         echo >>$m 'LIB_LDLIBS='
172 else
173         echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)'
174         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
175         echo >>$m 'LDLIBS='
176         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
177         echo >>$c '#define PCI_SHARED_LIB'
178         if [ "$SHARED" = yes ] ; then
179                 echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
180         fi
181 fi
182 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
183
184 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
185 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m