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