install.ml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 ocamloptflags = match os_type with "Unix" -> "-cclib -fno-stack-protector " | _ -> ""
  30. let zlib_path = match os_type with
  31. | "Win32" -> "libs/extc/zlib/"
  32. | _ -> "./"
  33. let zlib = match os_type with
  34. | "Win32" -> zlib_path ^ "zlib.lib"
  35. | _ ->
  36. try
  37. List.find Sys.file_exists ["/usr/lib/libz.dylib";"/usr/lib64/libz.so.1";"/usr/lib/libz.so.1";"/lib/libz.so.1";"/usr/lib/libz.so.4.1";"/lib/x86_64-linux-gnu/libz.so.1"]
  38. with
  39. Not_found ->
  40. failwith "LibZ was not found on your system, please install it or modify the search directories in the install script"
  41. let msg m =
  42. prerr_endline m;
  43. flush stdout
  44. let command c =
  45. msg ("> " ^ c);
  46. if Sys.command c <> 0 then failwith ("Error while running " ^ c)
  47. let cvs root cmd =
  48. command ("cvs -z3 -d" ^ root ^ " " ^ cmd)
  49. let ocamlc file =
  50. if bytecode then command ("ocamlc -c " ^ file);
  51. if native then command ("ocamlopt -c " ^ ocamloptflags ^ file)
  52. let modules l ext =
  53. String.concat " " (List.map (fun f -> f ^ ext) l)
  54. ;;
  55. let download() =
  56. command "svn co http://haxe.googlecode.com/svn/trunk haxe";
  57. in
  58. let compile_libs() =
  59. Sys.chdir "haxe/libs";
  60. (* EXTLIB *)
  61. Sys.chdir "extlib";
  62. command ("ocaml install.ml -nodoc -d .. " ^ (if bytecode then "-b " else "") ^ (if native then "-n" else ""));
  63. msg "";
  64. Sys.chdir "..";
  65. (* EXTC *)
  66. Sys.chdir "extc";
  67. let c_opts = (if Sys.ocaml_version < "3.08" then " -ccopt -Dcaml_copy_string=copy_string " else " ") in
  68. command ("ocamlc" ^ c_opts ^ " -I .. -I ../../" ^ zlib_path ^ " extc_stubs.c");
  69. let options = "-cclib libs/extc/extc_stubs" ^ obj_ext ^ " -cclib " ^ zlib ^ " extc.ml" in
  70. let options = if Sys.os_type = "Win32" then options ^ " -cclib shell32.lib" else options in
  71. if bytecode then command ("ocamlc -a -I .. -o extc.cma " ^ options);
  72. if native then command ("ocamlopt -a -I .. -o extc.cmxa " ^ options);
  73. Sys.chdir "..";
  74. (* SWFLIB *)
  75. Sys.chdir "swflib";
  76. let files = "-I .. -I ../extc as3.mli as3hl.mli as3code.ml as3parse.ml as3hlparse.ml swf.ml actionScript.ml swfParser.ml png.mli png.ml" in
  77. if bytecode then command ("ocamlc -a -o swflib.cma " ^ files);
  78. if native then command ("ocamlopt -a -o swflib.cmxa " ^ files);
  79. Sys.chdir "..";
  80. (* NEKO *)
  81. Sys.chdir "neko";
  82. let files = "-I .. nast.ml nxml.ml binast.ml nbytecode.ml ncompile.ml" in
  83. if bytecode then command ("ocamlc -a -o neko.cma " ^ files);
  84. if native then command ("ocamlopt -a -o neko.cmxa " ^ files);
  85. Sys.chdir "..";
  86. (* ZIPLIB *)
  87. Sys.chdir "ziplib";
  88. let files = "-I .. -I ../extc zlib.mli zlib.ml zip.mli zip.ml" in
  89. if bytecode then command ("ocamlc -a -o zip.cma " ^ files);
  90. if native then command ("ocamlopt -a -o zip.cmxa " ^ files);
  91. Sys.chdir "..";
  92. (* JAVALIB *)
  93. Sys.chdir "javalib";
  94. let files = "-I .. jData.ml jReader.ml" in
  95. if bytecode then command ("ocamlc -a -o java.cma " ^ files);
  96. if native then command ("ocamlopt -a -o java.cmxa " ^ files);
  97. Sys.chdir "..";
  98. (* TTFLIB *)
  99. Sys.chdir "ttflib";
  100. let files = "-I .. -I ../extlib -I ../swflib tTFData.ml tTFParser.ml tTFTools.ml tTFSwfWriter.ml tTFCanvasWriter.ml tTFJsonWriter.ml main.ml" in
  101. if bytecode then command ("ocamlc -a -o ttf.cma " ^ files);
  102. if native then command ("ocamlopt -a -o ttf.cmxa " ^ files);
  103. Sys.chdir "..";
  104. (* XML-LIGHT *)
  105. Sys.chdir "xml-light";
  106. command ("ocamlyacc xml_parser.mly");
  107. command ("ocamlc xml.mli dtd.mli xml_parser.mli xml_lexer.mli");
  108. command ("ocamllex xml_lexer.mll");
  109. let files = "xml_parser.ml xml_lexer.ml dtd.ml xmlParser.mli xmlParser.ml xml.ml" in
  110. if bytecode then command ("ocamlc -a -o xml-light.cma " ^ files);
  111. if native then command ("ocamlopt -a -o xml-light.cmxa " ^ files);
  112. Sys.chdir "..";
  113. Sys.chdir "../..";
  114. in
  115. let compile() =
  116. (try Unix.mkdir "bin" 0o740 with Unix.Unix_error(Unix.EEXIST,_,_) -> ());
  117. Sys.chdir "haxe";
  118. (* HAXE *)
  119. command "ocamllex lexer.mll";
  120. let libs = [
  121. "libs/extLib";
  122. "libs/extc/extc";
  123. "libs/swflib/swflib";
  124. "libs/xml-light/xml-light";
  125. "libs/neko/neko";
  126. "libs/javalib/java";
  127. "unix";
  128. "libs/ziplib/zip";
  129. "str";
  130. "libs/ttflib/ttf"
  131. ] in
  132. let paths = [
  133. "libs";
  134. "libs/swflib";
  135. "libs/xml-light";
  136. "libs/extc";
  137. "libs/neko";
  138. "libs/ziplib";
  139. "libs/javalib";
  140. "libs/ttflib"
  141. ] in
  142. let mlist = [
  143. "ast";"lexer";"type";"common";"parser";"typecore";
  144. "genxml";"optimizer";"typeload";"codegen";
  145. "gencommon"; "genneko";"genas3";"genjs";"genswf8";"genswf9";"genswf";"genphp";"gencpp"; "gencs";"genjava";
  146. "interp";"typer";"matcher";"dce";"main";
  147. ] in
  148. let path_str = String.concat " " (List.map (fun s -> "-I " ^ s) paths) in
  149. let libs_str ext = " " ^ String.concat " " (List.map (fun l -> l ^ ext) libs) ^ " " in
  150. ocamlc (path_str ^ " -pp camlp4o " ^ modules mlist ".ml");
  151. if bytecode then command ("ocamlc -custom -o ../bin/haxe-byte" ^ exe_ext ^ libs_str ".cma" ^ modules mlist ".cmo");
  152. if native then command ("ocamlopt -o ../bin/haxe" ^ exe_ext ^ libs_str ".cmxa" ^ modules mlist ".cmx");
  153. in
  154. let make_std() =
  155. if Sys.file_exists "../bin/std" then command (if os_type = "Win32" then "rmdir /S /Q ..\\bin\\std" else "rm -rf ../bin/std");
  156. command "svn export -q std ../bin/std";
  157. in
  158. let startdir = Sys.getcwd() in
  159. try
  160. download();
  161. compile_libs();
  162. compile();
  163. make_std();
  164. Sys.chdir startdir;
  165. with
  166. Failure msg ->
  167. Sys.chdir startdir;
  168. prerr_endline msg; exit 1