libftdi Archives

Subject: Mingw Cross compiling

From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 6 Apr 2009 13:59:35 +0200
Hello,

sleep() and usleep(0 are not available on Win32. Provide workarounds and add
some documentation for crosscompiling. It seems, I didn't send on the first
attempt. This is my first patch with git, so if things need another form,
please let me know. 

Changelog:

- Make the exampled compile on Win32
- Some help for crosscompiling with Mingw

---
 README.mingw              |   11 +++++++++++
 Toolchain-mingw32.cmake   |   16 ++++++++++++++++
 examples/bitbang.c        |    3 +++
 examples/bitbang2.c       |    3 +++
 examples/bitbang_ft2232.c |    3 +++
 5 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 README.mingw
 create mode 100644 Toolchain-mingw32.cmake

diff --git a/README.mingw b/README.mingw
new file mode 100644
index 0000000..afc02ad
--- /dev/null
+++ b/README.mingw
@@ -0,0 +1,11 @@
+To crosscompile for Win32 with mingw
+- Get and build libusb-win32-src-x.tar.gz from Sourceforge
+  Version was "libusb-win32-src-0.1.12.1.tar.gz" for April 4, 2009
+- Compile like  "make host_prefix=i386-mingw32msvc all". Your prefixes may 
vary.
+- Copy src/usb.h to /opt/cross/i386-mingw32msvc/include/
+- Copy *.a to /opt/cross/i386-mingw32msvc/lib/
+- Create a build directory like "mkdir build-win32", e.g in ../libftdi/
+- cd in that directory and run  
+  "cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-mingw32.cmake .."
+- Copy src/ftdi.h to /opt/cross/i386-mingw32msvc/include/
+- Copy build-win32/src/*.a to /opt/cross/i386-mingw32msvc/lib/
\ No newline at end of file
diff --git a/Toolchain-mingw32.cmake b/Toolchain-mingw32.cmake
new file mode 100644
index 0000000..bff3cba
--- /dev/null
+++ b/Toolchain-mingw32.cmake
@@ -0,0 +1,16 @@
+# the name of the target operating system
+SET(CMAKE_SYSTEM_NAME Windows)
+
+# which compilers to use for C and C++
+SET(CMAKE_C_COMPILER i386-mingw32msvc-gcc)
+SET(CMAKE_CXX_COMPILER i386-mingw32msvc-g++)
+
+# here is the target environment located
+SET(CMAKE_FIND_ROOT_PATH  /opt/cross/i386-mingw32msvc )
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search 
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/examples/bitbang.c b/examples/bitbang.c
index 4a3a823..2326605 100644
--- a/examples/bitbang.c
+++ b/examples/bitbang.c
@@ -2,6 +2,9 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#ifdef __WIN32__
+#define sleep(x) Sleep(x)
+#endif
 #include <ftdi.h>
 
 int main(int argc, char **argv)
diff --git a/examples/bitbang2.c b/examples/bitbang2.c
index 81b3963..d9ba439 100644
--- a/examples/bitbang2.c
+++ b/examples/bitbang2.c
@@ -31,6 +31,9 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#ifdef __WIN32__
+#define usleep(x) Sleep((x+999)/1000)
+#endif
 #include <ftdi.h>
 
 void ftdi_fatal (struct ftdi_context *ftdi, char *str)
diff --git a/examples/bitbang_ft2232.c b/examples/bitbang_ft2232.c
index cb09f0d..9d62ac0 100644
--- a/examples/bitbang_ft2232.c
+++ b/examples/bitbang_ft2232.c
@@ -10,6 +10,9 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#ifdef __WIN32__
+#define sleep(x) _sleep(x)
+#endif
 #include <ftdi.h>
 
 int main(int argc, char **argv)
-- 
1.6.0.2


-- 
Uwe Bonnes                bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread