2 * Install - ExtLib installation
3 * Copyright (C) 2003 Nicolas Cannasse
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version,
9 * with the special exception on linking described in file LICENSE.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50 String.concat
" " (List.map
(fun m
-> m ^ suffix
) modules)
52 let obj_ext , lib_ext
, cp_cmd
, path_type
= match Sys.os_type
with
53 | "Unix" | "Cygwin" | "MacOS" -> ".o" , ".a" , "cp", PathUnix
54 | "Win32" -> ".obj" , ".lib" , "copy", PathDos
55 | _
-> failwith
"Unknown OS"
59 let ecode = Sys.command cmd
in
60 if ecode <> 0 then failwith
(sprintf
"Exit Code %d - Stopped" ecode)
63 if dest
<> "" && dest
<> "." then begin
64 print_endline
("Installing " ^ file
);
65 let path = dest ^ file
in
66 (try Sys.remove
path with _
-> ());
70 _
-> failwith
"Aborted"
77 let c = p
.[String.length p
- 1] in
78 if c = '
/'
|| c = '
\\'
then
81 p ^
(match path_type
with PathUnix
-> "/" | PathDos
-> "\\")
87 _
-> prerr_endline
("Warning : failed to delete " ^ file
)
90 let findlib = Sys.command
(if Sys.os_type
= "Win32" then "ocamlfind printconf 2>NUL" else "ocamlfind printconf") = 0 in
91 if findlib then print_endline
"Using Findlib";
94 type install_dir
= Findlib
| Dir
of string
97 let autodir = ref None
in
98 let docflag = ref None
in
99 let autodoc = ref false in
100 let autobyte = ref false in
101 let autonative = ref false in
102 let usage = "ExtLib installation program v1.3\n(c)2003,2004 Nicolas Cannasse" in
104 ("-d", Arg.String
(fun s
-> autodir := Some s
) , "<dir> : install in target directory");
105 ("-b", Arg.Unit
(fun () -> autobyte := true) , ": byte code installation");
106 ("-n", Arg.Unit
(fun () -> autonative := true) , ": native code installation");
107 ("-doc", Arg.Unit
(fun () -> docflag := Some
true) , ": documentation installation");
108 ("-nodoc", Arg.Unit
(fun () -> docflag := Some
false) , ": documentation installation");
109 ] (fun s
-> raise
(Arg.Bad s
)) usage;
110 let findlib = is_findlib () in
114 if not
!autobyte && not
!autonative && not
!autodoc then failwith
"Nothing to do.";
115 Dir
(complete_path dir
)
118 if !autobyte || !autonative then
119 (!autobyte, !autonative)
121 printf
"Choose one of the following :\n1- Bytecode installation only\n2- Native installation only\n3- Both Native and Bytecode installation\n> ";
122 (match read_line
() with
126 | _
-> failwith
"Invalid choice, exit.")
130 if not
findlib then begin
131 printf
"Choose installation directory :\n> ";
132 let dest = complete_path (read_line
()) in
134 close_out
(open_out
(dest ^
"test.file"));
135 Sys.remove (dest ^
"test.file");
137 _
-> failwith
("Directory " ^
dest ^
" does not exists or cannot be written."));
141 autonative := native
;
148 printf
"Do you want to generate ocamldoc documentation (Y/N) ?\n> ";
149 (match read_line
() with
152 | _
-> failwith
"Invalid choice, exit.")
156 match install_dir with
157 Findlib
-> "extlib-doc"
159 sprintf
"%sextlib-doc" install_dir in
160 if !autodoc && not
(Sys.file_exists
doc_dir) then run (sprintf
"mkdir %s" doc_dir);
161 run (sprintf
"ocamlc -c %s" (m_list ".mli"));
162 if !autobyte then begin
163 List.iter
(fun m
-> run (sprintf
"ocamlc -c %s.ml" m
)) modules;
164 run (sprintf
"ocamlc -a -o extLib.cma %s extLib.ml" (m_list ".cmo"));
165 List.iter
(fun m
-> remove (m ^
".cmo")) modules;
168 if !autonative then begin
169 List.iter
(fun m
-> run (sprintf
"ocamlopt -c %s.ml" m
)) modules;
170 run (sprintf
"ocamlopt -a -o extLib.cmxa %s extLib.ml" (m_list ".cmx"));
171 List.iter
(fun m
-> remove (m ^
obj_ext)) modules;
172 remove ("extLib" ^
obj_ext);
174 if !autodoc then begin
175 run (sprintf
"ocamldoc -sort -html -d %s %s" doc_dir (m_list ".mli"));
176 run ((match path_type
with
177 | PathDos
-> sprintf
"%s odoc_style.css %s\\style.css";
178 | PathUnix
-> sprintf
"%s odoc_style.css %s/style.css") cp_cmd
doc_dir);
180 match install_dir with
182 let files = Buffer.create
0 in
184 Buffer.add_string
files (m ^
".cmi");
185 Buffer.add_char
files ' '
;
186 Buffer.add_string
files (m ^
".mli");
187 Buffer.add_char
files ' '
)
189 Buffer.add_string
files "extLib.cmi ";
190 if !autobyte then Buffer.add_string
files "extLib.cma ";
191 if !autonative then begin
192 Buffer.add_string
files "extLib.cmxa ";
193 Buffer.add_string
files ("extLib" ^ lib_ext^
" ");
195 let files = Buffer.contents
files in
196 run (sprintf
"ocamlfind install extlib %s META" files);
199 copy (m ^
".cmi") install_dir;
200 if !autonative then copy (m ^
".cmx") install_dir
201 ) ("extLib" :: modules);
202 if !autobyte then copy "extLib.cma" install_dir;
203 if !autonative then begin
204 copy "extLib.cmxa" install_dir;
205 copy ("extLib" ^ lib_ext
) install_dir;