diff options
| author | letouzey | 2011-04-21 16:12:19 +0000 |
|---|---|---|
| committer | letouzey | 2011-04-21 16:12:19 +0000 |
| commit | 64643bc2889ba26007cea65e3bf8917a8595d7ed (patch) | |
| tree | e263f2126df2d313d42ed56eadbda350377064be | |
| parent | 2e74a14de5ca180a700a731732700f9a32891ba5 (diff) | |
Ocamlbuild: in win32, coqide is now a console-free app by default
This is an adaptation of commit 13748 in 8.3 branch
Making coqide console-free can be done via a link flag given to mingw.
In case of problem with this setting, I also include a script mkwinapp.ml
borrowed from project OCaml-Win32 (and slightly modified to allow
restoring the console as well as removing it).
Use:
"mkwinapp coqide.exe" to make it console-free.
"mkwinapp -unset coqide.exe" to go back to usual console app.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@14039 85f007b7-540e-0410-9357-904b9bb8a0f7
| -rw-r--r-- | _tags | 1 | ||||
| -rw-r--r-- | myocamlbuild.ml | 8 | ||||
| -rw-r--r-- | tools/mkwinapp.ml | 92 |
3 files changed, 99 insertions, 2 deletions
@@ -11,6 +11,7 @@ <ide/coqide_main.{native,byte}> : use_str, use_unix, thread, ide <checker/main.{native,byte}> : use_str, use_unix, use_dynlink, use_camlpX <plugins/micromega/csdpcert.{native,byte}> : use_nums, use_unix +<tools/mkwinapp.{native,byte}> : use_unix ## tags for ide diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 05d99dbd20..97f91666e5 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -167,6 +167,7 @@ let coqmktop = "scripts/coqmktop" type links = Both | Best | BestInPlace | Ide let all_binaries = + (if w32 then [ "mkwinapp", "tools/mkwinapp", Best ] else []) @ [ "coqtop", coqtop, Both; "coqide", "ide/coqide_main", Ide; "coqmktop", coqmktop, Both; @@ -391,9 +392,12 @@ let extra_rules () = begin Cmd (S [P w32res;A "--input-format";A "rc";A "--input";P rc; A "--output-format";A "coff";A "--output"; Px o])); -(** For windows, Coqide should incorporate the Coq icon *) +(** The windows version of Coqide is now a console-free win32 app, + which moreover contains the Coq icon. If necessary, the mkwinapp + tool can be used later to restore or suppress the console of Coqide. *) - if w32 then flag ["link"; "ocaml"; "program"; "ide"] (P w32ico); + if w32 then flag ["link"; "ocaml"; "program"; "ide"] + (S [A "-ccopt"; A "-link -Wl,-subsystem,windows"; P w32ico]); (** Coqtop *) diff --git a/tools/mkwinapp.ml b/tools/mkwinapp.ml new file mode 100644 index 0000000000..226302fb2d --- /dev/null +++ b/tools/mkwinapp.ml @@ -0,0 +1,92 @@ +(* OCaml-Win32 + * mkwinapp.ml + * Copyright (c) 2002-2004 by Harry Chomsky + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +(********************************************************************* + * This program alters an .exe file to make it use the "windows subsystem" + * instead of the "console subsystem". In other words, when Windows runs + * the program, it will not create a console for it. + *) + +(* Pierre Letouzey 23/12/2010 : modification to allow selecting the + subsystem to use instead of just setting the windows subsystem *) + +(* This tool can be run directly via : + ocaml unix.cma mkwinapp.ml [-set|-unset] <filename> +*) + +exception Invalid_file_format + +let input_word ic = + let lo = input_byte ic in + let hi = input_byte ic in + (hi lsl 8) + lo + +let find_pe_header ic = + seek_in ic 0x3C; + let peheader = input_word ic in + seek_in ic peheader; + if input_char ic <> 'P' then + raise Invalid_file_format; + if input_char ic <> 'E' then + raise Invalid_file_format; + peheader + +let find_optional_header ic = + let peheader = find_pe_header ic in + let coffheader = peheader + 4 in + seek_in ic (coffheader + 16); + let optsize = input_word ic in + if optsize < 96 then + raise Invalid_file_format; + let optheader = coffheader + 20 in + seek_in ic optheader; + let magic = input_word ic in + if magic <> 0x010B && magic <> 0x020B then + raise Invalid_file_format; + optheader + +let change flag ic oc = + let optheader = find_optional_header ic in + seek_out oc (optheader + 64); + for i = 1 to 4 do + output_byte oc 0 + done; + output_byte oc (if flag then 2 else 3) + +let usage () = + print_endline "Alters a Win32 executable file to use the Windows subsystem or not."; + print_endline "Usage: mkwinapp [-set|-unset] <filename>"; + print_endline "Giving no option is equivalent to -set"; + exit 1 + +let main () = + let n = Array.length Sys.argv - 1 in + if not (n = 1 || n = 2) then usage (); + let flag = + if n = 1 then true + else if Sys.argv.(1) = "-set" then true + else if Sys.argv.(1) = "-unset" then false + else usage () + in + let filename = Sys.argv.(n) in + let f = Unix.openfile filename [Unix.O_RDWR] 0 in + let ic = Unix.in_channel_of_descr f and oc = Unix.out_channel_of_descr f in + change flag ic oc + +let _ = main () |
