1 (****************************************************************************)
5 (* INRIA Rocquencourt *)
7 (* Copyright 2006 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed under *)
9 (* the terms of the GNU Library General Public License, with the special *)
10 (* exception on linking described in LICENSE at the top of the Objective *)
11 (* Caml source tree. *)
13 (****************************************************************************)
16 * - Daniel de Rauglaudre: initial shell version
17 * - Nicolas Pouillard: rewriting in OCaml
27 value (interfaces
, options
, includes
) =
28 let rec self (interf
, opts
, incl
) =
30 [ [] -> (List.rev interf
, List.rev opts
, List.rev incl
)
31 | ["-I"; dir
:: args
] -> self (interf
, opts
, [dir
; "-I" :: incl
]) args
32 | ["-version" :: _
] ->
33 do { printf
"mkcamlp4, version %s@." version
; exit
0 }
34 | [ arg
:: args
] when check_suffix arg
".cmi" ->
35 let basename = String.capitalize
(Filename.chop_suffix
36 (Filename.basename arg
) ".cmi") in
37 self ([ basename :: interf
], opts
, incl
) args
39 self (interf
, [ arg
:: opts
], incl
) args
]
40 in self ([], [], ["."; "-I"]) (List.tl
(Array.to_list
Sys.argv
));
43 let cmd = String.concat
" " l
in
44 let () = Format.printf
"%s@." cmd in
49 if st <> 0 then failwith
("Exit: " ^ string_of_int
st) else ();
51 value crc_ml
= Filename.temp_file
"crc_" ".ml";
52 value crc
= Filename.chop_suffix crc_ml
".ml";
53 value clean
() = run
["rm"; "-f"; crc_ml
; crc^
".cmi"; crc^
".cmo"];
56 run
([ocaml_standard_library^
"/extract_crc"; "-I"; camlp4_standard_library
]
57 @ includes
@ interfaces
@ [">"; crc_ml
]);
59 let cout = open_out_gen
[Open_wronly
; Open_append
; Open_text
] 0o666 crc_ml
in do {
60 output_string
cout "let _ = Dynlink.add_available_units crc_unit_list\n";
64 run
(["ocamlc"; "-I"; camlp4_standard_library
; "Camlp4.cma"; crc_ml
]
65 @ includes
@ options
@ ["Camlp4Bin.cmo"; "-linkall"]);
68 with exc
-> do { clean
(); raise exc
};