Skip to content

Commit

Permalink
Update default /etc/opamrc with switch-defaults
Browse files Browse the repository at this point in the history
New switch-defaults set-up switch-arch, switch-cc and switch-libc.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
  • Loading branch information
dra27 committed May 10, 2017
1 parent 4aac3b3 commit 37d477a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/client/opamInitDefaults.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,40 @@ let eval_variables = [
"OCaml version present on your system independently of opam, if any";
]

let switch_variables =
let open OpamTypes in
let ocaml_system =
FIdent ([Some (OpamPackage.Name.of_string "ocaml-system")], OpamVariable.of_string "installed", None)
in
let not_ocaml_system =
FNot ocaml_system
in
let is_base_windows =
let os = FIdent ([], OpamVariable.of_string "os", None) in
let win32 = FString "win32" in
fun op -> FAnd (not_ocaml_system, FOp (os, op, win32))
in
let switch_var_name name = OpamVariable.of_string ("switch-"^name) in
let sys_var name description =
((switch_var_name name, S (Printf.sprintf "%%{sys-ocaml-%s}%%" name), description), Some ocaml_system)
in
let var ?(filter=not_ocaml_system) name value description =
((switch_var_name name, S value, description), Some filter)
in
[sys_var "arch" "Switch architecture (taken from system OCaml compiler)";
sys_var "cc" "Switch C compiler type (taken from system OCaml compiler)";
sys_var "libc" "Switch C runtime flavour (taken from system OCaml compiler)";
var "arch" "%{arch}%" "Switch architecture";
var "cc" "cc" "Switch C compiler type";
var ~filter:(is_base_windows `Eq) "libc" "msvc" "Switch C runtime flavour";
var ~filter:(is_base_windows `Neq) "libc" "libc" "Switch C runtime flavour"]

module I = OpamFile.InitConfig

let init_config =
I.empty |>
I.with_repositories
[OpamRepositoryName.of_string "default", (repository_url, None)] |>
I.with_default_compiler default_compiler |>
I.with_eval_variables eval_variables
I.with_eval_variables eval_variables |>
I.with_switch_defaults (OpamFile.SwitchDefaults.with_switch_variables switch_variables OpamFile.SwitchDefaults.empty)

0 comments on commit 37d477a

Please sign in to comment.