xref: /pciutils/lib/configure (revision 4c2bdb01)
1#!/bin/sh
2# Configuration script for the PCI library
3# (c) 1998--2009 Martin Mares <[email protected]>
4
5LC_ALL=C
6export LC_ALL
7
8echo_n() {
9	if [ -n "$BASH" ]
10	then
11		echo -n "$*"
12	else
13		echo "$*\c"
14	fi
15}
16
17if [ -z "$VERSION" -o -z "$IDSDIR" ] ; then
18	echo >&2 "Please run the configure script from the top-level Makefile"
19	exit 1
20fi
21
22echo_n "Configuring libpci for your system..."
23if [ -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/'`
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}
44fi
45[ -n "$RELEASE" ] && rel="${RELEASE}"
46# CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
47host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
48cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
49sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
50echo " $host $rel $cpu $sys"
51
52c=config.h
53m=config.mk
54echo >$c '#define PCI_CONFIG_H'
55echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
56echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
57echo >$m 'WITH_LIBS='
58
59echo_n "Looking for access methods..."
60LIBRESOLV=-lresolv
61
62case $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	aix)
104		echo_n " aix-device"
105		echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
106		echo >>$m 'CFLAGS=-g'
107		echo >>$m 'INSTALL=installbsd'
108		echo >>$m 'DIRINSTALL=mkdir -p'
109		;;
110	netbsd)
111		echo_n " nbsd-libpci"
112		echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
113		echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
114		echo >>$m 'LIBNAME=libpciutils'
115		echo >>$m 'WITH_LIBS+=-lpci'
116		LIBRESOLV=
117		;;
118    	gnu)
119		echo_n " i386-ports"
120		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
121		;;
122	cygwin)
123		echo_n " i386-ports"
124		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
125		echo >>$m 'WITH_LIBS+=-lioperm'
126		;;
127        *)
128		echo " Unfortunately, your OS is not supported by the PCI Library"
129		exit 1
130		;;
131esac
132
133echo >>$c '#define PCI_HAVE_PM_DUMP'
134echo " dump"
135
136echo_n "Checking for zlib support... "
137if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
138	echo "$ZLIB (set manually)"
139else
140	if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
141		ZLIB=yes
142	else
143		ZLIB=no
144	fi
145	echo "$ZLIB (auto-detected)"
146fi
147if [ "$ZLIB" = yes ] ; then
148	echo >>$c '#define PCI_COMPRESSED_IDS'
149	echo >>$c '#define PCI_IDS "pci.ids.gz"'
150	echo >>$m 'LIBZ=-lz'
151	echo >>$m 'WITH_LIBS+=$(LIBZ)'
152else
153	echo >>$c '#define PCI_IDS "pci.ids"'
154fi
155echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
156
157echo_n "Checking for DNS support... "
158if [ "$DNS" = yes -o "$DNS" = no ] ; then
159	echo "$DNS (set manually)"
160else
161	if [ -f /usr/include/resolv.h ] ; then
162		DNS=yes
163	else
164		DNS=no
165	fi
166	echo "$DNS (auto-detected)"
167fi
168if [ "$DNS" = yes ] ; then
169	echo >>$c "#define PCI_USE_DNS"
170	echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
171	echo >>$m "WITH_LIBS+=$LIBRESOLV"
172fi
173
174echo "Checking whether to build a shared library... $SHARED (set manually)"
175if [ "$SHARED" = no ] ; then
176	echo >>$m 'PCILIB=$(LIBNAME).a'
177	echo >>$m 'LDLIBS=$(WITH_LIBS)'
178	echo >>$m 'LIB_LDLIBS='
179else
180	echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)'
181	# We link the dependencies _to_ the library, so we do not need explicit deps in .pc
182	echo >>$m 'LDLIBS='
183	echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
184	echo >>$c '#define PCI_SHARED_LIB'
185	if [ "$SHARED" = yes ] ; then
186		echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
187	fi
188fi
189echo >>$m 'PCILIBPC=$(LIBNAME).pc'
190
191echo >>$c "#define PCILIB_VERSION \"$VERSION\""
192sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m
193