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