automate cross compile for windows in win32

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@769 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2012-04-14 00:51:11 +00:00
parent fd243987a1
commit 248281dd9f
4 changed files with 324 additions and 42 deletions

View File

@@ -1,46 +1,7 @@
SUBDIRS=src doc
SUBDIRS=src doc win32
LIBUSB_WIN32_BIN_VERSION=1.2.6.0
LIBUSB_WIN32_BIN_DIR=libusb-win32-bin-$(LIBUSB_WIN32_BIN_VERSION)
LIBUSB_DLL=$(abs_builddir)/$(LIBUSB_WIN32_BIN_DIR)/bin/x86/libusb0_x86.dll
LIBUSB_WIN32_BIN_ARCHIVE=$(LIBUSB_WIN32_BIN_DIR).zip
$(LIBUSB_WIN32_BIN_ARCHIVE):
wget http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$(LIBUSB_WIN32_BIN_VERSION)/$(LIBUSB_WIN32_BIN_ARCHIVE)
$(LIBUSB_DLL): $(LIBUSB_WIN32_BIN_ARCHIVE)
unzip $<
LIBNFC_DIR=$(abs_builddir)/libnfc
LIBNFC_DLL=$(LIBNFC_DIR)/libnfc.dll
$(LIBNFC_DIR):
svn co http://libnfc.googlecode.com/svn/trunk $@
$(LIBNFC_DLL): $(LIBNFC_DIR) $(LIBUSB_DLL)
cd $< && wget http://www2.informatik.hu-berlin.de/~morgner/libnfc.dll
MINGW ?= i686-w64-mingw32
MINGW_DIR=/usr/$(MINGW)
PCSC_RELAY_EXE=$(abs_builddir)/src/pcsc-relay.exe
$(PCSC_RELAY_EXE): $(LIBNFC_DIR) $(LIBNFC_DLL)
./configure --host=$(MINGW) --build=`config.guess` \
PKG_CONFIG_LIBDIR=$(MINGW_DIR)/lib/pkgconfig \
CFLAGS=-I$(MINGW_DIR)/include \
LDFLAGS=-L$(MINGW_DIR)/lib \
PCSC_LIBS="-lwinscard" \
LIBNFC_CFLAGS="-I$(LIBNFC_DIR)/include" \
LIBNFC_LIBS="$(LIBNFC_DLL)"
make
WIN32_DIR=$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)_win32
win: $(PCSC_RELAY_EXE)
mkdir -p $(WIN32_DIR)
for i in \
$(LIBNFC_DLL) \
$(PCSC_RELAY_EXE) \
; do cp $${i} $(WIN32_DIR); done
cp $(LIBUSB_DLL) $(WIN32_DIR)/libusb0.dll
win:
make -C win32 $@
dist-hook:
test -d .svn && \

View File

@@ -96,5 +96,6 @@ EOF
AC_CONFIG_FILES([Makefile
doc/Makefile
win32/Makefile
src/Makefile])
AC_OUTPUT

View File

@@ -0,0 +1,48 @@
EXTRA_DIST = libnfc_mingw.patch
all-local:
echo "Use \`make win\` to cross compile for Windows"
IMAGE=$(abs_builddir)/image
LIBNFC_DIR=$(abs_builddir)/libnfc
LIBNFC_DLL=$(IMAGE)/bin/libnfc-3.dll
$(LIBNFC_DIR):
svn co -r1327 http://libnfc.googlecode.com/svn/trunk $@
$(LIBNFC_DLL): $(LIBNFC_DIR)
grep i686-w64-mingw32 $(LIBNFC_DIR)/mingw-cross-configure.sh > /dev/null || \
patch -p0 -d $< < libnfc_mingw.patch
cd $< && sh mingw-cross-configure.sh --prefix=$(IMAGE)
make -C $< install
MINGW ?= i686-w64-mingw32
MINGW_DIR=/usr/$(MINGW)
PCSC_RELAY_EXE=$(IMAGE)/bin/pcsc-relay.exe
$(PCSC_RELAY_EXE): $(LIBNFC_DIR) $(LIBNFC_DLL)
cd $(abs_top_builddir) && ./configure \
--prefix=$(IMAGE) \
--host=$(MINGW) --target=$(MINGW) \
PKG_CONFIG_LIBDIR=$(IMAGE)/lib/pkgconfig \
CFLAGS=-I$(MINGW_DIR)/include \
LDFLAGS=-L$(MINGW_DIR)/lib \
PCSC_LIBS="-lwinscard"
make -C $(abs_top_builddir) install
LIBUSB_DLL=$(LIBNFC_DIR)/libusb-win32-bin-*/bin/x86/libusb0_x86.dll
WIN32_DIR=$(abs_top_builddir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)_win32
win: $(PCSC_RELAY_EXE)
$(INSTALL_PROGRAM) -t $(WIN32_DIR) \
$(LIBNFC_DLL) $(PCSC_RELAY_EXE)
$(INSTALL_PROGRAM) $(LIBUSB_DLL) $(WIN32_DIR)/libusb0.dll
clean-local:
rm -rf $(IMAGE) $(WIN32_DIR)
make -C $(LIBNFC_DIR) clean
distclean-local:
rm -rf $(LIBNFC_DIR)

View File

@@ -0,0 +1,272 @@
Index: examples/pn53x-tamashell.c
===================================================================
--- examples/pn53x-tamashell.c (Revision 1327)
+++ examples/pn53x-tamashell.c (Arbeitskopie)
@@ -76,7 +76,6 @@
uint8_t abtTx[MAX_FRAME_LEN];
size_t szRx = sizeof(abtRx);
size_t szTx;
- extern FILE* stdin;
FILE* input = NULL;
if (argc >= 2) {
Index: libnfc/nfc-internal.c
===================================================================
--- libnfc/nfc-internal.c (Revision 1327)
+++ libnfc/nfc-internal.c (Arbeitskopie)
@@ -22,6 +22,7 @@
* @brief Provide some useful internal functions
*/
+#define nfc_EXPORTS
#include <nfc/nfc.h>
void
Index: libnfc/chips/pn53x.c
===================================================================
--- libnfc/chips/pn53x.c (Revision 1327)
+++ libnfc/chips/pn53x.c (Arbeitskopie)
@@ -37,6 +37,7 @@
#include <sys/param.h>
+#define nfc_EXPORTS
#include "nfc/nfc.h"
#include "nfc-internal.h"
#include "pn53x.h"
Index: libnfc/drivers/acr122s.c
===================================================================
--- libnfc/drivers/acr122s.c (Revision 1327)
+++ libnfc/drivers/acr122s.c (Arbeitskopie)
@@ -35,6 +35,7 @@
#include <string.h>
#include <unistd.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "drivers.h"
Index: libnfc/drivers/arygon.c
===================================================================
--- libnfc/drivers/arygon.c (Revision 1327)
+++ libnfc/drivers/arygon.c (Arbeitskopie)
@@ -42,6 +42,7 @@
#include <string.h>
#include <unistd.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "drivers.h"
Index: libnfc/drivers/pn532_uart.c
===================================================================
--- libnfc/drivers/pn532_uart.c (Revision 1327)
+++ libnfc/drivers/pn532_uart.c (Arbeitskopie)
@@ -36,6 +36,7 @@
#include <string.h>
#include <unistd.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "drivers.h"
Index: libnfc/drivers/pn53x_usb.c
===================================================================
--- libnfc/drivers/pn53x_usb.c (Revision 1327)
+++ libnfc/drivers/pn53x_usb.c (Arbeitskopie)
@@ -50,8 +50,13 @@
#define _usb_strerror( X ) usb_strerror()
#endif
+#ifdef _WIN32
+ #include "contrib/windows.h"
+#endif
+
#include <string.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "nfc-internal.h"
Index: libnfc/drivers/acr122.c
===================================================================
--- libnfc/drivers/acr122.c (Revision 1327)
+++ libnfc/drivers/acr122.c (Arbeitskopie)
@@ -32,6 +32,7 @@
#include <stddef.h>
#include <string.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "chips/pn53x.h"
Index: libnfc/buses/uart.c
===================================================================
--- libnfc/buses/uart.c (Revision 1327)
+++ libnfc/buses/uart.c (Arbeitskopie)
@@ -29,6 +29,7 @@
#include "uart.h"
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "nfc-internal.h"
Index: libnfc/nfc-emulation.c
===================================================================
--- libnfc/nfc-emulation.c (Revision 1327)
+++ libnfc/nfc-emulation.c (Arbeitskopie)
@@ -22,6 +22,11 @@
* @brief Provide a small API to ease emulation in libnfc
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif // HAVE_CONFIG_H
+
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include <nfc/nfc-emulation.h>
Index: libnfc/iso14443-subr.c
===================================================================
--- libnfc/iso14443-subr.c (Revision 1327)
+++ libnfc/iso14443-subr.c (Arbeitskopie)
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
Index: libnfc/nfc.c
===================================================================
--- libnfc/nfc.c (Revision 1327)
+++ libnfc/nfc.c (Arbeitskopie)
@@ -73,6 +73,7 @@
#include <stddef.h>
#include <string.h>
+#define nfc_EXPORTS
#include <nfc/nfc.h>
#include "nfc-internal.h"
@@ -80,6 +81,10 @@
#include <sys/param.h>
+#ifdef _WIN32
+# include "contrib/windows.h"
+#endif
+
#define LOG_CATEGORY "libnfc.general"
const struct nfc_driver *nfc_drivers[] = {
Index: utils/nfc-read-forum-tag3.c
===================================================================
--- utils/nfc-read-forum-tag3.c (Revision 1327)
+++ utils/nfc-read-forum-tag3.c (Arbeitskopie)
@@ -51,11 +51,16 @@
#include <stdlib.h>
#include <sys/param.h>
#include <unistd.h>
+#include <getopt.h>
#include <nfc/nfc.h>
#include "nfc-utils.h"
+#ifdef _WIN32
+# include "contrib/windows.h"
+#endif
+
static nfc_device *pnd;
void
Index: mingw-cross-configure.sh
===================================================================
--- mingw-cross-configure.sh (Revision 1327)
+++ mingw-cross-configure.sh (Arbeitskopie)
@@ -1,8 +1,8 @@
#!/bin/sh
-WITH_USB=0
+WITH_USB=1
-LIBUSB_WIN32_BIN_VERSION="1.2.2.0"
+LIBUSB_WIN32_BIN_VERSION="1.2.6.0"
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
@@ -14,7 +14,8 @@
fi
fi
-MINGW_DIR="/usr/i586-mingw32msvc"
+MINGW="${MINGW:=i686-w64-mingw32}"
+MINGW_DIR="/usr/$MINGW"
# Use MinGW binaries before others
#export PATH=$MINGW_DIR/bin:$PATH
@@ -33,11 +34,58 @@
# Include default MinGW include directory, and libnfc's win32 files
export CFLAGS="$CFLAGS -I$MINGW_DIR/include -I$PWD/contrib/win32"
+if [ "$MINGW" = "i686-w64-mingw32" ]; then
+ # mingw-64 includes winscard.a and winscard.h
+ #
+ # It is not enough to set libpcsclite_LIBS to "-lwinscard", because it is
+ # forgotten when libnfc is created with libtool. That's why we are setting
+ # LIBS.
+ export LIBS="-lwinscard"
+
+ echo "MinGW-w64 ships all requirements libnfc."
+ echo "Unfortunately the MinGW-w64 header are currently"
+ echo "buggy. Also, Libtool doesn't support MinGW-w64"
+ echo "very well."
+ echo ""
+ echo "Warning ________________________________________"
+ echo "You will only be able to compile libnfc.dll, but"
+ echo "none of the executables (see utils and examples)."
+ echo ""
+ # You can fix winbase.h by adding the following lines:
+ # #include <basetsd.h>
+ # #include <windef.h>
+ # But the problem with Libtool remains.
+else
+ if [ -z "$libpcsclite_LIBS$libpcsclite_CFLAGS" ]; then
+ echo "Error __________________________________________"
+ echo "You need to get the PC/SC library from a Windows"
+ echo "machine and the appropriate header files. Then"
+ echo "specify libpcsclite_LIBS=.../WinScard.dll and"
+ echo "libpcsclite_CFLAGS=-I..."
+ fi
+ exit 1
+fi
+
## Configure to cross-compile using mingw32msvc
if [ "$WITH_USB" = "1" ]; then
# with direct-USB drivers (use libusb-win32)
- ./configure --target=i586-mingw32msvc --host=i586-mingw32msvc --with-drivers=pn531_usb,pn533_usb,pn532_uart,arygon --with-libusb-win32=$PWD/$LIBUSB_WIN32_BIN_DIR $*
+ DRIVERS="all"
else
# with UART divers only (can be tested under wine)
- ./configure --target=i586-mingw32msvc --host=i586-mingw32msvc --with-drivers=pn532_uart,arygon $*
+ DRIVERS="pn532_uart,arygon"
fi
+
+if [ ! -x configure ]; then
+ autoreconf -is
+fi
+
+./configure --target=$MINGW --host=$MINGW \
+ --with-drivers=$DRIVERS \
+ --with-libusb-win32=$PWD/$LIBUSB_WIN32_BIN_DIR \
+ $*
+
+if [ "$MINGW" = "i686-w64-mingw32" ]; then
+ # due to the buggy headers from MINGW-64 we always add "contrib/windows.h",
+ # otherwise some windows types won't be available.
+ echo "#include \"contrib/windows.h\"" >> config.h
+fi