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