xref: /pciutils/lib/configure (revision 92bd9d99)
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
67LSPCIDIR=SBINDIR
68
69case $sys in
70	linux*)
71		echo_n " sysfs proc mem-ports"
72		echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS'
73		echo >>$c '#define PCI_HAVE_PM_LINUX_PROC'
74		echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
75		echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H'
76		echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"'
77		echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"'
78		echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
79		case $cpu in
80				i?86|x86_64)	echo_n " i386-ports"
81						echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
82						;;
83		esac
84		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
85		LSPCIDIR=BINDIR
86		;;
87	sunos)
88		case $cpu in
89				i?86)		echo_n " i386-ports"
90						echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
91						;;
92				*)
93						echo " The PCI library does not support Solaris for this architecture: $cpu"
94						exit 1
95						;;
96		esac
97		echo >>$c '#define PCI_HAVE_STDINT_H'
98		;;
99	freebsd*|kfreebsd*)
100		echo_n " fbsd-device"
101		echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
102		echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
103		echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
104		echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
105		if [ "$sys" != "kfreebsd" ] ; then
106			LIBRESOLV=
107		fi
108		;;
109        openbsd)
110	        echo_n " obsd-device"
111		echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
112		echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
113		echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
114		echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
115		LIBRESOLV=
116		;;
117
118        darwin*)
119	        echo_n " darwin"
120		echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
121		echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
122		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
123		LIBRESOLV=
124		LIBEXT=dylib
125		SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include
126		;;
127	aix)
128		echo_n " aix-device"
129		echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
130		echo >>$m 'CFLAGS=-g'
131		echo >>$m 'INSTALL=installbsd'
132		echo >>$m 'DIRINSTALL=mkdir -p'
133		;;
134	netbsd)
135		echo_n " nbsd-libpci"
136		echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
137		echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
138		echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
139		echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
140		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
141		echo >>$m 'LIBNAME=libpciutils'
142		echo >>$m 'WITH_LIBS+=-lpci'
143		LIBRESOLV=
144		;;
145	gnu)
146		echo_n " hurd i386-ports"
147		echo >>$c '#define PCI_HAVE_PM_HURD_CONF'
148		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
149		;;
150	djgpp)
151		echo_n " i386-ports"
152		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
153		EXEEXT=.exe
154		;;
155	cygwin|windows)
156		echo_n " win32-cfgmgr32 win32-sysdbg"
157		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
158		echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32'
159		echo >>$c '#define PCI_HAVE_PM_WIN32_SYSDBG'
160		# Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions
161		# also in other import libraries, not only in libcfgmgr32.a.
162		# So always set -lcfgmgr32 as a first library parameter which
163		# instruct linker to prefer symbols from cfgmgr32.dll.
164		echo >>$m 'WITH_LIBS+=-lcfgmgr32'
165		case $cpu in i?86|x86_64)
166		echo_n " i386-ports"
167		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
168		if [ "$sys" = "cygwin" ] ; then
169			# ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h
170			echo >>$m 'WITH_LIBS+=-lioperm'
171		elif [ "$sys" = "windows" ] ; then
172			# advapi32 is windows system library and used only by lib/i386-io-windows.h
173			echo >>$m 'WITH_LIBS+=-ladvapi32'
174		fi
175		;; esac
176		EXEEXT=.exe
177		LIBEXT=dll
178		;;
179	beos|haiku)
180		case $cpu in
181				i?86|x86_64)	echo_n " i386-ports"
182						echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
183						;;
184		esac
185		echo >>$c '#define PCI_HAVE_STDINT_H'
186		;;
187	sylixos)
188		echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"'
189		echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
190		echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE'
191		IDSDIR="/etc/pci"
192		LIBRESOLV=
193		;;
194	*)
195		echo " Unfortunately, your OS is not supported by the PCI Library"
196		exit 1
197		;;
198esac
199
200echo >>$m "LIBEXT="$LIBEXT
201echo >>$m "EXEEXT="$EXEEXT
202echo >>$m "LSPCIDIR=\$($LSPCIDIR)"
203echo >>$c '#define PCI_HAVE_PM_DUMP'
204echo " dump"
205
206echo_n "Checking for zlib support... "
207if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
208	echo "$ZLIB (set manually)"
209else
210	if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then
211		ZLIB=yes
212	else
213		ZLIB=no
214	fi
215	echo "$ZLIB (auto-detected)"
216fi
217if [ "$ZLIB" = yes ] ; then
218	echo >>$c '#define PCI_COMPRESSED_IDS'
219	echo >>$c '#define PCI_IDS "pci.ids.gz"'
220	echo >>$m 'LIBZ=-lz'
221	echo >>$m 'WITH_LIBS+=$(LIBZ)'
222else
223	echo >>$c '#define PCI_IDS "pci.ids"'
224fi
225echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
226
227echo_n "Checking for DNS support... "
228if [ "$DNS" = yes -o "$DNS" = no ] ; then
229	echo "$DNS (set manually)"
230else
231	if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then
232		DNS=yes
233	else
234		DNS=no
235	fi
236	echo "$DNS (auto-detected)"
237fi
238if [ "$DNS" = yes ] ; then
239	echo >>$c "#define PCI_USE_DNS"
240	echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
241	echo >>$m "WITH_LIBS+=$LIBRESOLV"
242fi
243
244if [ "$sys" = linux ] ; then
245	echo_n "Checking for libkmod... "
246	LIBKMOD_DETECTED=
247	if [ -z "$PKG_CONFIG" ] ; then
248		PKG_CONFIG=pkg-config
249	fi
250	if [ "$LIBKMOD" != no ] ; then
251		if ! command -v $PKG_CONFIG >/dev/null ; then
252			echo_n "($PKG_CONFIG not found) "
253		elif $PKG_CONFIG libkmod ; then
254			LIBKMOD_DETECTED=1
255		fi
256	fi
257	if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
258		echo "$LIBKMOD (set manually)"
259		if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
260			echo "Requested use of libkmod, but it is not available. Giving up."
261			exit 1
262		fi
263	else
264		if [ -n "$LIBKMOD_DETECTED" ] ; then
265			LIBKMOD=yes
266		else
267			LIBKMOD=no
268		fi
269		echo "$LIBKMOD (auto-detected)"
270	fi
271	if [ "$LIBKMOD" = yes ] ; then
272		echo >>$c "#define PCI_USE_LIBKMOD"
273		echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
274		echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
275	fi
276
277	echo_n "Checking for udev hwdb support... "
278	if [ "$HWDB" = yes -o "$HWDB" = no ] ; then
279		echo "$HWDB (set manually)"
280	else
281		if `command -v $PKG_CONFIG >/dev/null && $PKG_CONFIG --atleast-version=196 libudev` ; then
282			HWDB=yes
283		else
284			HWDB=no
285		fi
286		echo "$HWDB (auto-detected)"
287	fi
288	if [ "$HWDB" = yes ] ; then
289		echo >>$c '#define PCI_HAVE_HWDB'
290		echo >>$m 'LIBUDEV=-ludev'
291		echo >>$m 'WITH_LIBS+=$(LIBUDEV)'
292	fi
293fi
294
295echo "Checking whether to build a shared library... $SHARED (set manually)"
296if [ "$SHARED" = no ] ; then
297	echo >>$m 'PCILIB=$(LIBNAME).a'
298	echo >>$m 'LDLIBS=$(WITH_LIBS)'
299	echo >>$m 'LIB_LDLIBS='
300else
301	if [ "$LIBEXT" = so ]; then
302		echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
303	elif [ "$LIBEXT" = dll ]; then
304		echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)'
305	else
306		echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
307	fi
308	# We link the dependencies _to_ the library, so we do not need explicit deps in .pc
309	echo >>$m 'LDLIBS='
310	echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
311	echo >>$c '#define PCI_SHARED_LIB'
312	if [ "$LIBEXT" = so ]; then
313		echo >>$m 'PCILIB_LDFLAGS+=-Wl,-soname,$(LIBNAME).$(LIBEXT).$(ABI_VERSION)'
314		echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver'
315	elif [ "$LIBEXT" = dylib ]; then
316		echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)'
317	elif [ "$LIBEXT" = dll ]; then
318		echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def'
319		# GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21)
320		echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols'
321	fi
322fi
323echo >>$m 'PCILIBPC=$(LIBNAME).pc'
324
325if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then
326	echo >>$m 'PCIIMPLIB=$(PCILIB).a'
327else
328	echo >>$m 'PCIIMPLIB=$(PCILIB)'
329fi
330
331echo >>$c "#define PCILIB_VERSION \"$VERSION\""
332sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m
333