~ubuntu-branches/ubuntu/vivid/ocaml-melt/vivid

« back to all changes in this revision

Viewing changes to .pc/0003-Support-for-bytecode-architectures.patch/configure.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-02-13 18:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20110213181525-3j4zv4nnr6rs3f8w
Tags: 1.3.0-2
Add patch to support bytecode architectures (Closes: #613058)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
(**************************************************************************)
 
3
(* Copyright (c) 2009, Romain BARDOU                                      *)
 
4
(* All rights reserved.                                                   *)
 
5
(*                                                                        *)
 
6
(* Redistribution and  use in  source and binary  forms, with  or without *)
 
7
(* modification, are permitted provided that the following conditions are *)
 
8
(* met:                                                                   *)
 
9
(*                                                                        *)
 
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.                           *)
 
18
(*                                                                        *)
 
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
(**************************************************************************)
 
31
 
 
32
open Format
 
33
#use "totoconf.ml"
 
34
 
 
35
let () =
 
36
  init
 
37
    ~file: "Config"
 
38
    ~spec: [
 
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)";
 
44
    ]
 
45
    ();
 
46
 
 
47
  let ocamlc = SVar.make
 
48
    ~query: "OCaml bytecode compiler"
 
49
    ~guess: (guess_bins ["ocamlc.opt"; "ocamlc"])
 
50
    "OCAMLC"
 
51
  in
 
52
 
 
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
 
57
 
 
58
  let ocaml_var name =
 
59
    SVar.umake
 
60
      ~guess: (guess_bins [
 
61
                 Filename.concat ocaml_dir (name ^ ".opt");
 
62
                 Filename.concat ocaml_dir name;
 
63
                 name ^ ".opt";
 
64
                 name
 
65
               ])
 
66
      ~check: (fun s ->
 
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;
 
72
                 true)
 
73
      (String.uppercase name)
 
74
  in
 
75
 
 
76
  ocaml_var "ocamlopt";
 
77
  ocaml_var "ocamlbuild";
 
78
  ocaml_var "ocaml";
 
79
  ocaml_var "ocamllex";
 
80
  ocaml_var "ocamlyacc";
 
81
  ocaml_var "ocamldoc";
 
82
 
 
83
  BVar.usimple "NATDYNLINK" (Version.ge ocaml_version "3.11");
 
84
 
 
85
  let cm_dir pkg cm = SVar.make
 
86
    ~guess: (fun s ->
 
87
               let l = [
 
88
                 Filename.concat ocaml_where pkg;
 
89
                 ocaml_where;
 
90
                 Filename.concat ocaml_dir pkg;
 
91
                 ocaml_dir;
 
92
               ] in
 
93
               try
 
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))
 
97
  in
 
98
 
 
99
  let mlpost_cm_dir =
 
100
    cm_dir "mlpost" "mlpost.cma"
 
101
      ~query: "Mlpost library directory"
 
102
      ~fail: (fun () -> warning "Mlpost not found"; "") "MLPOSTLIBDIR" in
 
103
 
 
104
  let check_mlpost_version () =
 
105
    try
 
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;
 
109
        true
 
110
      end else begin
 
111
        echo "Mlpost version too old (%s)" v;
 
112
        false
 
113
      end
 
114
    with
 
115
      | Not_found ->
 
116
          warning "Mlpost tool not found.";
 
117
          false
 
118
      | Exec_error 2 ->
 
119
          warning "Mlpost version too old (<0.6).";
 
120
          false
 
121
  in
 
122
 
 
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");
 
127
 
 
128
  let mlpost_with_cairo =
 
129
    mlpost &&
 
130
      try ignore (exec_line "mlpost" ["-cairo"]); true
 
131
      with Exec_error _ -> false
 
132
  in
 
133
  BVar.usimple "MLPOSTCAIRO" mlpost_with_cairo;
 
134
 
 
135
  let cm_dir_if_mlpost_with_cairo pkg cm name var =
 
136
    if mlpost_with_cairo then
 
137
      cm_dir pkg cm
 
138
        ~query: (name^" library directory")
 
139
        ~fail: (fun () -> warning "%s not found" name; "")
 
140
        var
 
141
    else
 
142
      cm_dir pkg cm ~fail: (fun () -> "") var
 
143
  in
 
144
 
 
145
  let bitstring_cm_dir =
 
146
    cm_dir_if_mlpost_with_cairo
 
147
      "bitstring" "bitstring.cma" "Bitstring" "BITSTRINGLIBDIR"
 
148
  in
 
149
 
 
150
  let cairo_cm_dir =
 
151
    cm_dir_if_mlpost_with_cairo
 
152
      "cairo" "cairo.cma" "Cairo" "CAIROLIBDIR"
 
153
  in
 
154
 
 
155
  SVar.umake
 
156
    ~query: "Install directory (tool binaries)"
 
157
    ~guess: (fun () -> ["/usr/local/bin"])
 
158
    "INSTALLBIN";
 
159
 
 
160
  SVar.umake
 
161
    ~query: "Install directory (OCaml libraries)"
 
162
    ~guess: (fun () -> let l = [Filename.concat ocaml_where "melt"] in
 
163
             try
 
164
               let dir = exec_line "ocamlfind" 
 
165
                 ["printconf"; "destdir"; "2> /dev/null"] in
 
166
               (Filename.concat dir "melt"):: l
 
167
             with Exec_error _ -> l
 
168
            )
 
169
    "INSTALLLIB";
 
170
 
 
171
  SVar.umake
 
172
    ~query: "Install directory (man pages)"
 
173
    ~guess: (fun () -> ["/usr/local/share/man/man1"])
 
174
    "INSTALLMAN";
 
175
 
 
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
 
179
    String.concat " " l
 
180
  in
 
181
 
 
182
  let ocaml_includes =
 
183
    let includes =
 
184
      if mlpost then [
 
185
        !!mlpost_cm_dir;
 
186
        !!bitstring_cm_dir;
 
187
        !!cairo_cm_dir
 
188
      ] else []
 
189
    in
 
190
    SVar.simple "OCAMLINCLUDES" (ocaml_includes includes)
 
191
  in
 
192
 
 
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 ""
 
197
  in
 
198
 
 
199
  SVar.usimple "OCAMLBUILDFLAGS" (ocamlbuild_flags [!!ocaml_includes]);
 
200
 
 
201
  finish ()