aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/mkwinapp.ml
diff options
context:
space:
mode:
authorGravatar letouzey <letouzey@85f007b7-540e-0410-9357-904b9bb8a0f7>2011-04-21 16:12:19 +0000
committerGravatar letouzey <letouzey@85f007b7-540e-0410-9357-904b9bb8a0f7>2011-04-21 16:12:19 +0000
commit64643bc2889ba26007cea65e3bf8917a8595d7ed (patch)
treee263f2126df2d313d42ed56eadbda350377064be /tools/mkwinapp.ml
parent2e74a14de5ca180a700a731732700f9a32891ba5 (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
Diffstat (limited to 'tools/mkwinapp.ml')
-rw-r--r--tools/mkwinapp.ml92
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/mkwinapp.ml b/tools/mkwinapp.ml
new file mode 100644
index 000000000..226302fb2
--- /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 ()