Permalink
Browse files

[feature] build: support for Windows Mingw64 compiler chain

  • Loading branch information...
1 parent 93fa005 commit 22548596a1c9ecfe62602e5ff5a6715427701ac2 @shadinger committed Feb 12, 2012
@@ -27,6 +27,7 @@ open Command
let mlstate_platform = "mlstate_platform"
let is_mac = Config.os = Config.Mac
let is_fbsd = Config.os = Config.FreeBSD
+let is_mingw = Config.os = Config.Mingw
let sed = if is_mac then P"gsed" else P"sed"
let md5 = if is_fbsd then P"md5" else P"md5sum"
@@ -38,8 +39,7 @@ let md5 = if is_fbsd then P"md5" else P"md5sum"
let windows_mode = (os = Win32)
let c_wall,c_werror =
- if windows_mode (*&& compiler=microsoft*) then "/Wall","/Wall"
- else if is_mac then "-Wall","-Wall"
+ if is_mac then "-Wall","-Wall"
else "-Wall","-Werror"
let winocamldir = Pathname.pwd / "ms_windows"
@@ -54,19 +54,11 @@ let winocamldoc = winocamldir / "windows_ocamldoc"
let as_wintools = [ ("trx", "") ; ("bslregister", "") ; ("opa.exe", windows_opa) ]
-let _ = if windows_mode then Printf.printf "MYOCAMLBUILD WINDOWS MODE\n" else ()
-
let _ =
Options.ext_lib := Config.ext_lib;
Options.ext_obj := Config.ext_obj;
Options.ext_dll := Config.ext_shared
-let _ = if windows_mode then (
- Options.ocamlmklib := P winocamlmklib;
- Options.ocamlmktop := P winocamlmktop;
- Options.ocamldoc := P winocamldoc
-) else ()
-
let run_and_read s =
let output = run_and_read s in
String.sub output 0 (String.length output - 1) (* Remove trailing \n *)
@@ -78,13 +70,13 @@ let debug_getenv_toggle var = try Sys.getenv var = "1" with Not_found -> false
*)
let rec trx_deps dep prod env build =
- Cmd(S[A"grep"; A"^\\s*\\(read\\|include\\)"; P(env dep);
+
+ Cmd(S[Sh"grep"; Sh"'^\\s*\\(read\\|include\\)'"; P(env dep);
Sh("| perl -p -e 's/^ *(read|include) +([^ ]+).*/\\2/'");
Sh("> "^(env prod))])
let proto_deps dep prod env build =
- Cmd(S[A"grep"; A"^-include"; P(env dep);
- Sh("| perl -p -e 's/^ *([-]include) +\"([^ ]+)\".*/\\2/'");
+ Cmd(S[Sh"bash"; Sh"../utils/protodeps.sh"; P(env dep);
Sh("> "^(env prod))])
let build_list build targets = List.iter Outcome.ignore_good (build (List.map (fun f -> [f]) targets))
@@ -118,7 +110,7 @@ let get_tool ?local:(local=false) name =
true, (if c <> "" then c else (wingate f))
with Not_found -> false, ""
in
- if windows_mode && wintools_b then (Sh winf) else (P f)
+ P f
| External f -> P f)
with Not_found -> failwith ("Build tool not found: "^name)
@@ -388,8 +380,7 @@ let _ = dispatch begin function
~dep: "%.c"
~prod: "%.c.depends"
(fun env build ->
- Cmd(S[P"perl"; A"-n"; A"-e";
- A("if (/^ *(#include) +\"(\\.\\.\\/)*([^\"]+)\".*/) { print \"$3\\n\"; }");
+ Cmd(S[ Sh"sh"; Sh"../utils/cdeps.sh";
P(env "%.c"); Sh">"; P(env "%.c.depends")]));
rule "cc: c & c.depends -> o"
@@ -496,7 +487,6 @@ let _ = dispatch begin function
flag ["ocaml"; "compile"; "noassert"] (A"-noassert");
flag ["extension:c"; "compile"; "c_wall"] (S[A"-ccopt";A c_wall;A"-ccopt";A c_werror]);
-
(* PB WITH libcrypto.obj MISSING ??? *)
if windows_mode then (
(* openssl *)
@@ -544,6 +534,10 @@ let _ = dispatch begin function
flag ["ocaml"; "native"; "link"; tag] (S[A"-ccopt";A("-L"^dir);A"-cclib";A("-l"^name)]);
in
+ (* When compiling memory.c on Mingw we need to link to the psapi and dnsapi lib *)
+ if is_mingw then
+ flag ["use_stubs"; "link"] (S[A"-cclib";A"-lpsapi";A"-cclib";A"-ldnsapi";A"-cclib";A"-lmswsock"]);
+
(* In the memory.c in FreeBSD part that uses kvm_getprocs() required link with -lkvm. *)
if is_fbsd then
flag ["use_stubs"; "link"] (S[A "-cclib";A "-lkvm"]);
@@ -33,13 +33,9 @@
P (pp_script "mlstate_nodebug"),
P (pp_script "pa_ulex")
else
- P (Pathname.pwd/"utils"/"ppdebug.pl"),
- S [ P (Pathname.pwd/"utils"/"ppdebug.pl"); A "-r" ],
- S [ P Config.camlp4o;
- (match Config.Libdir.ulex with
- | Some dir -> S [A "-I"; P dir]
- | None -> N);
- P "pa_ulex.cma"; P "pr_o.cmo" ]
+ S [ P "perl"; P (".."/"utils"/"ppdebug.pl") ],
+ S [ P "perl"; P (".."/"utils"/"ppdebug.pl"); A "-r" ],
+ S [ P "bash"; P (".."/"utils"/"camlp4o-ulex.sh") ; P "pa_ulex.cma"; P "pr_o.cmo" ]
in
flag ["ocaml"; "pp"; "with_mlstate_debug"]
View
@@ -139,10 +139,14 @@ let generate_ocamldep_rule ml_or_mli =
~insert:`top (* need to be inserted before the real ocamldep rule *)
(fun env build ->
let ml = env "%." ^ ml_or_mli in
- if Tags.mem "with_mlstate_debug" (tags_of_pathname ml) &&
- Sys.command ("grep -q '#<Ifstatic:' " ^ Pathname.to_string ml) = 0
+ if Tags.mem "with_mlstate_debug" (tags_of_pathname ml)
then
tag_file ml ["with_static_preprocessing"];
+
+(* if Tags.mem "with_mlstate_debug" (tags_of_pathname ml) &&
+ Sys.command ("grep -q '#<Ifstatic:' " ^ Pathname.to_string ml) = 0
+ then
+ tag_file ml ["with_static_preprocessing"]; *) (* TODO get back optimization *)
fail_rule build (* failing to that ocamlbuild calls the real ocamldep rule *)
) in
generate_ocamldep_rule "ml";
View
@@ -60,7 +60,7 @@ val all_tags : string list
val is_release : bool
(** the target OS type *)
-type os = Linux | Mac | Win32 | Cygwin | FreeBSD
+type os = Linux | Mac | Win32 | Cygwin | FreeBSD | Mingw
val os : os
(** the name of the GNU make binary, gmake on fBSD, make on other platforms *)
View
@@ -106,9 +106,13 @@ EXT_LIB="a"
EXT_OBJ="o"
EXT_SHARED="so"
case $(uname) in
+ MINGW*)
+ echo-ok Windows/Mingw
+ EXT_SHARED="dll"
+ IS_MINGW=1;
+ IS_WINDOWS=1;;
CYGWIN*)
echo-ok Windows/cygwin
- EXT_LIB="lib"
EXT_SHARED="dll"
IS_WINDOWS=1;;
Darwin*)
@@ -274,9 +278,9 @@ EOF
echo "Your ocaml seems to be neither a 64bit or a 32bit version. Please install a native 64 bit package."
false
esac >&2
+ cd "$OPA_SOURCE_DIR"
rm -rf /tmp/${DIR#/tmp/}
trap - EXIT
- cd "$OPA_SOURCE_DIR"
}
check-ocaml
@@ -365,8 +369,8 @@ check-c-lib () (
# Now checking compile, link & run
local DIR=$(mktemp -d /tmp/opa-configure.XXXXX)
- trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
cd $DIR
+ trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
{
for i in "${INCLUDES[@]}"; do echo '#include <'$i'>'; done
@@ -454,8 +458,8 @@ check-ocaml-lib () {
fi
local DIR=$(mktemp -d /tmp/opa-configure.XXXXX)
- trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
cd $DIR
+ trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
echo "module M = $MODULE $MORE" >check_${LIB}.ml
@@ -484,9 +488,9 @@ EOF
else
echo-ok-tag
fi >&2
+ cd "$OPA_SOURCE_DIR"
rm -rf /tmp/${DIR#/tmp/}
trap - EXIT
- cd "$OPA_SOURCE_DIR"
}
check-cmxa () {
@@ -671,11 +675,12 @@ let available = [ $TAGS_LIST]
let all_tags = [ $(for t in $ALL_TAGS_LIST; do echo -n "\"$t\"; "; done)]
let is_release = $(camlbool "$IS_RELEASE")
-type os = Linux | Mac | Win32 | Cygwin | FreeBSD
+type os = Linux | Mac | Win32 | Cygwin | FreeBSD | Mingw
let os =
$(if [ -n "${IS_LINUX:-}" ]; then echo Linux
elif [ -n "${IS_MAC:-}" ]; then echo Mac
elif [ -n "${IS_FREEBSD:-}" ]; then echo FreeBSD
+ elif [ -n "${IS_MINGW:-}" ]; then echo Mingw
else echo 'match Sys.os_type with "Win32" -> Win32 | "Cygwin" -> Cygwin | _ -> assert false'
fi)
@@ -722,8 +727,10 @@ IS_LINUX="${IS_LINUX:-}"
IS_WINDOWS="${IS_WINDOWS:-}"
IS_MAC="${IS_MAC:-}"
IS_FREEBSD="${IS_FREEBSD:-}"
+IS_MINGW="${IS_MINGW:-}"
OS=$(if [ -n "${IS_LINUX:-}" ]; then echo '"Linux"'
elif [ -n "${IS_MAC:-}" ]; then echo '"Mac"'
+ #elif [ -n "${IS_MINGW:-}" ]; then echo '"Mingw"'
elif [ -n "${IS_WINDOWS:-}" ]; then echo '"Win32"'
elif [ -n "${IS_FREEBSD:-}" ]; then echo '"FreeBSD"'
else echo "Error: OS inconsistency" >&2; exit 2
View
@@ -21,10 +21,14 @@
value stack_pointer (value v) {
int x[1]; /* don't use 0, some compilers don't like 0-sized arrays */
- return (Val_long((long int)x));
+ return (Val_long(x));
}
value immediate_exit (value v) {
- _exit (Long_val(v));
+ #ifdef WIN32
+ exit(Long_val(v));
+ #else
+ _exit (Long_val(v));
+ #endif
return Val_unit;
}
View
@@ -327,7 +327,7 @@ let check_create_path ?(rights=0o755) path =
let path =
if Filename.basename path = "." then path
else path ^ "/" in
- let path = remove_all_symlinks path in
+ let path = Mlstate_platform.platform_dependent ~unix:remove_all_symlinks ~windows:(fun x->x) () path in
let rec aux1 = function
[] -> aux1 [Filename.dirname path]
| (hd :: tl) as l ->
@@ -1,14 +1,17 @@
#! /bin/sh
CYG=$(uname | grep CYGWIN)
+MING=$(uname | grep MINGW)
[ "$1" = "WIN" ] && WINDOWS=1
[ -n "$CYG" ] && CYGWIN=1
-[ -z "$CYG" ] && UNIX=1
+[ -n "$MING" ] && MINGW=1
+[ -z "$CYG" ] && [ -z "$MING" ] && UNIX=1
FILE="mlstate_platform.h"
-echo "// generated C $CYGWIN L $UNIX W $WINDOWS" > $FILE
-echo "// can define MLSTATE_WINDOWS MLSTATE_UNIX MLSTATE_CYGWIN" >> $FILE
+echo "// generated C $CYGWIN L $UNIX W $WINDOWS M $MINGW" > $FILE
+echo "// can define MLSTATE_WINDOWS MLSTATE_UNIX MLSTATE_CYGWIN MLSTATE_MINGW" >> $FILE
echo "#ifndef MLSTATE_PLATFORM_H" >> $FILE
echo "#define MLSTATE_PLATFORM_H" >> $FILE
[ -n "$WINDOWS" ] && echo "#define MLSTATE_WINDOWS 1" >> $FILE
[ -n "$UNIX" ] && echo "#define MLSTATE_UNIX 1" >> $FILE
[ -n "$CYGWIN" ] && echo "#define MLSTATE_CYGWIN 1" >> $FILE
+[ -n "$MINGW" ] && echo "#define MLSTATE_MINGW 1" >> $FILE
echo "#endif" >> $FILE
View
@@ -69,6 +69,25 @@ int get_mem (unsigned int *rss)
#else /* not MAC and FreeBSD */
+#ifdef WIN32
+#include <windows.h>
+#include <Psapi.h>
+int get_mem (unsigned int *rss)
+{
+HANDLE pHandle;
+PROCESS_MEMORY_COUNTERS pmc;
+
+ pHandle = GetCurrentProcess();
+ if (GetProcessMemoryInfo(pHandle, &pmc, sizeof(pmc))) {
+ *rss = pmc.WorkingSetSize;
+ } else {
+ *rss =-1;
+ }
+ return 0;
+}
+
+#else /* not WIN32 */
+
#include <stdio.h>
#include <unistd.h>
@@ -84,7 +103,8 @@ int get_mem (unsigned int *rss)
return 0;
}
-#endif
+#endif /* WIN32 */
+#endif /* MAC */
long usage() {
unsigned int rss = -1;
View
@@ -11,6 +11,7 @@ IS_MAC=""
IS_WINDOWS=""
case $(uname) in
+ MINGW*) IS_WINDOWS=1;;
CYGWIN*) IS_WINDOWS=1;;
Darwin*) IS_MAC=1;;
Linux*|GNU/kFreeBSD) IS_LINUX=1;;
@@ -45,7 +45,8 @@ struct
let options_linker =
["-w a"]
@ (if Base.is_windows then
- ["-cclib"; "Dnsapi.lib"; "-cclib"; "libeay32.lib"; "-cclib"; "ssleay32.lib" (*; "ssl_stubs.obj" *)]
+ (* ["-cclib"; "Dnsapi.lib"; "-cclib"; "libeay32.lib"; "-cclib"; "ssleay32.lib"] *)
+ [ "-cclib"; "'-link -Wl,--stack,16777216'"]
else [])
(**
@@ -66,21 +67,7 @@ struct
Like [server_include_dir] but the path is not absolute, but relative to MLSTATELIBS directory.
The following directories will be prefixed by MLSTATELIBS before passing to ocaml compiler with -I
*)
- let server_include_mlstate_dir =
- InstallDir.lib_opa ::
- (
- if Base.is_windows
- then
- (*
- FIXME
- What is the purpose of this ?
- This will be concatenated with a Filename.concat anyway
- *)
- if BuildInfos.is_release
- then ["windows_libs/openssl/lib"]
- else ["/windows_libs/openssl/lib"]
- else []
- )
+ let server_include_mlstate_dir = [InstallDir.lib_opa]
(**
The list of ocaml libraries. Will be suffixed by ".cma" or ".cmxa" depending of the option --bytecode.
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+source ../config.sh
+
+camlp4o -I $LIB_ULEX_DIR $@
+
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env sh
+
+perl -n -e 'if (/^ *(#include) +"(\.\.\/)*([^"]+)".*/) { print "$3\n"; }' $@
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+grep '^-include' $@ | perl -p -e 's/^ *([-]include) +"([^ ]+)".*/\2/'

0 comments on commit 2254859

Please sign in to comment.