Skip to content

Commit

Permalink
[ocpwin] improve configure-wxMSW script
Browse files Browse the repository at this point in the history
`
  • Loading branch information
lefessan committed Jan 12, 2016
1 parent a919bf5 commit e737ffe
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 96 deletions.
109 changes: 28 additions & 81 deletions README.ocpwin
Original file line number Diff line number Diff line change
@@ -1,94 +1,41 @@

* You need a version of libasmrun.a compiled under the same MSVC, and also
of flexdll_ocaml_msvc64.obj with /GS-
* You need :
* wxMSW-3.0.2/ containing:
Building ocplib-wxOCaml on Windows
==================================

Requirements:
=============
* You need:
* a recent ocpwin install (2016-)
* Some directory wxMSW-3.0.2/ containing:
include/: header files
lib/: library files, i.e. both Dev files and Release files
* A visual studio install, with version matching your wxMSW dlls.
* We advise to use Windows GIT, and the "git bash" shell to run all this.

* Start by creating and calling:
echo "" > toto.c
export OCPWIN_MSVC=export:9.0
ocamlc -c toto.c
This should create a file 'vcvars.sh'
Now, use:
. ./vcvars.sh
This should allow you to run "cl" directly from the command line.

* ocp-build init
* ocp-build

==========================================================================
config.ocp:

(*******************************************************************)
(* *)
(* wxOCaml *)
(* *)
(* Fabrice LE FESSANT *)
(* *)
(* Copyright 2013, INRIA/OCamlPro. *)
(* Licence LGPL v3.0 with linking exception. *)
(* *)
(*******************************************************************)

if system = "win32" || system = "win64" then {
x = [ %disp( env = [ system "WINDOWS !" ]) ]
exe_ext = ".exe"
obj_ext = ".obj"
lib_ext = ".lib"
} else {
x = [ %disp( env = [ system "NOT WINDOWS !" ]) ]
exe_ext = ""
obj_ext = ".o"
lib_ext = ".a"
}

binannot = false
Building:
=========

wx_version = "3.0.2"
(* You must rename vc90_x64_dll to vc_x64_dll *)
cxx = [ "cl" "/nologo" "/MD"
]
cppflags = [
"-I" "C:/Users/LeFessant/GIT/ocplib-wxOCaml/wxMSW-3.0.2/include/msvc"
"-I" "C:/Users/LeFessant/GIT/ocplib-wxOCaml/wxMSW-3.0.2/include"
"-I" "C:/Users/LeFessant/AppData/Roaming/OCamlPro/OCPWin64/lib"
"-D_FILE_OFFSET_BITS=64" "-DWXUSINGDLL" "-D_UNICODE"
"/EHsc"
"-I" "../wxConfig" ] (* @CPPFLAGS *)
cxxflags = [] (* @CXXFLAGS *)
cxxlibs = [ "/link" "/LIBPATH:C:/Users/LeFessant/GIT/ocplib-wxOCaml/wxMSW-3.0.2/lib/vc_x64_dll" ] (* @LIBS *)
* Configure: do not use ./configure but ./configure-wxMSW
On Git Bash:
./configure-wxMSW -wx-dir c:/wxMSW-3.0.2 -msvc 11.0 -arch x64
where c:/wxMSW-3.0.2 is the directory containg your wx install
11.0 is your MSVC version
x64 is your architecture (x86 otherwise)
* Start the build, by using to ocpwin to specify the environment for MSVC:
ocpwin -msvc 11.0 -msvc-exec ocp-build

begin config "link-with-wxOCaml"
custom = true
bytelink += [ "-custom" ]
link += [ "-verbose" "-cclib" "-llibwxOCaml_api" "-I" "C:/Users/LeFessant/GIT/ocplib-wxOCaml/wxMSW-3.0.2/lib/vc_x64_dll" (* @LIBS *) ]
end
Examples:
=========
There are some examples in the distribution. They are compiled by default,
and available in _obuild:

begin config "compile-c-with-wxWidget"
ccopt = [ cxxflags cppflags ]
end
For example, you can call "./_obuild/two-panels/two-panels.asm

==========================================================================
wxConfig/wxOCamlConfig.h
/*******************************************************************/
/* */
/* wxOCaml */
/* */
/* Fabrice LE FESSANT */
/* */
/* Copyright 2013, INRIA/OCamlPro. */
/* Licence LGPL v3.0 with linking exception. */
/* */
/*******************************************************************/
Before calling them, you might need to have MSVC and WX dlls in the PATH.
For that, the following script might be useful:

#define WXOCAML_HAS_STC 1
#define WXOCAML_HAS_WRAPSIZER 1
==========================================================================
vcredist.sh (useful to run the generated application)

export PATH="/c/Program Files (x86)/Microsoft Visual Studio 9.0/VC/redist/amd64/Microsoft.VC90.CRT:$PATH"
export PATH="/c/Users/LeFessant/GIT/ocplib-wxOCaml/wxMSW-3.0.2/lib/vc_x64_dll:$PATH"
export PATH="/c/wxMSW-3.0.2/lib/vc110_x64_dll:$PATH"


2 changes: 1 addition & 1 deletion api/wxDefs.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ CONSTINT(wxCAL_SHOW_WEEK_NUMBERS,wxCAL_SHOW_WEEK_NUMBERS)
// Not in 3.0 under Windows ?
//CONSTINT(wxEXTEND_LAST_ON_EACH_LINE, wxEXTEND_LAST_ON_EACH_LINE)
//CONSTINT(wxREMOVE_LEADING_SPACES, wxREMOVE_LEADING_SPACES)
//CONSTINT(wxWRAPSIZER_DEFAULT_FLAGS, wxWRAPSIZER_DEFAULT_FLAGS)
CONSTINT(wxWRAPSIZER_DEFAULT_FLAGS, wxWRAPSIZER_DEFAULT_FLAGS)

CONSTINT(wxBITMAP_DEFAULT_TYPE, wxBITMAP_DEFAULT_TYPE)
CONSTINT(wxALPHA_OPAQUE, wxALPHA_OPAQUE)
Expand Down
2 changes: 1 addition & 1 deletion config.ocp.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ binannot = false
wx_version = "@WX_VERSION@"

cxx = "@CXX@"
cppflags = [ %split_simplify( s = "@CPPFLAGS@" ) "-I" "@OCAMLLIB@" "-I" "../wxConfig" ]
cppflags = [ %split_simplify( s = "@CPPFLAGS@" ) "-I" "@OCAMLLIB@" "-I" "../wxConfig" "-g" "-fPIC" ]
cxxflags = %split_simplify( s = "@CXXFLAGS@" )
cxxlibs = %split_simplify(s = "@LIBS@" )

Expand Down
121 changes: 115 additions & 6 deletions config/config-wxMSW.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,112 @@

(* Maybe add _DEBUG ? *)
let ocamllib = Sys.argv.(1)
let wxMSW_dir = Sys.argv.(2)
let wxMSW_vc = Sys.argv.(3) (* vc100_x64 *)
let wxMSW_dir = ref None
let msvc = ref None
let arch = ref (Some "x64")

let arg_usage =
String.concat "\n" [
"Usage is ./configure-wxMSW [OPTIONS]";
"Most options are mandatory the first time it is used.";
]

let () =
if Sys.file_exists "config.prev" then begin
let input_line ic =
let s = input_line ic in
if s = "-" then None else Some s
in
let ic = open_in "config.prev" in
wxMSW_dir := input_line ic;
msvc := input_line ic;
arch := input_line ic;
close_in ic
end

let arg_list = [
"-wx-dir", Arg.String
(fun s -> wxMSW_dir := Some s), "wxMSW_dir WX directory";
"-msvc", Arg.String
(fun s -> msvc := Some s), "MSVC Microsoft MSVC version (11.0 for example)";
"-arch", Arg.String
(fun s -> arch := Some s), "ARCH Architecture (either x64 or x86)";
]

let () =
Arg.parse arg_list
(fun s ->
Printf.eprintf "Error: unexpected argument %S\n%!" s;
Arg.usage arg_list arg_usage; exit 2) arg_usage

let check_arg arg v = match !v with
None -> Printf.eprintf "Error: You must specify at least once %s\n%!" arg;
exit 2
| Some s -> s

let () =
let output_line oc s =
match !s with
| None -> output_string oc "-\n"
| Some s -> output_string oc s; output_string oc "\n"
in
let oc = open_out "config.prev" in
output_line oc wxMSW_dir;
output_line oc msvc;
output_line oc arch;
close_out oc

let wxMSW_dir = check_arg "-wx-dir" wxMSW_dir
let msvc = check_arg "-msvc" msvc
let arch = check_arg "-arch" arch

let wxMSW_vc =
match msvc with
| "9.0" -> "vc90"
| "10.0" -> "vc100"
| "11.0" -> "vc110"
| "12.0" -> "vc120"
| "14.0" -> "vc140"
| _ ->
Printf.eprintf "Error: unsupported MSVC version %S\n%!" msvc;
Printf.eprintf " Supported versions: 9.0, 10.0, 11.0, 12.0 and 14.0\n%!";
exit 2

let wxMSW_vc =
match arch with
| "x64" -> wxMSW_vc ^ "_x64"
| "x86" -> wxMSW_vc
| _ ->
Printf.eprintf "Error: unsupported architecture %S\n%!" arch;
Printf.eprintf " Supported architectures: x64, x86\n%!";
exit 2

let () =
Printf.printf "Configuring for:\n";
Printf.printf "OCaml directory: %S\n" ocamllib;
Printf.printf "wxMSW directory = %S\n%!" wxMSW_dir;
Printf.printf "MSVC version = %S\n%!" wxMSW_vc
Printf.printf "wxMSW VC = %S\n%!" wxMSW_vc;
()

let () =
if Filename.is_relative wxMSW_dir || Filename.is_implicit wxMSW_dir then begin
Printf.eprintf "Error: wxMSW directory must be absolute\n%!";
exit 2
end

let () =
let dlldir = Printf.sprintf "%s/lib/%s_dll" wxMSW_dir wxMSW_vc in
if not (Sys.file_exists dlldir) then begin
Printf.eprintf "Error: wxMSW directory does not contains libraries ?\n";
Printf.eprintf " dlldir = %S\n%!" dlldir;
exit 2
end

let () =
let incdir = Printf.sprintf "%s/include/msvc" wxMSW_dir in
if not (Sys.file_exists incdir) then begin
Printf.eprintf "Error: wxMSW directory does not contains includes ?\n";
Printf.eprintf " incdir = %S\n%!" incdir;
exit 2
end

let () =
let oc = open_out "wxConfig/wxOCamlConfig.h" in
Expand Down Expand Up @@ -42,7 +140,7 @@ let () =
[
"-I"; Printf.sprintf "%s/include/msvc" wxMSW_dir;
"-I"; Printf.sprintf "%s/include" wxMSW_dir;
"-I"; ocamllib;
"-I"; "%{OCAMLLIB}%";
"-D_FILE_OFFSET_BITS=64";
"-DWXUSINGDLL";
"-D_UNICODE";
Expand Down Expand Up @@ -82,3 +180,14 @@ let () =
]
);
close_out oc

let () =
let cmd = "ocp-build init" in
Printf.printf "Calling: %s\n" cmd;
if Sys.command cmd <> 0 then begin
Printf.eprintf "Error while calling %s\n%!" cmd;
exit 2;
end;
Printf.printf "\nYou should now call:\n";
Printf.printf "ocpwin -msvc %s -msvc-exec ocp-build\n" msvc;
()
2 changes: 1 addition & 1 deletion configure-wxMSW
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

ocaml ./config/config-wxMSW.ml $(ocamlc -version) $*
ocaml ./config/config-wxMSW.ml $*


8 changes: 3 additions & 5 deletions wxConfig/build.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
(*******************************************************************)

if system = "win32" || system = "win64" then {
x = [ %disp( env = [ system "WINDOWS !" ]) ]
exe_ext = ".exe"
} else {
x = [ %disp( env = [ system "NOT WINDOWS !" ]) ]
exe_ext = ""
}

Expand Down Expand Up @@ -50,7 +48,7 @@ begin library "wxConfig"
"wxOCamlConfig.h"
]
commands = [
{ cxx cxxflags cppflags "-g" "-fPIC" "-o" "%{wxConfig_FULL_DST_DIR}%/genWxUSE" "genWxUSE.cpp" cxxlibs }
{ cxx cxxflags cppflags "-o" "%{wxConfig_FULL_DST_DIR}%/genWxUSE" "genWxUSE.cpp" cxxlibs }
]
)

Expand Down Expand Up @@ -82,7 +80,7 @@ begin library "wxConfig"
"wxOCamlConfig.h"
]
commands = [
{ cxx cxxflags cppflags "-g" "-fPIC" "-o" "%{wxConfig_FULL_DST_DIR}%/genWxHAS" "genWxHAS.cpp" cxxlibs }
{ cxx cxxflags cppflags "-o" "%{wxConfig_FULL_DST_DIR}%/genWxHAS" "genWxHAS.cpp" cxxlibs }
]
)

Expand All @@ -108,7 +106,7 @@ begin library "wxConfig"
"%{api_dir_FULL_SRC_DIR}%/wxDefs.dsc"
]
commands = [
{ cxx cxxflags cppflags "-g" "-fPIC" "-o" "%{wxConfig_FULL_DST_DIR}%/genWxDefs" "genWxDefs.cpp" cxxlibs }
{ cxx cxxflags cppflags "-o" "%{wxConfig_FULL_DST_DIR}%/genWxDefs" "genWxDefs.cpp" cxxlibs }
]
)

Expand Down
2 changes: 1 addition & 1 deletion wxWidgets_cpp/build.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
build_rules = [
OBJECTS (
commands = [
{ cxx cxxflags cppflags "-c" "-g" "-fPIC" "%{basename}%.cpp" }
{ cxx cxxflags cppflags "-c" "%{basename}%.cpp" }
]
sources = [ "%{basename}%.cpp"
"%{wxConfig_dir_FULL_SRC_DIR}%/wxOCaml.h"
Expand Down

0 comments on commit e737ffe

Please sign in to comment.