summaryrefslogtreecommitdiffstats
path: root/src/ocaml-core-1-fixes.patch
blob: dfe9bd51adc10d8c5fd113b468ee05fed0f317a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
This file is part of MXE. See LICENSE.md for licensing information.

Contains ad hoc patches for cross building.

From 002715e4bdd4f2aacb6ce8b1b89bae734b6c36fc Mon Sep 17 00:00:00 2001
From: MXE
Date: Wed, 13 Jun 2012 22:27:54 +0200
Subject: [PATCH] various patches to build an ocaml cross compiler


diff --git a/Makefile b/Makefile
index e53fd0d..0decd00 100644
--- a/Makefile
+++ b/Makefile
@@ -289,16 +289,17 @@ install:
 	for i in $(OTHERLIBRARIES); do \
 	  (cd otherlibs/$$i; $(MAKE) install) || exit $$?; \
 	done
-	cd ocamldoc; $(MAKE) install
+	# cd ocamldoc; $(MAKE) install
 	if test -f ocamlopt; then $(MAKE) installopt; else :; fi
 	if test -f debugger/ocamldebug; then (cd debugger; $(MAKE) install); \
 	   else :; fi
 	cp config/Makefile $(LIBDIR)/Makefile.config
-	BINDIR=$(BINDIR) LIBDIR=$(LIBDIR) PREFIX=$(PREFIX) \
-	  ./build/partial-install.sh
+	#BINDIR=$(BINDIR) LIBDIR=$(LIBDIR) PREFIX=$(PREFIX) \
+	#  ./build/partial-install.sh
 
 # Installation of the native-code compiler
 installopt:
+	if test -d $(COMPLIBDIR); then : ; else $(MKDIR) $(COMPLIBDIR); fi
 	cd asmrun; $(MAKE) install
 	cp ocamlopt $(BINDIR)/ocamlopt$(EXE)
 	cd stdlib; $(MAKE) installopt
@@ -737,7 +738,7 @@ ocamlbuild.native: ocamlopt ocamlbuild-mixed-boot
 ocamlbuildlib.native: ocamlopt ocamlbuild-mixed-boot
 	./build/ocamlbuildlib-native-only.sh
 
-ocamlbuild-mixed-boot: ocamlc
+ocamlbuild-mixed-boot: ocamlc otherlibraries
 	./build/mixed-boot.sh
 	touch ocamlbuild-mixed-boot
 
diff --git a/Makefile-mingw.in b/Makefile-mingw.in
new file mode 100644
index 0000000..c3dddf6
--- /dev/null
+++ b/Makefile-mingw.in
@@ -0,0 +1,160 @@
+######### General configuration
+
+PREFIX=@prefix@
+
+### Remove this to disable compiling camlp4
+#CAMLP4=camlp4
+
+### Where to install the binaries
+BINDIR=$(PREFIX)/bin
+
+### Where to install the standard library
+LIBDIR=$(PREFIX)/lib/ocaml
+
+### Where to install the stub DLLs
+STUBLIBDIR=$(LIBDIR)/stublibs
+
+### Where to install the info files
+DISTRIB=$(PREFIX)
+
+### Where to install the man pages
+MANDIR=$(PREFIX)/man
+
+########## Toolchain and OS dependencies
+
+TOOLCHAIN=cc
+
+### Toolchain prefix
+TOOLPREF=@toolpref@-
+
+CCOMPTYPE=cc
+O=o
+A=a
+S=s
+SO=dll
+EXE=
+EXT_DLL=.dll
+EXT_OBJ=.$(O)
+EXT_LIB=.$(A)
+EXT_ASM=.$(S)
+MANEXT=1
+SHARPBANGSCRIPTS=true
+PTHREAD_LINK=
+X11_INCLUDES=
+X11_LINK=
+DBM_INCLUDES=
+DBM_LINK=
+BYTECCRPATH=
+SUPPORTS_SHARED_LIBRARIES=true
+SHAREDCCCOMPOPTS=
+MKSHAREDLIBRPATH=
+NATIVECCPROFOPTS=-pg
+NATIVECCRPATH=
+ASM=$(TOOLPREF)as
+ASPP=$(TOOLPREF)gcc -c
+ASPPPROFFLAGS=-DPROFILING
+PROFILING=prof
+DYNLINKOPTS=-ldl
+DEBUGGER=ocamldebugger
+CC_PROFILE=-pg
+SYSTHREAD_SUPPORT=true
+EXTRALIBS=
+NATDYNLINK=true
+NATDYNLINKOPTS=
+CMXS=cmxs
+RUNTIMED=noruntimed
+ASM_CFI_SUPPORTED=false
+
+########## Configuration for the bytecode compiler
+
+### Which C compiler to use for the bytecode interpreter.
+BYTECC=$(TOOLPREF)gcc
+
+### Additional compile-time options for $(BYTECC).  (For static linking.)
+BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(BYTECC).  (For static linking.)
+BYTECCLINKOPTS=-L$(PREFIX)/lib
+
+### Additional compile-time options for $(BYTECC).  (For building a DLL.)
+DLLCCCOMPOPTS=
+
+### Libraries needed
+BYTECCLIBS=
+NATIVECCLIBS=
+
+### How to invoke the C preprocessor
+
+### Flexlink
+FLEXLINK=$(TOOLPREF)flexlink -chain mingw
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
+MKMAINDLL=$(FLEXLINK) -maindll
+
+### How to build a static library
+MKLIB=$(TOOLPREF)ar rcs $(1) $(2)
+#ml let mklib out files opts = Printf.sprintf ("%sar rcs %s %s %s") toolpref out opts files;;
+
+### Canonicalize the name of a system library
+SYSLIB=-l$(1)
+#ml let syslib x = "-l"^x;;
+
+### The ranlib command
+RANLIB=$(TOOLPREF)ranlib
+RANLIBCMD=$(TOOLPREF)ranlib
+
+### The ar command
+ARCMD=$(TOOLPREF)ar
+
+############# Configuration for the native-code compiler
+
+### Name of architecture for the native-code compiler
+ARCH=i386
+
+### Name of architecture model for the native-code compiler.
+MODEL=default
+
+### Name of operating system family for the native-code compiler.
+SYSTEM=mingw
+
+### Which C compiler to use for the native-code compiler.
+NATIVECC=$(BYTECC)
+
+### Additional compile-time options for $(NATIVECC).
+NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(NATIVECC)
+NATIVECCLINKOPTS=-L$(PREFIX)/lib
+
+### Build partially-linked object file
+PACKLD=$(TOOLPREF)ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o'
+
+############# Configuration for the contributed libraries
+
+OTHERLIBRARIES=@otherlibraries@
+
+### Name of the target architecture for the "num" library
+BNG_ARCH=i386
+BNG_ASM_LEVEL=1
+
+### Configuration for LablTk
+# Set TK_ROOT to the directory where you installed TCL/TK 8.5
+# There must be no spaces or special characters in $(TK_ROOT)
+TK_DEFS=
+TK_LINK=
+
+############# Aliases for common commands
+
+# MAKEREC=$(MAKE) -f Makefile.nt
+# MAKECMD=$(MAKE)
+
+# Build compiler for cross-compilation.
+BUILD_MKEXE=gcc
+BUILD_RANLIB=ranlib
+BUILD_MKDLL=gcc -shared
+BUILD_CC=gcc
+BUILD_CCLIBS=-lm
+BUILD_CFLAGS=
+
diff --git a/asmrun/Makefile b/asmrun/Makefile
index d4f0c56..a535666 100644
--- a/asmrun/Makefile
+++ b/asmrun/Makefile
@@ -26,7 +26,7 @@ COBJS=startup.o main.o fail.o roots.o globroots.o signals.o signals_asm.o \
   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 debugger.o \
+  compact.o finalise.o custom.o unix.o win32.o backtrace.o natdynlink.o debugger.o \
   meta.o dynlink.o
 
 ASMOBJS=$(ARCH).o
@@ -153,6 +153,8 @@ globroots.c: ../byterun/globroots.c
 	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
@@ -163,7 +165,7 @@ debugger.c: ../byterun/debugger.c
 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 debugger.c
 
 clean::
diff --git a/asmrun/i386.S b/asmrun/i386.S
index e8e00a4..800247e 100644
--- a/asmrun/i386.S
+++ b/asmrun/i386.S
@@ -76,6 +76,9 @@
         popl %edx; popl %ecx; popl %eax; popl %ebp
 #define PROFILE_C \
         pushl %ebp; movl %esp, %ebp; call Lmcount$stub; popl %ebp
+#elif defined(SYS_mingw)
+#define PROFILE_CAML
+#define PROFILE_C
 #endif
 #else
 #define PROFILE_CAML
diff --git a/byterun/Makefile.common b/byterun/Makefile.common
index b519f75..2274562 100755
--- a/byterun/Makefile.common
+++ b/byterun/Makefile.common
@@ -24,7 +24,7 @@ COMMONOBJS=\
   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 --git a/byterun/dynlink.c b/byterun/dynlink.c
index 5cb2ed7..b6605fa 100644
--- a/byterun/dynlink.c
+++ b/byterun/dynlink.c
@@ -80,7 +80,12 @@ static char * parse_ld_conf(void)
 
   stdlib = getenv("OCAMLLIB");
   if (stdlib == NULL) stdlib = getenv("CAMLLIB");
-  if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR;
+  if (stdlib == NULL)
+#ifdef OCAML_STDLIB_DIR
+    stdlib = OCAML_STDLIB_DIR;
+#else
+    stdlib = ".";
+#endif
   ldconfname = caml_stat_alloc(strlen(stdlib) + 2 + sizeof(LD_CONF_NAME));
   strcpy(ldconfname, stdlib);
   strcat(ldconfname, "/" LD_CONF_NAME);
diff --git a/byterun/unix.c b/byterun/unix.c
index 7d24ef4..3619e67 100644
--- a/byterun/unix.c
+++ b/byterun/unix.c
@@ -15,6 +15,8 @@
 
 /* Unix-specific stuff */
 
+#ifndef WIN32
+
 #define _GNU_SOURCE
            /* Helps finding RTLD_DEFAULT in glibc */
 
@@ -323,3 +325,5 @@ int caml_executable_name(char * name, int name_len)
 }
 
 #endif
+
+#endif /* !WIN32 */
diff --git a/byterun/win32.c b/byterun/win32.c
index f8ba9c9..82afc1c 100644
--- a/byterun/win32.c
+++ b/byterun/win32.c
@@ -13,6 +13,8 @@
 
 /* $Id: win32.c 12686 2012-07-10 11:34:39Z scherer $ */
 
+#ifdef WIN32
+
 /* Win32-specific stuff */
 
 #include <windows.h>
@@ -35,6 +37,26 @@
 
 #include "flexdll.h"
 
+/* XXX including <io.h> gets ../byterun/io.h for some reason.
+ * Including the real io.h using the full path fails because of
+ * some strange bug in the system header file itself.  Give up and
+ * just define _finddata_t explicitly here.
+ */
+#ifndef _FSIZE_T_DEFINED
+typedef unsigned long   _fsize_t;
+#define _FSIZE_T_DEFINED
+
+struct _finddata_t
+{
+  unsigned        attrib;
+  time_t          time_create;
+  time_t          time_access;
+  time_t          time_write;
+  _fsize_t        size;
+  char            name[FILENAME_MAX];
+};
+#endif
+
 #ifndef S_ISREG
 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
 #endif
@@ -93,7 +115,7 @@ CAMLexport char * caml_search_exe_in_path(char * name)
   pathlen = strlen(name) + 1;
   if (pathlen < 256) pathlen = 256;
   while (1) {
-    fullname = stat_alloc(pathlen);
+    fullname = caml_stat_alloc(pathlen);
     retcode = SearchPath(NULL,              /* use system search path */
                          name,
                          ".exe",            /* add .exe extension if needed */
@@ -107,7 +129,7 @@ CAMLexport char * caml_search_exe_in_path(char * name)
       break;
     }
     if (retcode < pathlen) break;
-    stat_free(fullname);
+    caml_stat_free(fullname);
     pathlen = retcode + 1;
   }
   return fullname;
@@ -479,3 +501,5 @@ int caml_win32_random_seed (intnat data[16])
   data[2] = GetCurrentProcessId();
   return 3;
 }
+
+#endif /* WIN32 */
diff --git a/hardcode_mingw_include.patch b/hardcode_mingw_include.patch
new file mode 100644
index 0000000..571747d
--- /dev/null
+++ b/hardcode_mingw_include.patch
@@ -0,0 +1,24 @@
+Index: build-tree/ocaml-3.11.1/utils/clflags.ml
+===================================================================
+--- build-tree.orig/ocaml-3.12.1/utils/clflags.ml	2010-01-07 04:00:11.000000000 +0100
++++ build-tree/ocaml-3.12.1/utils/clflags.ml	2010-01-07 04:00:24.000000000 +0100
+@@ -20,7 +20,7 @@
+ 
+ let compile_only = ref false            (* -c *)
+ and output_name = ref (None : string option) (* -o *)
+-and include_dirs = ref ([] : string list)(* -I *)
++and include_dirs = ref (["@libdir@"] : string list)(* -I *)
+ and no_std_include = ref false          (* -nostdlib *)
+ and print_types = ref false             (* -i *)
+ and make_archive = ref false            (* -a *)
+--- build-tree.orig/ocaml-3.12.1/tools/ocamlmklib.mlp	2010-02-22 20:15:57.000000000 -0600
++++ build-tree/ocaml-3.12.1/tools/ocamlmklib.mlp	2010-02-22 20:16:20.000000000 -0600
+@@ -29,7 +29,7 @@
+ and failsafe = ref false    (* whether to fall back on static build only *)
+ and c_libs = ref []         (* libs to pass to mksharedlib and ocamlc -cclib *)
+ and c_opts = ref []      (* options to pass to mksharedlib and ocamlc -ccopt *)
+-and ld_opts = ref []        (* options to pass only to the linker *)
++and ld_opts = ref ["-I @libdir@"]        (* options to pass only to the linker *)
+ and ocamlc = ref (compiler_path "ocamlc")
+ and ocamlopt = ref (compiler_path "ocamlopt")
+ and output = ref "a"        (* Output name for Caml part of library *)
diff --git a/myocamlbuild.ml b/myocamlbuild.ml
index c687242..ccdd937 100644
--- a/myocamlbuild.ml
+++ b/myocamlbuild.ml
@@ -107,9 +107,11 @@ let if_mixed_dir dir =
   if mixed then ".."/dir else dir;;
 
 let unix_dir =
-  match Sys.os_type with
-  | "Win32" -> if_mixed_dir "otherlibs/win32unix"
-  | _       -> if_mixed_dir "otherlibs/unix";;
+  if_mixed_dir (
+    let win32path = "otherlibs/win32unix" in
+    if Sys.file_exists (win32path / "unix.cma") then win32path
+    else "otherlibs/unix"
+  );;
 
 let threads_dir    = if_mixed_dir "otherlibs/threads";;
 let systhreads_dir = if_mixed_dir "otherlibs/systhreads";;
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index 74c82d3..61036c8 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -69,6 +69,7 @@ INCLUDES_DEP=-I $(OCAMLSRCDIR)/parsing \
 INCLUDES_NODEP=	-I $(OCAMLSRCDIR)/stdlib \
 	-I $(OCAMLSRCDIR)/otherlibs/str \
 	-I $(OCAMLSRCDIR)/otherlibs/dynlink \
+	-I $(OCAMLSRCDIR)/otherlibs/win32unix \
 	-I $(OCAMLSRCDIR)/otherlibs/unix \
 	-I $(OCAMLSRCDIR)/otherlibs/num \
 	-I $(OCAMLSRCDIR)/otherlibs/graph
diff --git a/otherlibs/Makefile.shared b/otherlibs/Makefile.shared
index 2c084a0..0e13022 100644
--- a/otherlibs/Makefile.shared
+++ b/otherlibs/Makefile.shared
@@ -33,7 +33,7 @@ MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib
 #EXTRACFLAGS=
 #EXTRACAMLFLAGS=
 #LINKOPTS=
-#LDOPTS=
+LDOPTS=-L$(LIBDIR)
 #HEADERS=
 
 CMIFILES ?= $(CAMLOBJS:.cmo=.cmi)
@@ -42,7 +42,8 @@ CLIBNAME ?= $(LIBNAME)
 
 all: lib$(CLIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)
 
-allopt: lib$(CLIBNAME).$(A) $(LIBNAME).cmxa $(LIBNAME).$(CMXS) $(CMIFILES)
+allopt: lib$(CLIBNAME).$(A) $(LIBNAME).cmxa $(CMIFILES)
+# $(LIBNAME).$(CMXS)
 
 $(LIBNAME).cma: $(CAMLOBJS)
 	$(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlc '$(CAMLC)' -linkall $(CAMLOBJS) $(LINKOPTS)
@@ -50,8 +51,8 @@ $(LIBNAME).cma: $(CAMLOBJS)
 $(LIBNAME).cmxa: $(CAMLOBJS_NAT)
 	$(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlopt '$(CAMLOPT)' -linkall $(CAMLOBJS_NAT) $(LINKOPTS)
 
-$(LIBNAME).cmxs: $(LIBNAME).cmxa lib$(CLIBNAME).$(A)
-	$(CAMLOPT) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa
+#$(LIBNAME).cmxs: $(LIBNAME).cmxa lib$(CLIBNAME).$(A)
+#	$(CAMLOPT) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa
 
 lib$(CLIBNAME).$(A): $(COBJS)
 	$(MKLIB) -oc $(CLIBNAME) $(COBJS) $(LDOPTS)
diff --git a/otherlibs/bigarray/Makefile b/otherlibs/bigarray/Makefile
index d442edb..dc34d6d 100644
--- a/otherlibs/bigarray/Makefile
+++ b/otherlibs/bigarray/Makefile
@@ -14,8 +14,8 @@
 # $Id: Makefile 11156 2011-07-27 14:17:02Z doligez $
 
 LIBNAME=bigarray
-EXTRACFLAGS=-I../unix -DIN_OCAML_BIGARRAY -DCAML_NAME_SPACE
-EXTRACAMLFLAGS=-I ../unix
+EXTRACFLAGS=-I../win32unix -I../unix -DIN_OCAML_BIGARRAY -DCAML_NAME_SPACE
+EXTRACAMLFLAGS=-I ../win32unix -I ../unix
 COBJS=bigarray_stubs.$(O) mmap_unix.$(O)
 CAMLOBJS=bigarray.cmo
 HEADERS=bigarray.h
diff --git a/otherlibs/systhreads/Makefile b/otherlibs/systhreads/Makefile
index 502498f..7ed53df 100644
--- a/otherlibs/systhreads/Makefile
+++ b/otherlibs/systhreads/Makefile
@@ -15,13 +15,13 @@
 
 include ../../config/Makefile
 
-CAMLC=../../ocamlcomp.sh -I ../unix
-CAMLOPT=../../ocamlcompopt.sh -I ../unix
+CAMLC=../../ocamlcomp.sh -I ../win32unix -I ../unix
+CAMLOPT=../../ocamlcompopt.sh -I ../win32unix -I ../unix
 MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib
 COMPFLAGS=-warn-error A -g
 
-BYTECODE_C_OBJS=st_stubs_b.o
-NATIVECODE_C_OBJS=st_stubs_n.o
+BYTECODE_C_OBJS=st_stubs_b.o win32_b.o
+NATIVECODE_C_OBJS=st_stubs_n.o win32_n.o
 
 THREAD_OBJS= thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo
 
@@ -37,6 +37,10 @@ st_stubs_b.o: st_stubs.c st_posix.h
 	   -c st_stubs.c
 	mv st_stubs.o st_stubs_b.o
 
+win32_b.$(O): st_stubs.c st_win32.h
+	$(BYTECC) -I ../../byterun $(BYTECCCOMPOPTS) $(CFLAGS) -c st_stubs.c
+	mv st_stubs.$(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)
@@ -46,9 +50,13 @@ st_stubs_n.o: st_stubs.c st_posix.h
 	$(NATIVECC) -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) -c st_stubs.c
 	mv st_stubs.o st_stubs_n.o
 
+win32_n.$(O): st_stubs.c st_win32.h
+	$(NATIVECC) -DNATIVE_CODE -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) -c st_stubs.c
+	mv st_stubs.$(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 --git a/otherlibs/systhreads/Makefile.nt b/otherlibs/systhreads/Makefile.nt
index dc118b7..4b53d6e 100644
--- a/otherlibs/systhreads/Makefile.nt
+++ b/otherlibs/systhreads/Makefile.nt
@@ -21,6 +21,7 @@ CAMLOPT=../../boot/ocamlrun ../../ocamlopt -I ../../stdlib -I ../win32unix
 COMPFLAGS=-warn-error A -g
 MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib
 CFLAGS=-I../../byterun $(EXTRACFLAGS)
+LDOPTS=-L@libdir@
 
 CAMLOBJS=thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo
 CMIFILES=$(CAMLOBJS:.cmo=.cmi)
@@ -34,7 +35,7 @@ all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)
 allopt: lib$(LIBNAME).$(A) $(LIBNAME).cmxa $(LIBNAME).cmxs $(CMIFILES)
 
 $(LIBNAME).cma: $(CAMLOBJS)
-	$(MKLIB) -o $(LIBNAME) -ocamlc "..\\..\\boot\\ocamlrun ..\\..\\ocamlc" -linkall $(CAMLOBJS) $(LINKOPTS)
+	$(MKLIB) -o $(LIBNAME) -ocamlc "../../boot/ocamlrun ../../ocamlc" -linkall $(CAMLOBJS) $(LINKOPTS)
 
 lib$(LIBNAME).$(A): $(COBJS)
 	$(MKLIB) -o $(LIBNAME) $(COBJS) $(LDOPTS)
@@ -46,7 +47,7 @@ st_stubs_b.$(O): st_stubs.c st_win32.h
 
 
 $(LIBNAME).cmxa: $(CAMLOBJS:.cmo=.cmx)
-	$(MKLIB) -o $(LIBNAME)nat -ocamlopt "..\\..\\boot\\ocamlrun ..\\..\\ocamlopt" -linkall $(CAMLOBJS:.cmo=.cmx) $(LINKOPTS)
+	$(MKLIB) -o $(LIBNAME)nat -ocamlopt "../../boot/ocamlrun ../../ocamlopt" -linkall $(CAMLOBJS:.cmo=.cmx) $(LINKOPTS)
 	mv $(LIBNAME)nat.cmxa $(LIBNAME).cmxa
 	mv $(LIBNAME)nat.$(A) $(LIBNAME).$(A)
 
@@ -71,6 +72,7 @@ clean: partialclean
 install:
 	cp dllthreads.dll $(STUBLIBDIR)/dllthreads.dll
 	cp libthreads.$(A) $(LIBDIR)/libthreads.$(A)
+	cd $(LIBDIR); $(RANLIB) libthreads.$(A)
 	mkdir -p $(LIBDIR)/threads
 	cp $(CMIFILES) threads.cma $(LIBDIR)/threads
 	rm -f $(LIBDIR)/threads/stdlib.cma
@@ -78,6 +80,7 @@ install:
 
 installopt:
 	cp libthreadsnat.$(A) $(LIBDIR)/libthreadsnat.$(A)
+	cd $(LIBDIR); $(RANLIB) libthreadsnat.$(A)
 	cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.$(A) $(LIBDIR)/threads
 	cp threads.cmxs $(LIBDIR)/threads
 
diff --git a/otherlibs/systhreads/st_win32.h b/otherlibs/systhreads/st_win32.h
index da602b7..7e1dcb9 100644
--- a/otherlibs/systhreads/st_win32.h
+++ b/otherlibs/systhreads/st_win32.h
@@ -17,7 +17,7 @@
 
 #define _WIN32_WINNT 0x0400
 #include <windows.h>
-#include <WinError.h>
+#include <winerror.h>
 #include <stdio.h>
 #include <signal.h>
 
diff --git a/otherlibs/win32graph/Makefile.nt b/otherlibs/win32graph/Makefile.nt
index 62c4678..e7c6d6b 100644
--- a/otherlibs/win32graph/Makefile.nt
+++ b/otherlibs/win32graph/Makefile.nt
@@ -18,10 +18,11 @@ COBJS=open.$(O) draw.$(O) events.$(O) dib.$(O)
 CAMLOBJS=graphics.cmo
 WIN32LIBS=$(call SYSLIB,kernel32) $(call SYSLIB,gdi32) $(call SYSLIB,user32)
 LINKOPTS=-cclib "\"$(WIN32LIBS)\""
-LDOPTS=-ldopt "$(WIN32LIBS)"
 
 include ../Makefile.nt
 
+LDOPTS=-L@libdir@ -ldopt "$(WIN32LIBS)"
+
 graphics.ml: ../graph/graphics.ml
 	cp ../graph/graphics.ml graphics.ml
 graphics.mli: ../graph/graphics.mli
diff --git a/otherlibs/win32unix/Makefile.nt b/otherlibs/win32unix/Makefile.nt
index 76a1c19..c401bbb 100644
--- a/otherlibs/win32unix/Makefile.nt
+++ b/otherlibs/win32unix/Makefile.nt
@@ -40,7 +40,6 @@ LIBNAME=unix
 COBJS=$(ALL_FILES:.c=.$(O))
 CAMLOBJS=unix.cmo unixLabels.cmo
 LINKOPTS=-cclib $(WSOCKLIB)
-LDOPTS=-ldopt $(WSOCKLIB)
 EXTRACAMLFLAGS=-nolabels
 EXTRACFLAGS=-I../unix
 HEADERS=unixsupport.h socketaddr.h
@@ -48,6 +47,8 @@ HEADERS=unixsupport.h socketaddr.h
 
 include ../Makefile.nt
 
+LDOPTS=-L@libdir@ -ldopt $(WSOCKLIB)
+
 clean::
 	rm -f $(UNIX_FILES) $(UNIX_CAML_FILES)
 
diff --git a/utils/config.mlp b/utils/config.mlp
index cdf67d4..b905059 100644
--- a/utils/config.mlp
+++ b/utils/config.mlp
@@ -86,11 +86,7 @@ let ext_asm = "%%EXT_ASM%%"
 let ext_lib = "%%EXT_LIB%%"
 let ext_dll = "%%EXT_DLL%%"
 
-let default_executable_name =
-  match Sys.os_type with
-    "Unix" -> "a.out"
-  | "Win32" | "Cygwin" -> "camlprog.exe"
-  | _ -> "camlprog"
+let default_executable_name = "camlprog.exe"
 
 let systhread_supported = %%SYSTHREAD_SUPPORT%%;;
 
@@ -118,7 +114,7 @@ let print_config oc =
   p "ext_asm" ext_asm;
   p "ext_lib" ext_lib;
   p "ext_dll" ext_dll;
-  p "os_type" Sys.os_type;
+  p "os_type" "Win32";
   p "default_executable_name" default_executable_name;
   p_bool "systhread_supported" systhread_supported;
   flush oc;
-- 
1.7.9.5