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