@@ -39,6 +39,7 @@ let nostdlib = ref false
3939let use_menhir = ref false
4040let catch_errors = ref true
4141let use_ocamlfind = ref false
42+ let plugin_use_ocamlfind = ref false
4243let toolchain = ref " "
4344
4445(* Currently only ocamlfind and menhir is defined as no-core tool,
@@ -85,7 +86,9 @@ let () =
8586 [" ocamlc" ; " ocamlopt" ; " ocamldep" ; " ocamldoc" ;
8687 " ocamlyacc" ; " menhir" ; " ocamllex" ; " ocamlmklib" ; " ocamlmktop" ; " ocamlfind" ]
8788let ocamlc = ref (V " OCAMLC" )
89+ let plugin_ocamlc = ref (V " OCAMLC" )
8890let ocamlopt = ref (V " OCAMLOPT" )
91+ let plugin_ocamlopt = ref (V " OCAMLOPT" )
8992let ocamldep = ref (V " OCAMLDEP" )
9093let ocamldoc = ref (V " OCAMLDOC" )
9194let ocamlyacc = ref N
@@ -99,6 +102,7 @@ let ocamlfind arg =
99102 S [! ocamlfind_cmd; arg]
100103 else
101104 S [! ocamlfind_cmd; A " -toolchain" ; A ! toolchain; arg]
105+ let plugin_ocamlfind arg = S [! ocamlfind_cmd; arg]
102106let program_to_execute = ref false
103107let must_clean = ref false
104108let show_documentation = ref false
@@ -142,7 +146,9 @@ let dummy = "*invalid-dummy-string*";; (* Dummy string for delimiting the latest
142146 * multiple/installed plugins *)
143147let use_jocaml () =
144148 ocamlc := A " jocamlc" ;
149+ plugin_ocamlc := A " jocamlc" ;
145150 ocamlopt := A " jocamlopt" ;
151+ plugin_ocamlopt := A " jocamlopt" ;
146152 ocamldep := A " jocamldep" ;
147153 ocamlyacc := A " jocamlyacc" ;
148154 ocamllex := A " jocamllex" ;
@@ -234,11 +240,16 @@ let spec = ref (
234240 " -classic-display" , Set Log. classic_display, " Display executed commands the old-fashioned way" ;
235241 " -use-menhir" , Set use_menhir, " Use menhir instead of ocamlyacc" ;
236242 " -use-jocaml" , Unit use_jocaml, " Use jocaml compilers instead of ocaml ones" ;
237- " -use-ocamlfind" , Set use_ocamlfind, " Use the 'ocamlfind' wrapper instead of \
243+ " -use-ocamlfind" , Unit ( fun () -> use_ocamlfind := true ; plugin_use_ocamlfind := true ) , " Use the 'ocamlfind' wrapper instead of \
238244 using Findlib directly to determine command-line arguments. \
239- Use -no-ocamlfind to disable." ;
240- " -no-ocamlfind" , Clear use_ocamlfind, " Don't use ocamlfind." ;
241- " -toolchain" , Set_string toolchain, " <toolchain> Set the Findlib toolchain to use." ;
245+ Use -no-ocamlfind to disable. Implies -plugin-use-ocamlfind." ;
246+ " -no-ocamlfind" , Unit (fun () -> use_ocamlfind := false ; plugin_use_ocamlfind := false ), " Don't use ocamlfind. Implies -plugin-no-ocamlfind." ;
247+ " -plugin-use-ocamlfind" , Set plugin_use_ocamlfind, " Use the 'ocamlfind' wrapper \
248+ for building myocamlbuild.ml" ;
249+ " -plugin-no-ocamlfind" , Clear plugin_use_ocamlfind, " Don't use ocamlfind \
250+ for building myocamlbuild.ml" ;
251+ " -toolchain" , Set_string toolchain, " <toolchain> Set the Findlib toolchain to use. \
252+ The default toolchain is always used for building myocamlbuild.ml." ;
242253
243254 " -j" , Set_int Command. jobs, " <N> Allow N jobs at once (0 for unlimited)" ;
244255
@@ -248,7 +259,11 @@ let spec = ref (
248259 " -where" , Unit (fun () -> print_endline ! Ocamlbuild_where. libdir; raise Exit_OK ), " Display the install library directory" ;
249260 " -which" , String (fun cmd -> print_endline (find_tool cmd); raise Exit_OK ), " <command> Display path to the tool command" ;
250261 " -ocamlc" , set_cmd ocamlc, " <command> Set the OCaml bytecode compiler" ;
262+ " -plugin-ocamlc" , set_cmd plugin_ocamlc, " <command> Set the OCaml bytecode compiler \
263+ used when building myocamlbuild.ml (only)" ;
251264 " -ocamlopt" , set_cmd ocamlopt, " <command> Set the OCaml native compiler" ;
265+ " -plugin-ocamlopt" , set_cmd plugin_ocamlopt, " <command> Set the OCaml native compiler \
266+ used when building myocamlbuild.ml (only)" ;
252267 " -ocamldep" , set_cmd ocamldep, " <command> Set the OCaml dependency tool" ;
253268 " -ocamldoc" , set_cmd ocamldoc, " <command> Set the OCaml documentation generator" ;
254269 " -ocamlyacc" , set_cmd ocamlyacc, " <command> Set the ocamlyacc tool" ;
@@ -305,34 +320,47 @@ let init () =
305320 Log. init log
306321 in
307322
323+ let with_ocamlfind (ocamlfind , command_name , command_ref ) =
324+ command_ref := match ! command_ref with
325+ | Sh user_command ->
326+ (* this command has been set by the user
327+ using an -ocamlc, -ocamlopt, etc. flag;
328+
329+ not all such combinations make sense (eg. "ocamlfind
330+ /my/special/path/to/ocamlc" will make ocamlfind choke),
331+ but the user will see the error and hopefully fix the
332+ flags. *)
333+ ocamlfind & (Sh user_command);
334+ | _ -> ocamlfind & A command_name
335+ in
336+
308337 if ! use_ocamlfind then begin
309338 begin try ignore(Command. search_in_path " ocamlfind" )
310339 with Not_found ->
311340 failwith " ocamlfind not found on path, but -no-ocamlfind not used"
312341 end ;
313342
314- let with_ocamlfind (command_name , command_ref ) =
315- command_ref := match ! command_ref with
316- | Sh user_command ->
317- (* this command has been set by the user
318- using an -ocamlc, -ocamlopt, etc. flag;
319-
320- not all such combinations make sense (eg. "ocamlfind
321- /my/special/path/to/ocamlc" will make ocamlfind choke),
322- but the user will see the error and hopefully fix the
323- flags. *)
324- ocamlfind & (Sh user_command);
325- | _ -> ocamlfind & A command_name
326- in
327343 (* Note that plugins can still modify these variables After_options.
328344 This design decision can easily be changed. *)
329345 List. iter with_ocamlfind [
330- " ocamlc" , ocamlc;
331- " ocamlopt" , ocamlopt;
332- " ocamldep" , ocamldep;
333- " ocamldoc" , ocamldoc;
334- " ocamlmklib" , ocamlmklib;
335- " ocamlmktop" , ocamlmktop;
346+ ocamlfind, " ocamlc" , ocamlc;
347+ ocamlfind, " ocamlopt" , ocamlopt;
348+ ocamlfind, " ocamldep" , ocamldep;
349+ ocamlfind, " ocamldoc" , ocamldoc;
350+ ocamlfind, " ocamlmklib" , ocamlmklib;
351+ ocamlfind, " ocamlmktop" , ocamlmktop;
352+ ]
353+ end ;
354+
355+ if ! plugin_use_ocamlfind then begin
356+ begin try ignore(Command. search_in_path " ocamlfind" )
357+ with Not_found ->
358+ failwith " ocamlfind not found on path, but -no-plugin-ocamlfind not used"
359+ end ;
360+
361+ List. iter with_ocamlfind [
362+ plugin_ocamlfind, " ocamlc" , plugin_ocamlc;
363+ plugin_ocamlfind, " ocamlopt" , plugin_ocamlopt;
336364 ]
337365 end ;
338366
0 commit comments