2
(**************************************************************************)
3
(* Copyright (c) 2009, Romain BARDOU *)
4
(* All rights reserved. *)
6
(* Redistribution and use in source and binary forms, with or without *)
7
(* modification, are permitted provided that the following conditions are *)
10
(* * Redistributions of source code must retain the above copyright *)
11
(* notice, this list of conditions and the following disclaimer. *)
12
(* * Redistributions in binary form must reproduce the above copyright *)
13
(* notice, this list of conditions and the following disclaimer in the *)
14
(* documentation and/or other materials provided with the distribution. *)
15
(* * Neither the name of Melt nor the names of its contributors may be *)
16
(* used to endorse or promote products derived from this software *)
17
(* without specific prior written permission. *)
19
(* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *)
20
(* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *)
21
(* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *)
22
(* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *)
23
(* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *)
24
(* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *)
25
(* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *)
26
(* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *)
27
(* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *)
28
(* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *)
29
(* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)
30
(**************************************************************************)
39
force "OCAMLC" "<path> OCaml bytecode compiler";
40
force "MLPOST" "<path> Mlpost library directory";
41
force "INSTALLBIN" "<path> Install directory (tool binaries)";
42
force "INSTALLLIB" "<path> Install directory (OCaml libraries)";
43
force "INSTALLMAN" "<path> Install directory (man pages)";
47
let ocamlc = SVar.make
48
~query: "OCaml bytecode compiler"
49
~guess: (guess_bins ["ocamlc.opt"; "ocamlc"])
53
let ocaml_dir = Filename.dirname !!ocamlc in
54
let ocaml_version = exec_line !!ocamlc ["-version"] in
55
echo "OCaml version: %s" ocaml_version;
56
let ocaml_where = exec_line !!ocamlc ["-where"] in
61
Filename.concat ocaml_dir (name ^ ".opt");
62
Filename.concat ocaml_dir name;
67
let v = Str.last_word (exec_line s ["-version"]) in
68
if name <> "ocamlbuild" || Version.ge ocaml_version "3.11" then
69
if not (Version.eq ocaml_version v) then
70
warning "Version of %s (%s) do not match \
71
compiler version (%s)" s v ocaml_version;
73
(String.uppercase name)
77
ocaml_var "ocamlbuild";
80
ocaml_var "ocamlyacc";
83
BVar.usimple "NATDYNLINK" (Version.ge ocaml_version "3.11");
85
let cm_dir pkg cm = SVar.make
88
Filename.concat ocaml_where pkg;
90
Filename.concat ocaml_dir pkg;
94
exec_line "ocamlfind" ["query"; pkg; "2> /dev/null"] :: l
95
with Exec_error _ -> l)
96
~check: (fun s -> Sys.file_exists (Filename.concat s cm))
100
cm_dir "mlpost" "mlpost.cma"
101
~query: "Mlpost library directory"
102
~fail: (fun () -> warning "Mlpost not found"; "") "MLPOSTLIBDIR" in
104
let check_mlpost_version () =
106
let v = exec_line (which "mlpost") ["-version"; "2> /dev/null"] in
107
if Version.ge v "0.6" || v = "current" then begin
108
echo "Mlpost version: %s" v;
111
echo "Mlpost version too old (%s)" v;
116
warning "Mlpost tool not found.";
119
warning "Mlpost version too old (<0.6).";
123
let mlpost = !!mlpost_cm_dir <> "" && check_mlpost_version () in
124
BVar.usimple "MLPOST" mlpost;
125
SVar.usimple "MLPOSTSPECIFIC"
126
(if mlpost then "melt/mlpost_on.ml" else "melt/mlpost_off.ml");
128
let mlpost_with_cairo =
130
try ignore (exec_line "mlpost" ["-cairo"]); true
131
with Exec_error _ -> false
133
BVar.usimple "MLPOSTCAIRO" mlpost_with_cairo;
135
let cm_dir_if_mlpost_with_cairo pkg cm name var =
136
if mlpost_with_cairo then
138
~query: (name^" library directory")
139
~fail: (fun () -> warning "%s not found" name; "")
142
cm_dir pkg cm ~fail: (fun () -> "") var
145
let bitstring_cm_dir =
146
cm_dir_if_mlpost_with_cairo
147
"bitstring" "bitstring.cma" "Bitstring" "BITSTRINGLIBDIR"
151
cm_dir_if_mlpost_with_cairo
152
"cairo" "cairo.cma" "Cairo" "CAIROLIBDIR"
156
~query: "Install directory (tool binaries)"
157
~guess: (fun () -> ["/usr/local/bin"])
161
~query: "Install directory (OCaml libraries)"
162
~guess: (fun () -> let l = [Filename.concat ocaml_where "melt"] in
164
let dir = exec_line "ocamlfind"
165
["printconf"; "destdir"; "2> /dev/null"] in
166
(Filename.concat dir "melt"):: l
167
with Exec_error _ -> l
172
~query: "Install directory (man pages)"
173
~guess: (fun () -> ["/usr/local/share/man/man1"])
176
let ocaml_includes l =
177
let l = List.filter (fun s -> s <> "" && s <> ocaml_where) l in
178
let l = List.map (sprintf "-I %s") l in
190
SVar.simple "OCAMLINCLUDES" (ocaml_includes includes)
193
let ocamlbuild_flags l =
194
let l = String.concat " " l in
195
let l = Str.replace_char l ' ' ',' in
196
if l <> "" then sprintf "-cflags %s -lflags %s" l l else ""
199
SVar.usimple "OCAMLBUILDFLAGS" (ocamlbuild_flags [!!ocaml_includes]);