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