OCaml sources uses separate Makefile and Makefile.nt in each directory, which is a pain when cross-compiling. Instead of that, it's better to combine all objects into one Makefile, and make sure the source is defended by #ifdef/#ifndef WIN32 ... #endif, around the whole files as necessary. diff -urN ocaml-3.11.0+beta1.orig/asmrun/Makefile ocaml-3.11.0+beta1.mingw/asmrun/Makefile --- ocaml-3.11.0+beta1.orig/asmrun/Makefile 2007-11-15 13:21:15.000000000 +0000 +++ ocaml-3.11.0+beta1.mingw/asmrun/Makefile 2008-11-15 14:43:50.000000000 +0000 @@ -26,7 +26,7 @@ misc.o freelist.o major_gc.o minor_gc.o memory.o alloc.o compare.o ints.o \ floats.o str.o array.o io.o extern.o intern.o hash.o sys.o parsing.o \ gc_ctrl.o terminfo.o md5.o obj.o lexing.o printexc.o callback.o weak.o \ - compact.o finalise.o custom.o unix.o backtrace.o natdynlink.o + compact.o finalise.o custom.o unix.o win32.o backtrace.o natdynlink.o ASMOBJS=$(ARCH).o @@ -138,6 +138,8 @@ ln -s ../byterun/globroots.c globroots.c unix.c: ../byterun/unix.c ln -s ../byterun/unix.c unix.c +win32.c: ../byterun/win32.c + ln -s ../byterun/win32.c win32.c dynlink.c: ../byterun/dynlink.c ln -s ../byterun/dynlink.c dynlink.c signals.c: ../byterun/signals.c @@ -146,7 +148,7 @@ LINKEDFILES=misc.c freelist.c major_gc.c minor_gc.c memory.c alloc.c array.c \ compare.c ints.c floats.c str.c io.c extern.c intern.c hash.c sys.c \ parsing.c gc_ctrl.c terminfo.c md5.c obj.c lexing.c printexc.c callback.c \ - weak.c compact.c finalise.c meta.c custom.c main.c globroots.c unix.c \ + weak.c compact.c finalise.c meta.c custom.c main.c globroots.c unix.c win32.c \ dynlink.c signals.c clean:: diff --exclude _build -urN ocaml-3.11.0+beta1.orig/byterun/Makefile.common ocaml-3.11.0+beta1.mingw/byterun/Makefile.common --- ocaml-3.11.0+beta1.orig/byterun/Makefile.common 2008-09-10 06:51:11.000000000 +0100 +++ ocaml-3.11.0+beta1.mingw/byterun/Makefile.common 2008-11-15 15:47:05.000000000 +0000 @@ -24,7 +24,7 @@ compare.o ints.o floats.o str.o array.o io.o extern.o intern.o \ hash.o sys.o meta.o parsing.o gc_ctrl.o terminfo.o md5.o obj.o \ lexing.o callback.o debugger.o weak.o compact.o finalise.o custom.o \ - dynlink.o + dynlink.o win32.o PRIMS=\ alloc.c array.c compare.c extern.c floats.c gc_ctrl.c hash.c \ diff --exclude _build -urN ocaml-3.11.0+beta1.orig/byterun/unix.c ocaml-3.11.0+beta1.mingw/byterun/unix.c --- ocaml-3.11.0+beta1.orig/byterun/unix.c 2008-04-22 13:40:14.000000000 +0100 +++ ocaml-3.11.0+beta1.mingw/byterun/unix.c 2008-11-15 14:44:12.000000000 +0000 @@ -15,6 +15,8 @@ /* Unix-specific stuff */ +#ifndef WIN32 + #define _GNU_SOURCE /* Helps finding RTLD_DEFAULT in glibc */ @@ -320,3 +322,5 @@ } #endif + +#endif /* !WIN32 */ diff --exclude _build -urN ocaml-3.11.0+beta1.orig/byterun/win32.c ocaml-3.11.0+beta1.mingw/byterun/win32.c --- ocaml-3.11.0+beta1.orig/byterun/win32.c 2008-04-22 13:24:10.000000000 +0100 +++ ocaml-3.11.0+beta1.mingw/byterun/win32.c 2008-11-15 15:50:32.000000000 +0000 @@ -13,6 +13,8 @@ /* $Id: win32.c,v 1.36 2008/04/22 12:24:10 frisch Exp $ */ +#ifdef WIN32 + /* Win32-specific stuff */ #include @@ -543,3 +564,5 @@ seed ^= GetCurrentProcessId(); return seed; } + +#endif /* WIN32 */ diff --exclude _build -urN ocaml-3.11.0+beta1.orig/otherlibs/systhreads/Makefile ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/Makefile --- ocaml-3.11.0+beta1.orig/otherlibs/systhreads/Makefile 2008-07-15 16:31:32.000000000 +0100 +++ ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/Makefile 2008-11-15 15:51:58.000000000 +0000 @@ -20,8 +20,8 @@ MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib COMPFLAGS=-warn-error A -g -BYTECODE_C_OBJS=posix_b.o -NATIVECODE_C_OBJS=posix_n.o +BYTECODE_C_OBJS=posix_b.o win32_b.o +NATIVECODE_C_OBJS=posix_n.o win32_n.o THREAD_OBJS= thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo @@ -39,6 +39,10 @@ -c posix.c mv posix.o posix_b.o +win32_b.$(O): win32.c + $(BYTECC) -I ../../byterun $(BYTECCCOMPOPTS) $(CFLAGS) -c win32.c + mv win32.$(O) win32_b.$(O) + # Dynamic linking with -lpthread is risky on many platforms, so # do not create a shared object for libthreadsnat. libthreadsnat.a: $(NATIVECODE_C_OBJS) @@ -48,9 +52,13 @@ $(NATIVECC) -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) -c posix.c mv posix.o posix_n.o +win32_n.$(O): win32.c + $(NATIVECC) -DNATIVE_CODE -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) -c win32.c + mv win32.$(O) win32_n.$(O) + threads.cma: $(THREAD_OBJS) $(MKLIB) -ocamlc '$(CAMLC)' -o threads $(THREAD_OBJS) \ - -cclib -lunix $(PTHREAD_LINK) + -cclib -lunix $(PTHREAD_LINK) -lcamlrun # See remark above: force static linking of libthreadsnat.a threads.cmxa: $(THREAD_OBJS:.cmo=.cmx) diff --exclude _build -urN ocaml-3.11.0+beta1.orig/otherlibs/systhreads/posix.c ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/posix.c --- ocaml-3.11.0+beta1.orig/otherlibs/systhreads/posix.c 2008-09-27 11:46:55.000000000 +0100 +++ ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/posix.c 2008-11-15 15:35:28.000000000 +0000 @@ -13,6 +13,8 @@ /* $Id: posix.c,v 1.58 2008/09/27 10:46:55 xleroy Exp $ */ +#ifndef WIN32 + /* Thread interface for POSIX 1003.1c threads */ #include @@ -924,3 +926,4 @@ raise_sys_error(str); } +#endif /* !WIN32 */ diff --exclude _build -urN ocaml-3.11.0+beta1.orig/otherlibs/systhreads/win32.c ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/win32.c --- ocaml-3.11.0+beta1.orig/otherlibs/systhreads/win32.c 2007-10-31 09:12:29.000000000 +0000 +++ ocaml-3.11.0+beta1.mingw/otherlibs/systhreads/win32.c 2008-11-15 15:35:47.000000000 +0000 @@ -13,6 +13,8 @@ /* $Id: win32.c,v 1.45 2007/10/31 09:12:29 xleroy Exp $ */ +#ifdef WIN32 + /* Thread interface for Win32 threads */ #include @@ -662,3 +664,6 @@ sprintf(errmsg, "%s: error code %lx", msg, GetLastError()); raise_sys_error(copy_string(errmsg)); } + +#endif /* WIN32 */ +