From 8aa1ab77f16ccab01c5ac492901239b1f9d1e676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20Mart=C3=ADnez?= Date: Mon, 10 Feb 2025 16:50:27 -0800 Subject: [PATCH] Allow to override flavor --- lib/Driver.ml | 7 ++++++- lib/Options.ml | 9 +++++++++ src/Karamel.ml | 9 +++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Driver.ml b/lib/Driver.ml index 085b9b68..374bc988 100644 --- a/lib/Driver.ml +++ b/lib/Driver.ml @@ -428,7 +428,12 @@ let detect_cc () = KPrint.bprintf "%scc is:%s %s%s\n" Ansi.underline Ansi.reset !cc real end; - cc_flavor := detect_compiler_flavor !cc; + begin + match !Options.cc_flavor with + | Some f -> cc_flavor := f + | None -> cc_flavor := detect_compiler_flavor !cc + end; + if not !Options.silent then KPrint.bprintf "%scc flavor is:%s %s\n" Ansi.underline Ansi.reset (Options.string_of_compiler_flavor !cc_flavor); diff --git a/lib/Options.ml b/lib/Options.ml index 7ec74498..27cf0546 100644 --- a/lib/Options.ml +++ b/lib/Options.ml @@ -17,6 +17,14 @@ let string_of_compiler_flavor = function | Compcert -> "compcert" | MSVC -> "msvc" +let compiler_flavor_of_string = function + | "generic" -> Generic + | "gcc" -> GCC + | "clang" -> Clang + | "compcert" -> Compcert + | "msvc" -> MSVC + | s -> failwith ("unrecognized compiler flavor: " ^ s) + let pinc b = function | All -> Buffer.add_string b "*" | HeaderOnly h -> Buffer.add_string b h; Buffer.add_string b ".h" @@ -43,6 +51,7 @@ let verbose = ref false let silent = ref false let exe_name = ref "" let cc = ref "" +let cc_flavor : compiler_flavor option ref = ref None let m32 = ref false let fsopts: string list ref = ref [] let ccopts: string list ref = ref [] diff --git a/src/Karamel.ml b/src/Karamel.ml index 6b41ff19..a21dfb8a 100644 --- a/src/Karamel.ml +++ b/src/Karamel.ml @@ -191,8 +191,13 @@ Supported options:|} (* KaRaMeL as a driver *) "-fstar", Arg.Set_string Options.fstar, " fstar.exe to use; defaults to \ 'fstar.exe'"; - "-cc", Arg.Set_string Options.cc, " compiler to use; one of gcc (default), \ - compcert, g++, clang, msvc"; + "-cc", Arg.Set_string Options.cc, " compiler to use; default is 'cc'. \ + you can also set the CC environment variable"; + "-ccflavor", Arg.String (fun s -> + let flav = Options.compiler_flavor_of_string s in + Options.cc_flavor := Some flav), " C compiler flavor. This is \ + normally autodetected. It can be set to 'gcc', 'clang', 'compcert', 'msvc' \ + or 'generic'"; "-m32", Arg.Set Options.m32, " turn on 32-bit cross-compiling"; "-fsopt", Arg.String (prepend Options.fsopts), " option to pass to F* (use \ -fsopts to pass a comma-separated list of values)";