What's new? | Help | Directory | Sign in
Google
ocaml-plplot
PLplot library bindings for OCaml
  
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
open Ocamlbuild_plugin;;
open Command;;

(* ocamlfind packages required for compilation *)
let packages = "";;

(* Build an appropriate ocamlfind command line *)
let ocamlfind cmd =
S [A "ocamlfind"; A cmd; A "-package"; A packages];;

(* Link packages in when needed. *)
flag ["ocaml"; "link"; "program"] (A "-linkpkg");;

(* The camlidl command to use (default: first one found in $PATH) *)
let camlidl = S([A"camlidl"; A"-header"]);;

(* Files included in the main idl descriptor *)
let idl_includes = ["plplot_h.inc"];;

(* A simple function to check if a string is empty/whitespace *)
let is_all_whitespace s =
try
String.iter (fun c -> if c <> ' ' then raise Exit) s;
true
with Exit -> false

let get_env_elem s =
let it = getenv s in
match is_all_whitespace it with
true -> N
| false -> A it

let plplot_cflags = get_env_elem "PLPLOT_CFLAGS"
let plplot_libs = get_env_elem "PLPLOT_LIBS"
let plplot_libs_dirs = get_env_elem "PLPLOT_LIBS_DIRS"
let plplot_libs_libs = get_env_elem "PLPLOT_LIBS_LIBS"

let camlidl_lib = get_env_elem "CAMLIDL_LIB"
let camlidl_lib_dir = get_env_elem "CAMLIDL_LIB_DIR"
;;

dispatch begin function
| After_options ->
(* Redefine ocaml{c,opt,dep} to use the ocamlfind equivalents *)
Options.ocamlc := ocamlfind "c";
Options.ocamlopt := ocamlfind "opt";
Options.ocamldep := ocamlfind "dep";
| After_rules ->
(* Handle *.idl files properly... I think *)
rule "camlidl processing"
~prods:["%.mli"; "%.ml"; "%_stubs.c"]
~deps:["%.idl"]
begin fun env _build ->
let idl = env "%.idl" in
let tags = tags_of_pathname idl++"compile"++"camlidl" in
let cmd = Cmd(S[camlidl; T tags; P idl]) in
Seq [cmd]
end;

(* Include the plplot and camlidl compiler options for ocamlmklib *)
flag ["ocamlmklib"; "c"]
(S[plplot_libs; camlidl_lib_dir; camlidl_lib]);

(* gcc needs to know where to find the needed #includes *)
flag ["c"; "compile"]
(S[A"-ccopt"; plplot_cflags]);

(* Custom tag for OCaml bytecode *)
flag ["ocaml"; "link"; "byte"]
(A"-custom");

(* Use the proper extras when compiling the OCaml library *)
flag ["ocaml"; "link"; "library"; "byte"]
(S[A"-dllib"; A "-lplplot_stubs"; A"-cclib"; A"-lplplot_stubs";
A"-cclib"; plplot_libs; A"-cclib"; camlidl_lib]);

flag ["ocaml"; "link"; "library"; "native"]
(S[A"-cclib"; A"-lplplot_stubs"; A"-cclib"; plplot_libs;
A"-cclib"; camlidl_lib]);

(* Make sure the C pieces and built... *)
dep ["ocaml"; "compile"] ["libplplot_stubs.a"];

(* Any camlidl work must be updated if the camlidl inputs are changed *)
dep ["compile"; "camlidl"] idl_includes;

| _ -> ()
end
Show details Hide details

Change log

r48 by hcarty on Mar 11, 2008   Diff
* Makefile, libplplot_stubs.clib,
myocamlbuild.ml:
  - Fixes (??) to the build system.
ocamlbuild is still somewhat black
    magic to me.  The original build and
install worked for the
    toplevel but not for compiled code.
These changes seem to fix
    that problem.
Go to: 
Project members, sign in to write a code review

Older revisions

r43 by hcarty on Mar 04, 2008   Diff
* META:
  - Update to reflect that this does
not
    need Bigarray
* Makefile:
...
All revisions of this file

File info

Size: 2816 bytes, 88 lines