install.ml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. (*
  2. * Haxe installer
  3. * Copyright (c)2005 Nicolas Cannasse
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *)
  19. #load "unix.cma"
  20. (* ----- BEGIN CONFIGURATION ---- *)
  21. let bytecode = false
  22. let native = true
  23. (* ------ END CONFIGURATION ----- *)
  24. let os_type = Sys.os_type
  25. (* remove the comment to compile with windows using ocaml cygwin *)
  26. (* let os_type = "Cygwin" *)
  27. let obj_ext = match os_type with "Win32" -> ".obj" | _ -> ".o"
  28. let exe_ext = match os_type with "Win32" | "Cygwin" -> ".exe" | _ -> ""
  29. let zlib = match os_type with
  30. | "Win32" -> "zlib.lib"
  31. | _ ->
  32. let osx = "/usr/lib/libz.dylib" in
  33. if Sys.file_exists osx then osx else "/usr/lib/libz.so.1"
  34. let msg m =
  35. prerr_endline m;
  36. flush stdout
  37. let command c =
  38. msg ("> " ^ c);
  39. if Sys.command c <> 0 then failwith ("Error while running " ^ c)
  40. let cvs root cmd =
  41. command ("cvs -z3 -d" ^ root ^ " " ^ cmd)
  42. let ocamlc file =
  43. if bytecode then command ("ocamlc -c " ^ file);
  44. if native then command ("ocamlopt -c " ^ file)
  45. let modules l ext =
  46. String.concat " " (List.map (fun f -> f ^ ext) l)
  47. ;;
  48. let motiontwin = ":pserver:[email protected]:/cvsroot" in
  49. let download_libs() =
  50. cvs motiontwin "co ocaml/swflib";
  51. cvs motiontwin "co ocaml/extc";
  52. cvs motiontwin "co ocaml/extlib-dev";
  53. cvs motiontwin "co neko/libs/include/ocaml"
  54. in
  55. let download() =
  56. msg "*** Please hit enter on login (empty password) ***";
  57. cvs motiontwin "login";
  58. cvs motiontwin "co haxe";
  59. download_libs();
  60. in
  61. let compile_libs() =
  62. (* EXTLIB *)
  63. Sys.chdir "ocaml/extlib-dev";
  64. command ("ocaml install.ml -nodoc -d .. " ^ (if bytecode then "-b " else "") ^ (if native then "-n" else ""));
  65. msg "";
  66. Sys.chdir "../..";
  67. (* EXTC *)
  68. Sys.chdir "ocaml/extc";
  69. let c_opts = (if Sys.ocaml_version < "3.08" then " -ccopt -Dcaml_copy_string=copy_string " else " ") in
  70. command ("ocamlc" ^ c_opts ^ "extc_stubs.c");
  71. let options = "-cclib ../ocaml/extc/extc_stubs" ^ obj_ext ^ " -cclib " ^ zlib ^ " extc.mli extc.ml" in
  72. if bytecode then command ("ocamlc -a -o extc.cma " ^ options);
  73. if native then command ("ocamlopt -a -o extc.cmxa " ^ options);
  74. Sys.chdir "../..";
  75. (* SWFLIB *)
  76. Sys.chdir "ocaml/swflib";
  77. let files = "-I .. -I ../extc swf.ml swfZip.ml actionScript.ml swfParser.ml" in
  78. if bytecode then command ("ocamlc -a -o swflib.cma " ^ files);
  79. if native then command ("ocamlopt -a -o swflib.cmxa " ^ files);
  80. Sys.chdir "../..";
  81. in
  82. let compile() =
  83. (try Unix.mkdir "bin" 0o740 with Unix.Unix_error(Unix.EEXIST,_,_) -> ());
  84. compile_libs();
  85. (* HAXE *)
  86. Sys.chdir "haxe";
  87. command "ocamllex lexer.mll";
  88. ocamlc "-I ../ocaml plugin.ml ast.ml lexer.ml";
  89. ocamlc "-I ../ocaml -pp camlp4o parser.ml";
  90. ocamlc "-I ../ocaml -I ../ocaml/swflib type.ml plugin.ml typer.ml genswf.ml genxml.ml genjs.ml";
  91. ocamlc "-I ../ocaml -I ../neko/libs/include/ocaml ../neko/libs/include/ocaml/nast.ml ../neko/libs/include/ocaml/nxml.ml genneko.ml";
  92. ocamlc "-I ../ocaml -I ../ocaml/extc main.ml";
  93. let mlist = ["plugin";"ast";"lexer";"parser";"type";"typer";"genswf";"../neko/libs/include/ocaml/nast";"../neko/libs/include/ocaml/nxml";"genneko";"genxml";"genjs";"main"] in
  94. if bytecode then command ("ocamlc -custom -o ../bin/haxe-byte" ^ exe_ext ^ " ../ocaml/extLib.cma ../ocaml/extc/extc.cma ../ocaml/swflib/swflib.cma " ^ modules mlist ".cmo");
  95. if native then command ("ocamlopt -o ../bin/haxe" ^ exe_ext ^ " ../ocaml/extLib.cmxa ../ocaml/extc/extc.cmxa ../ocaml/swflib/swflib.cmxa " ^ modules mlist ".cmx");
  96. in
  97. let startdir = Sys.getcwd() in
  98. try
  99. download();
  100. compile();
  101. Sys.chdir startdir;
  102. with
  103. Failure msg ->
  104. Sys.chdir startdir;
  105. prerr_endline msg; exit 1