]> mj.ucw.cz Git - pciutils.git/blob - lib/configure
Merge branch 'amiga'
[pciutils.git] / lib / configure
1 #!/bin/sh
2 # Configuration script for the PCI library
3 # (c) 1998--2013 Martin Mares <mj@ucw.cz>
4
5 LC_ALL=C
6 export LC_ALL
7
8 echo_n() {
9         printf '%s' "$*"
10 }
11
12 if [ -z "$VERSION" ] ; then
13         echo >&2 "Please run the configure script from the top-level Makefile"
14         exit 1
15 fi
16
17 echo_n "Configuring libpci for your system..."
18 if [ -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}
47 fi
48 [ -n "$RELEASE" ] && rel="${RELEASE}"
49 # CAVEAT: tr on Solaris is a bit weird and the extra [] is otherwise harmless.
50 host=`echo $HOST | sed -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\3/' -e 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)$/\1-\2/' -e 's/^\([^-]*\)-\([^-]*\)$/\1--\2/' | tr '[A-Z]' '[a-z]'`
51 cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
52 sys=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
53 echo " $host $rel $cpu $sys"
54
55 c=config.h
56 m=config.mk
57 echo >$c '#define PCI_CONFIG_H'
58 echo >>$c "#define PCI_ARCH_`echo $cpu | tr '[a-z]' '[A-Z]'`"
59 echo >>$c "#define PCI_OS_`echo $sys | tr '[a-z]' '[A-Z]'`"
60 echo >$m 'WITH_LIBS='
61
62 echo_n "Looking for access methods..."
63 LIBRESOLV=-lresolv
64 LIBEXT=so
65 EXEEXT=
66 SYSINCLUDE=/usr/include
67 LSPCIDIR=SBINDIR
68
69 case $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                 echo_n " mem-ports ecam"
92                 case $cpu in
93                                 i?86)           echo_n " i386-ports"
94                                                 echo >>$c "#define PCI_HAVE_PM_INTEL_CONF"
95                                                 ;;
96                 esac
97                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
98                 echo >>$c '#define PCI_HAVE_PM_ECAM'
99                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/xsvc"'
100                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
101                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
102                 ;;
103         freebsd*|kfreebsd*)
104                 echo_n " fbsd-device mem-ports ecam"
105                 echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE'
106                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
107                 echo >>$c '#define PCI_HAVE_PM_ECAM'
108                 echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
109                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
110                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
111                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
112                 if [ "$sys" != "kfreebsd" ] ; then
113                         LIBRESOLV=
114                 fi
115                 ;;
116         openbsd)
117                 echo_n " obsd-device mem-ports ecam"
118                 echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
119                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
120                 echo >>$c '#define PCI_HAVE_PM_ECAM'
121                 echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
122                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
123                 echo >>$c '#define PCI_PATH_ACPI_MCFG "/var/db/acpi/MCFG.*"'
124                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
125                 case $cpu in
126                                 i386|amd64)     echo_n " i386-ports"
127                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
128                                                 echo >>$m 'WITH_LIBS+=-l'$cpu
129                                                 ;;
130                 esac
131                 LIBRESOLV=
132                 ;;
133
134         darwin*)
135                 echo_n " darwin"
136                 echo >>$c '#define PCI_HAVE_PM_DARWIN_DEVICE'
137                 echo >>$m 'WITH_LIBS+=-lresolv -framework CoreFoundation -framework IOKit'
138                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
139                 LIBRESOLV=
140                 LIBEXT=dylib
141                 SYSINCLUDE=$(xcrun --sdk macosx --show-sdk-path)/usr/include
142                 ;;
143         aix)
144                 echo_n " aix-device"
145                 echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'
146                 echo >>$m 'CFLAGS=-g'
147                 echo >>$m 'INSTALL=installbsd'
148                 echo >>$m 'DIRINSTALL=mkdir -p'
149                 ;;
150         netbsd)
151                 echo_n " nbsd-libpci mem-ports ecam"
152                 echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI'
153                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
154                 echo >>$c '#define PCI_HAVE_PM_ECAM'
155                 echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"'
156                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/mem"'
157                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
158                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
159                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
160                 echo >>$m 'LIBNAME=libpciutils'
161                 echo >>$m 'WITH_LIBS+=-lpci'
162                 LIBRESOLV=
163                 ;;
164         gnu)
165                 echo_n " hurd i386-ports"
166                 echo >>$c '#define PCI_HAVE_PM_HURD_CONF'
167                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
168                 ;;
169         djgpp)
170                 echo_n " i386-ports"
171                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
172                 EXEEXT=.exe
173                 ;;
174         cygwin|windows)
175                 echo_n " win32-cfgmgr32 win32-kldbg win32-sysdbg"
176                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
177                 echo >>$c '#define PCI_HAVE_PM_WIN32_CFGMGR32'
178                 echo >>$c '#define PCI_HAVE_PM_WIN32_KLDBG'
179                 echo >>$c '#define PCI_HAVE_PM_WIN32_SYSDBG'
180                 # Warning: MinGW-w64 (incorrectly) provides cfgmgr32 functions
181                 # also in other import libraries, not only in libcfgmgr32.a.
182                 # So always set -lcfgmgr32 as a first library parameter which
183                 # instruct linker to prefer symbols from cfgmgr32.dll.
184                 echo >>$m 'WITH_LIBS+=-lcfgmgr32'
185                 case $cpu in i?86|x86_64)
186                 echo_n " i386-ports"
187                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
188                 if [ "$sys" = "cygwin" ] ; then
189                         # ioperm is cygwin specific library and used only by lib/i386-io-cygwin.h
190                         echo >>$m 'WITH_LIBS+=-lioperm'
191                 elif [ "$sys" = "windows" ] ; then
192                         # advapi32 is windows system library and used only by lib/i386-io-windows.h
193                         echo >>$m 'WITH_LIBS+=-ladvapi32'
194                 fi
195                 ;; esac
196                 EXEEXT=.exe
197                 LIBEXT=dll
198                 ;;
199         beos|haiku)
200                 echo_n " mem-ports ecam"
201                 case $cpu in
202                                 i?86|x86_64)    echo_n " i386-ports"
203                                                 echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
204                                                 ;;
205                 esac
206                 echo >>$c '#define PCI_HAVE_PM_MMIO_CONF'
207                 echo >>$c '#define PCI_HAVE_PM_ECAM'
208                 echo >>$c '#define PCI_PATH_DEVMEM_DEVICE "/dev/misc/mem"'
209                 echo >>$c '#define PCI_PATH_ACPI_MCFG ""'
210                 echo >>$c '#define PCI_PATH_EFI_SYSTAB ""'
211                 ;;
212         sylixos)
213                 echo >>$c '#define PCI_PATH_SYLIXOS_DEVICE "/proc/pci"'
214                 echo >>$c '#define PCI_HAVE_64BIT_ADDRESS'
215                 echo >>$c '#define PCI_HAVE_PM_SYLIXOS_DEVICE'
216                 IDSDIR="/etc/pci"
217                 LIBRESOLV=
218                 ;;
219         amigaos)
220                 echo_n " aos-expansion"
221                 echo >>$c '#define PCI_HAVE_STDINT_H'
222                 echo >>$c '#define PCI_HAVE_PM_AOS_EXPANSION'
223                 IDSDIR="DEVS:"
224                 echo >>$m 'CC=gcc'
225                 ;;
226         *)
227                 echo " Unfortunately, your OS is not supported by the PCI Library"
228                 exit 1
229                 ;;
230 esac
231
232 echo >>$m "LIBEXT="$LIBEXT
233 echo >>$m "EXEEXT="$EXEEXT
234 echo >>$m "LSPCIDIR=\$($LSPCIDIR)"
235 echo >>$c '#define PCI_HAVE_PM_DUMP'
236 echo " dump"
237
238 echo_n "Checking for zlib support... "
239 if [ "$ZLIB" = yes -o "$ZLIB" = no ] ; then
240         echo "$ZLIB (set manually)"
241 else
242         if [ -f "$SYSINCLUDE/zlib.h" -o -f /usr/local/include/zlib.h ] ; then
243                 ZLIB=yes
244         else
245                 ZLIB=no
246         fi
247         echo "$ZLIB (auto-detected)"
248 fi
249 if [ "$ZLIB" = yes ] ; then
250         echo >>$c '#define PCI_COMPRESSED_IDS'
251         echo >>$c '#define PCI_IDS "pci.ids.gz"'
252         echo >>$m 'LIBZ=-lz'
253         echo >>$m 'WITH_LIBS+=$(LIBZ)'
254 else
255         echo >>$c '#define PCI_IDS "pci.ids"'
256 fi
257 echo >>$c "#define PCI_PATH_IDS_DIR \"$IDSDIR\""
258
259 echo_n "Checking for DNS support... "
260 if [ "$DNS" = yes -o "$DNS" = no ] ; then
261         echo "$DNS (set manually)"
262 else
263         if [ "$sys" != "windows" -a -f "$SYSINCLUDE/resolv.h" ] ; then
264                 DNS=yes
265         else
266                 DNS=no
267         fi
268         echo "$DNS (auto-detected)"
269 fi
270 if [ "$DNS" = yes ] ; then
271         echo >>$c "#define PCI_USE_DNS"
272         echo >>$c "#define PCI_ID_DOMAIN \"pci.id.ucw.cz\""
273         echo >>$m "WITH_LIBS+=$LIBRESOLV"
274 fi
275
276 if [ "$sys" = linux ] ; then
277         echo_n "Checking for libkmod... "
278         LIBKMOD_DETECTED=
279         if [ -z "$PKG_CONFIG" ] ; then
280                 PKG_CONFIG=pkg-config
281         fi
282         if [ "$LIBKMOD" != no ] ; then
283                 if ! command -v $PKG_CONFIG >/dev/null ; then
284                         echo_n "($PKG_CONFIG not found) "
285                 elif $PKG_CONFIG libkmod ; then
286                         LIBKMOD_DETECTED=1
287                 fi
288         fi
289         if [ "$LIBKMOD" = yes -o "$LIBKMOD" = no ] ; then
290                 echo "$LIBKMOD (set manually)"
291                 if [ "$LIBKMOD" = yes -a -z "$LIBKMOD_DETECTED" ] ; then
292                         echo "Requested use of libkmod, but it is not available. Giving up."
293                         exit 1
294                 fi
295         else
296                 if [ -n "$LIBKMOD_DETECTED" ] ; then
297                         LIBKMOD=yes
298                 else
299                         LIBKMOD=no
300                 fi
301                 echo "$LIBKMOD (auto-detected)"
302         fi
303         if [ "$LIBKMOD" = yes ] ; then
304                 echo >>$c "#define PCI_USE_LIBKMOD"
305                 echo >>$m "LIBKMOD_CFLAGS=$($PKG_CONFIG --cflags libkmod)"
306                 echo >>$m "LIBKMOD_LIBS=$($PKG_CONFIG --libs libkmod)"
307         fi
308
309         echo_n "Checking for udev hwdb support... "
310         if [ "$HWDB" = yes -o "$HWDB" = no ] ; then
311                 echo "$HWDB (set manually)"
312         else
313                 if `command -v $PKG_CONFIG >/dev/null && $PKG_CONFIG --atleast-version=196 libudev` ; then
314                         HWDB=yes
315                 else
316                         HWDB=no
317                 fi
318                 echo "$HWDB (auto-detected)"
319         fi
320         if [ "$HWDB" = yes ] ; then
321                 echo >>$c '#define PCI_HAVE_HWDB'
322                 echo >>$m 'LIBUDEV=-ludev'
323                 echo >>$m 'WITH_LIBS+=$(LIBUDEV)'
324         fi
325 fi
326
327 echo "Checking whether to build a shared library... $SHARED (set manually)"
328 if [ "$SHARED" = no ] ; then
329         echo >>$m 'PCILIB=$(LIBNAME).a'
330         echo >>$m 'LDLIBS=$(WITH_LIBS)'
331         echo >>$m 'LIB_LDLIBS='
332 else
333         if [ "$LIBEXT" = so ]; then
334                 echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
335         elif [ "$LIBEXT" = dll ]; then
336                 echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)'
337         else
338                 echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
339         fi
340         # We link the dependencies _to_ the library, so we do not need explicit deps in .pc
341         echo >>$m 'LDLIBS='
342         echo >>$m 'LIB_LDLIBS=$(WITH_LIBS)'
343         echo >>$c '#define PCI_SHARED_LIB'
344         if [ "$LIBEXT" = so ]; then
345                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-soname,$(LIBNAME).$(LIBEXT).$(ABI_VERSION)'
346                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver'
347         elif [ "$LIBEXT" = dylib ]; then
348                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)'
349         elif [ "$LIBEXT" = dll ]; then
350                 echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def'
351                 # GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21)
352                 echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols'
353         fi
354 fi
355 echo >>$m 'PCILIBPC=$(LIBNAME).pc'
356
357 if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then
358         echo >>$m 'PCIIMPLIB=$(PCILIB).a'
359 else
360         echo >>$m 'PCIIMPLIB=$(PCILIB)'
361 fi
362
363 echo >>$c "#define PCILIB_VERSION \"$VERSION\""
364 echo >>$c "#define PCILIB_DATE_AMIGAOS \"`echo $DATE | sed 's/\(....\)-\(..\)-\(..\)/\3.\2.\1/'`\""
365 sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m