Commits

camlspotter committed a3a87e4

ocaml Build.ml <command> interface

  • Participants
  • Parent commits a88c8d8
  • Branches android

Comments (0)

Files changed (1)

     loop ()
 end
 
-(* Host tools: ocamlrun and ocamlyacc must exist in the path. *)
-let ocamlrun  = Test.program "ocamlrun"
-let ocamlyacc = Test.program "ocamlyacc"
-let _ = printf "Host compiler tools:\n%!"
-let _ = printf "ocamlrun:  %s\n%!" ocamlrun
-let _ = printf "ocamlyacc: %s\n%!" ocamlyacc
+module Configure(A:sig end) = struct
+  (* Host tools: ocamlrun and ocamlyacc must exist in the path. *)
+  let ocamlrun  = Test.program "ocamlrun"
+  let ocamlyacc = Test.program "ocamlyacc"
+  let _ = printf "Host compiler tools:\n%!"
+  let _ = printf "ocamlrun:  %s\n%!" ocamlrun
+  let _ = printf "ocamlyacc: %s\n%!" ocamlyacc
+  
+  (* Android SDK compiler check *)
+  
+  let cross_tool_dir = 
+    sprintf "%s/toolchains/%s-linux-androideabi-%s/prebuilt/%s" 
+      ndk_home target_arch gcc_version host_arch
+  
+  let libgcc_dir = 
+    sprintf "%s/toolchains/%s-linux-androideabi-%s/prebuilt/%s/lib/gcc/%s-linux-androideabi/%s" 
+      ndk_home target_arch gcc_version host_arch target_arch gcc_version
+  
+  let libc_dir = 
+    sprintf "%s/platforms/android-%s/arch-%s/usr/lib"
+      ndk_home platform_version target_arch 
+  
+  let target_root_dir = 
+    sprintf "%s/platforms/android-%s/arch-%s"
+      ndk_home platform_version target_arch 
+  
+  let _ = 
+    Test.must_exist ndk_home "ndk-build";
+    Test.must_exist cross_tool_dir (sprintf "bin/%s-linux-androideabi-gcc" target_arch);
+    Test.must_exist libgcc_dir "libgcc.a";
+    Test.must_exist libc_dir "libc.so";
+    Test.must_exist target_root_dir "usr/include/stdlib.h"
+  
+  (* Create config/Makefile *)
+  let tbl = [ "prefix"          , prefix
+            ; "cross_tool_dir"  , cross_tool_dir
+            ; "libgcc_dir"      , libgcc_dir
+            ; "target_root_dir" , target_root_dir
+            ]
+  
+  let _ = At.replace_file tbl "config/Makefile.android.temp" "config/Makefile"
+  
+  (* Copy stdlib.h *)
+  let _ =
+    let path = sprintf "%s/usr/include/stdlib.h" target_root_dir in
+    printf "Copying NDK stdlib.h: %s\n%!" path;
+    Sys.cp (sprintf "%s/usr/include/stdlib.h" target_root_dir) "byterun"
+  
+  (* Patch stdlib.h *)
+  let _ =
+    printf "Patching copied stdlib.h...\n%!";
+    Sys.patch_p1 "ocaml-android-3.12.1-stdlib_h.patch"
 
-(* Android SDK compiler check *)
+  let _ = printf "Configuration done\n%!"
+end
 
-let cross_tool_dir = 
-  sprintf "%s/toolchains/%s-linux-androideabi-%s/prebuilt/%s" 
-    ndk_home target_arch gcc_version host_arch
+module Build(A:sig end) = struct
+  module C = Configure(struct end)
+  open C
 
-let libgcc_dir = 
-  sprintf "%s/toolchains/%s-linux-androideabi-%s/prebuilt/%s/lib/gcc/%s-linux-androideabi/%s" 
-    ndk_home target_arch gcc_version host_arch target_arch gcc_version
-
-let libc_dir = 
-  sprintf "%s/platforms/android-%s/arch-%s/usr/lib"
-    ndk_home platform_version target_arch 
-
-let target_root_dir = 
-  sprintf "%s/platforms/android-%s/arch-%s"
-    ndk_home platform_version target_arch 
+  (* Build target ocamlrun *)
+  let _ =
+    printf "Building target ocamlrun (byterun/ocamlrun.target)\n%!";
+    Sys.must "(cd byterun; make all)";
+    Unix.rename "byterun/ocamlrun" "byterun/ocamlrun.target"
+  
+  (* Build target ocamlyacc *)
+  let _ =
+    printf "Building target ocamlyacc (yacc/ocamlyacc.target)\n%!";
+    Sys.must "(cd yacc; make all)";
+    Unix.rename "yacc/ocamlyacc" "yacc/ocamlyacc.target"
+  
+  (* Recovering host ocamlrun and ocamlyacc *)
+  let _ =
+    printf "Recovering host ocamlrun and ocamlyacc\n%!";
+    Sys.must "cp %s byterun" ocamlrun;
+    Sys.must "cp %s yacc"    ocamlyacc
+  
+  (* Make world and opt *)
+  let _ =
+    printf "Now building!\n%!";
+    Sys.must "make world opt";
+    printf "Done!!\n%!"
+end
 
 let _ = 
-  Test.must_exist ndk_home "ndk-build";
-  Test.must_exist cross_tool_dir (sprintf "bin/%s-linux-androideabi-gcc" target_arch);
-  Test.must_exist libgcc_dir "libgcc.a";
-  Test.must_exist libc_dir "libc.so";
-  Test.must_exist target_root_dir "usr/include/stdlib.h"
+  let print_help () = prerr_endline 
+"ocaml Build.ml <command>
 
-(* Create config/Makefile *)
-let tbl = [ "prefix"          , prefix
-          ; "cross_tool_dir"  , cross_tool_dir
-          ; "libgcc_dir"      , libgcc_dir
-          ; "target_root_dir" , target_root_dir
-          ]
-
-let _ = At.replace_file tbl "config/Makefile.android.temp" "config/Makefile"
-
-(* Copy stdlib.h *)
-let _ =
-  let path = sprintf "%s/usr/include/stdlib.h" target_root_dir in
-  printf "Copying NDK stdlib.h: %s\n%!" path;
-  Sys.cp (sprintf "%s/usr/include/stdlib.h" target_root_dir) "byterun"
-
-(* Patch stdlib.h *)
-let _ =
-  printf "Patching copied stdlib.h...\n%!";
-  Sys.patch_p1 "ocaml-android-3.12.1-stdlib_h.patch"
-
-(* Build target ocamlrun *)
-let _ =
-  printf "Building target ocamlrun (byterun/ocamlrun.target)\n%!";
-  Sys.must "(cd byterun; make all)";
-  Unix.rename "byterun/ocamlrun" "byterun/ocamlrun.target"
-
-(* Build target ocamlyacc *)
-let _ =
-  printf "Building target ocamlyacc (yacc/ocamlyacc.target)\n%!";
-  Sys.must "(cd yacc; make all)";
-  Unix.rename "yacc/ocamlyacc" "yacc/ocamlyacc.target"
-
-(* Recovering host ocamlrun and ocamlyacc *)
-let _ =
-  printf "Recovering host ocamlrun and ocamlyacc\n%!";
-  Sys.must "cp %s byterun" ocamlrun;
-  Sys.must "cp %s yacc"    ocamlyacc
-
-(* Make world and opt *)
-let _ =
-  printf "Now building!\n%!";
-  Sys.must "make world opt";
-  printf "Done!!\n%!"
+  commands:
+    config    Test the configuration writtein in Build.ml
+    build     Build the system
+    clean     Clean the build
+"
+  in
+  if Array.length Sys.argv = 1 then print_help ()
+  else match Sys.argv.(1) with
+  | "config" -> 
+      let module M = Configure(struct end) in
+      ()
+  | "build" ->
+      let module M = Build(struct end) in
+      ()
+  | "clean" -> Sys.must "make clean"
+  | s ->
+      failwithf "Unknown command %s" s