endif
AR=$(CROSS_COMPILE)ar
RANLIB=$(CROSS_COMPILE)ranlib
+DLLTOOL=$(CROSS_COMPILE)dlltool
# Base name of the library (overridden on NetBSD, which has its own libpci)
LIBNAME=libpci
clean:
rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
- rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags
+ rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* lib/*.dll lib/*.def tags
rm -rf maint/dist
distclean: clean
ifeq ($(SHARED),yes)
ifeq ($(LIBEXT),dylib)
ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
-else
+else ifeq ($(LIBEXT),so)
ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
endif
endif
install-pcilib: lib/$(PCILIB)
$(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
+ifeq ($(SHARED)_$(LIBEXT),yes_dll)
+# DLL library must have executable flag on disk and be placed in same directory as where are EXE files
+ $(DIRINSTALL) -m 755 $(DESTDIR)$(SBINDIR)
+ $(INSTALL) -c -m 755 lib/$(PCILIB) $(DESTDIR)$(SBINDIR)
+else
$(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
+endif
install-lib: $(PCIINC_INS) install-pcilib
$(DIRINSTALL) -m 755 $(DESTDIR)$(INCDIR)/pci $(DESTDIR)$(PKGCFDIR)
ifneq ($(PCIIMPLIB),$(PCILIB))
$(INSTALL) -c -m 644 lib/$(PCIIMPLIB) $(DESTDIR)$(LIBDIR)
endif
+ifneq ($(PCIIMPDEF),)
+ $(INSTALL) -c -m 644 lib/$(PCIIMPDEF) $(DESTDIR)$(LIBDIR)
+endif
ifeq ($(SHARED),yes)
ifeq ($(LIBEXT),dylib)
ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
ln -sf $(LIBNAME).$(ABI_VERSION).$(LIBEXT) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
-else
+else ifeq ($(LIBEXT),so)
ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
ln -sf $(LIBNAME).$(LIBEXT).$(ABI_VERSION) $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
endif
rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8
rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7
rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5
+ifeq ($(SHARED)_$(LIBEXT),yes_dll)
+ rm -f $(DESTDIR)$(SBINDIR)/$(PCILIB)
+else
rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
+endif
rm -f $(DESTDIR)$(PKGCFDIR)/$(PCILIBPC)
rm -f $(addprefix $(DESTDIR)$(INCDIR)/pci/,$(notdir $(PCIINC_INS)))
ifneq ($(PCIIMPLIB),$(PCILIB))
rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPLIB)
endif
+ifneq ($(PCIIMPDEF),)
+ rm -f $(DESTDIR)$(LIBDIR)/$(PCIIMPDEF)
+endif
ifeq ($(SHARED),yes)
+ifneq ($(LIBEXT),dll)
rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT)
ifeq ($(LIBEXT),dylib)
rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(ABI_VERSION).$(LIBEXT)
rm -f $(DESTDIR)$(LIBDIR)/$(LIBNAME).$(LIBEXT).$(ABI_VERSION)
endif
endif
+endif
pci.ids.gz: pci.ids
gzip -9n <$< >$@
$(AR) rcs $@ $^
$(RANLIB) $@
else
+ifeq ($(LIBEXT),dll)
+all: $(PCIIMPDEF) $(PCIIMPLIB)
+build.def: $(PCIIMPDEF)
+$(PCIIMPDEF): libpci.ver ver2def.pl
+ perl ver2def.pl libpci.ver $(PCILIB) build.def $(PCIIMPDEF)
+$(PCIIMPLIB): $(PCIIMPDEF)
+ $(DLLTOOL) --input-def $< --output-lib $@
+endif
CFLAGS += -fPIC -fvisibility=hidden
$(PCILIB): $(addsuffix .o,$(OBJS))
$(CC) -shared $(CFLAGS) $(LDFLAGS) $(PCILIB_LDFLAGS) -o $@ $^ $(LIB_LDLIBS)
+ifeq ($(LIBEXT),dll)
+$(PCILIB): build.def
+endif
endif
$(PCILIBPC): libpci.pc.in
fi
;; esac
EXEEXT=.exe
+ LIBEXT=dll
;;
beos|haiku)
case $cpu in
else
if [ "$LIBEXT" = so ]; then
echo >>$m 'PCILIB=$(LIBNAME).$(LIBEXT).$(VERSION)'
+ elif [ "$LIBEXT" = dll ]; then
+ echo >>$m 'PCILIB=$(LIBNAME)$(ABI_VERSION).$(LIBEXT)'
else
echo >>$m 'PCILIB=$(LIBNAME).$(VERSION).$(LIBEXT)'
fi
echo >>$m 'PCILIB_LDFLAGS+=-Wl,--version-script=libpci.ver'
elif [ "$LIBEXT" = dylib ]; then
echo >>$m 'PCILIB_LDFLAGS+=-Wl,-install_name,$(LIBDIR)/$(PCILIB)'
+ elif [ "$LIBEXT" = dll ]; then
+ echo >>$m 'PCIIMPDEF=$(LIBNAME)$(ABI_VERSION).def'
+ # GCC's -fvisibility=hidden is broken for Windows targets, use -Wl,--exclude-all-symbols instead (supported since GNU LD 2.21)
+ echo >>$m 'PCILIB_LDFLAGS+=-Wl,--exclude-all-symbols'
fi
fi
echo >>$m 'PCILIBPC=$(LIBNAME).pc'
-echo >>$m 'PCIIMPLIB=$(PCILIB)'
+if [ "$SHARED" != no ] && [ "$LIBEXT" = dll ]; then
+ echo >>$m 'PCIIMPLIB=$(PCILIB).a'
+else
+ echo >>$m 'PCIIMPLIB=$(PCILIB)'
+fi
echo >>$c "#define PCILIB_VERSION \"$VERSION\""
sed '/"/{s/^#define \([^ ]*\) "\(.*\)"$/\1=\2/;p;d;};s/^#define \(.*\)/\1=1/' <$c >>$m
#else
#define STATIC_ALIAS(_decl, _for)
#define DEFINE_ALIAS(_decl, _for) extern _decl __attribute__((alias(#_for)))
+#ifdef _WIN32
+/* GCC does not support asm .symver directive for Windows targets, so define new external global function symbol as alias to internal symbol */
+#define SYMBOL_VERSION(_int, _ext) asm(".globl\t" PCI_STRINGIFY(__MINGW_USYMBOL(_ext)) "\n\t" \
+ ".def\t" PCI_STRINGIFY(__MINGW_USYMBOL(_ext)) ";\t.scl\t2;\t.type\t32;\t.endef\n\t" \
+ ".set\t" PCI_STRINGIFY(__MINGW_USYMBOL(_ext)) "," PCI_STRINGIFY(__MINGW_USYMBOL(_int)))
+#else
#define SYMBOL_VERSION(_int, _ext) asm(".symver " #_int "," #_ext)
#endif
+#endif
#else
#define VERSIONED_ABI
#define STATIC_ALIAS(_decl, _for) _decl { return _for; }
#include "pci.h"
#include "sysdep.h"
+/* Old 32-bit-only versions of MinGW32 do not define __MINGW_USYMBOL macro */
+#ifdef __MINGW32__
+#ifndef __MINGW_USYMBOL
+#define __MINGW_USYMBOL(sym) _##sym
+#endif
+#endif
+
+#define _PCI_STRINGIFY(x) #x
+#define PCI_STRINGIFY(x) _PCI_STRINGIFY(x)
+
struct pci_methods {
char *name;
char *help;
* Visibility declarations in the source take precedence over this script,
* so we can boldly declare pci_* as public and still keep the internal
* functions properly hidden.
+ *
+ * To preserve compatibility of Windows DLL file, always add new symbol at
+ * the end of file and never change order of symbols nor version sections.
+ * On Windows the last referenced version of the symbol is the default one.
+
+ * For PE/COFF targets this file is processed by ver2def.pl script and not
+ * by GNU LD linker like for ELF targets.
*/
LIBPCI_3.0 {
--- /dev/null
+#!/usr/bin/perl
+use strict;
+use warnings;
+die "Usage: $0 script.ver dllname build.def import.def\n" if @ARGV != 4;
+my ($verfile, $dllname, $builddef, $importdef) = @ARGV;
+open my $verfh, '<', $verfile or die "Cannot open input file $verfile: $!\n";
+my $input = join '', <$verfh>;
+close $verfh;
+my @syms;
+my (%cnt, %last, %ords);
+$input =~ s/\/\*.*?\*\///sg; # Remove C comments
+while ($input =~ m/(\S+)\s*\{((?:[^\{\}]|\{(?2)\})+)\}\s*;/sg) { # Split {...}
+ my ($ver, $block) = ($1, $2);
+ while ($block =~ s/(\S+)\s*:((?:[^\{\}:]|\{(?2)\})+)$//sg) { # Split section:
+ my ($section, $syms) = ($1, $2);
+ next if $section ne 'global';
+ $syms =~ s/\s+//g;
+ foreach (split /;\s*/, $syms) { # Split symbols
+ $cnt{$_}++;
+ $last{$_} = $ver;
+ push @syms, [$_, $ver];
+ }
+ }
+}
+open my $importfh, '>', $importdef or die "Cannot open output file $importdef: $!\n";
+open my $buildfh, '>', $builddef or die "Cannot open output file $builddef: $!\n";
+print $importfh "LIBRARY \"$dllname\"\n";
+print $importfh "EXPORTS\n";
+print $buildfh "EXPORTS\n";
+my $ord = 1;
+foreach (@syms) {
+ my ($sym, $ver) = @{$_};
+ print $importfh "\"$sym\@$ver\" \@$ord\n";
+ if ($last{$sym} ne $ver) {
+ print $buildfh "\"$sym\@$ver\" \@$ord\n";
+ } else {
+ $ords{$sym} = $ord;
+ print $buildfh "\"$sym\@$ver\" = " . (($cnt{$sym} > 1) ? "\"$sym\@\@$ver\"" : $sym) . " \@$ord\n"
+ }
+ $ord++;
+}
+# GNU dlltool has broken calculation of ordinals for aliased symbols, so specify ordinals explicitly
+# GNU LD prior 2.21 has broken handling of symbols with dot character
+# Operator == for defining symbol alias is supported since GNU dlltool 2.21
+print $importfh "$_ \@$ords{$_} == \"$_\@$last{$_}\"\n" foreach sort keys %last;
+close $importfh;
+close $buildfh;