xref: /pciutils/lib/configure (revision bcfd10e3)
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
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	beos|haiku)
128		case $cpu in
129				i?86|x86_64)	echo_n " i386-ports"
130						echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
131						;;
132		esac
133		echo >>$c '#define PCI_HAVE_STDINT_H'
134		;;
135	*)
136		echo " Unfortunately, your OS is not supported by the PCI Library"
137		exit 1
138		;;
139esac
140
141echo >>$c '#define PCI_HAVE_PM_DUMP'
142echo " dump"
143
144echo_n "Checking for zlib support... "
145if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
146	echo "$ZLIB (set manually)"
147else
148	if [ -f /usr/include/zlib.h -o -f /usr/local/include/zlib.h ] ; then
149		ZLIB=yes
150	else
151		ZLIB=no
152	fi
153	echo "$ZLIB (auto-detected)"
154fi
155if [ "$ZLIB" = yes ] ; then
156	echo >>$c '#define PCI_COMPRESSED_IDS'
157	echo >>$c '#define PCI_IDS "pci.ids.gz"'
158	echo >>$m 'LIBZ=-lz'
159	echo >>$m 'WITH_LIBS+=$(LIBZ)'
160else
161	echo >>$c '#define PCI_IDS "pci.ids"'
162fi
163echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
164
165echo_n "Checking for DNS support... "
166if [ "$DNS" = yes -o "$DNS" = no ] ; then
167	echo "$DNS (set manually)"
168else
169	if [ -f /usr/include/resolv.h ] ; then
170		DNS=yes
171	else
172		DNS=no
173	fi
174	echo "$DNS (auto-detected)"
175fi
176if [ "$DNS" = yes ] ; then
177	echo >>$c "#define PCI_USE_DNS"
178	echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
179	echo >>$m "WITH_LIBS+=$LIBRESOLV"
180fi
181
182if [ "$sys" = linux ] ; then
183	echo_n "Checking for libkmod... "
184	LIBKMOD_DETECTED=
185	if [ -z "$PKG_CONFIG" ] ; then
186		PKG_CONFIG=pkg-config
187	fi
188	if [ "$LIBKMOD" != no ] ; then
189		if ! which $PKG_CONFIG >/dev/null ; then
190			echo_n "($PKG_CONFIG not found) "
191		elif $PKG_CONFIG libkmod ; then
192			LIBKMOD_DETECTED=1
193		fi
194	fi
195	if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
196		echo "$LIBKMOD (set manually)"
197		if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
198			echo "Requested use of libkmod, but it is not available. Giving up."
199			exit 1
200		fi
201	else
202		if [ -n "$LIBKMOD_DETECTED" ] ; then
203			LIBKMOD=yes
204		else
205			LIBKMOD=no
206		fi
207		echo "$LIBKMOD (auto-detected)"
208	fi
209	if [ "$LIBKMOD" = yes ] ; then
210		echo >>$c "#define PCI_USE_LIBKMOD"
211		echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
212		echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
213	fi
214fi
215
216echo "Checking whether to build a shared library... $SHARED (set manually)"
217if [ "$SHARED" = no ] ; then
218	echo >>$m 'PCILIB=$(LIBNAME).a'
219	echo >>$m 'LDLIBS=$(WITH_LIBS)'
220	echo >>$m 'LIB_LDLIBS='
221else
222	echo >>$m 'PCILIB=$(LIBNAME).so.$(VERSION)'
223	# We link the dependencies _to_ the library, so we do not need explicit deps in .pc
224	echo >>$m 'LDLIBS='
225	echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
226	echo >>$c '#define PCI_SHARED_LIB'
227	if [ "$SHARED" = yes ] ; then
228		echo >>$m 'SONAME=-Wl,-soname,$(LIBNAME).so$(ABI_VERSION)'
229	fi
230fi
231echo >>$m 'PCILIBPC=$(LIBNAME).pc'
232
233echo >>$c "#define PCILIB_VERSION \"$VERSION\""
234sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m
235