Mingw Cross compiling
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Mon, 6 Apr 2009 11:59:35 +0000 (13:59 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 6 Apr 2009 12:56:31 +0000 (14:56 +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 [new file with mode: 0644]
Toolchain-mingw32.cmake [new file with mode: 0644]
examples/bitbang.c
examples/bitbang2.c
examples/bitbang_ft2232.c

diff --git a/README.mingw b/README.mingw
new file mode 100644 (file)
index 0000000..afc02ad
--- /dev/null
@@ -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 (file)
index 0000000..bff3cba
--- /dev/null
@@ -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)
index 4a3a823..2326605 100644 (file)
@@ -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)
index 81b3963..d9ba439 100644 (file)
@@ -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)
index cb09f0d..9d62ac0 100644 (file)
@@ -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)