···11+let () =
22+ let exe = ".exe" in
33+ let ocamlc =
44+ let (base, suffix) =
55+ let s = Sys.executable_name in
66+ if Filename.check_suffix s exe then
77+ (Filename.chop_suffix s exe, exe)
88+ else
99+ (s, "") in
1010+ base ^ "c" ^ suffix in
1111+ if Sys.ocaml_version <> "%{_:version}%" then
1212+ (Printf.eprintf
1313+ "ERROR: The compiler found at %%s has version %%s,\n\
1414+ and this package requires %{_:version}%.\n\
1515+ You should use e.g. 'opam switch create %{_:name}%.%%s' \
1616+ instead."
1717+ ocamlc Sys.ocaml_version Sys.ocaml_version;
1818+ exit 1)
1919+ else
2020+ let ocamlc_digest = Digest.to_hex (Digest.file ocamlc) in
2121+ let libdir =
2222+ if Sys.command (ocamlc^" -where > %{_:name}%.config") = 0 then
2323+ let ic = open_in "%{_:name}%.config" in
2424+ let r = input_line ic in
2525+ close_in ic;
2626+ Sys.remove "%{_:name}%.config";
2727+ r
2828+ else
2929+ failwith "Bad return from 'ocamlc -where'"
3030+ in
3131+ let graphics = Filename.concat libdir "graphics.cmi" in
3232+ let graphics_digest =
3333+ if Sys.file_exists graphics then
3434+ Digest.to_hex (Digest.file graphics)
3535+ else
3636+ String.make 32 '0'
3737+ in
3838+ let oc = open_out "%{_:name}%.config" in
3939+ Printf.fprintf oc "opam-version: \"2.0\"\n\
4040+ file-depends: [ [ %%S %%S ] [ %%S %%S ] ]\n\
4141+ variables { path: %%S }\n"
4242+ ocamlc ocamlc_digest graphics graphics_digest (Filename.dirname ocamlc);
4343+ close_out oc