forked from iSCGroup/libres3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect.ml
More file actions
executable file
·992 lines (870 loc) · 31.5 KB
/
detect.ml
File metadata and controls
executable file
·992 lines (870 loc) · 31.5 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
open Printf;;
printf "OCaml compiler version ... %s\n%!" Sys.ocaml_version;;
#load "str.cma"
#load "unix.cma"
(* Version number handling based on odb.ml which is under the WTFPL license*)
module Ver = struct
(* A version number is a list of (string or number) *)
type ver_comp = Num of int | Str of string
type ver = ver_comp list
let rec cmp : ver -> ver -> int = fun a b ->
match a,b with
| [],[] -> 0 (* each component was equal *)
(* ignore trailing .0's *)
| Str"."::Num 0::t, [] -> cmp t [] | [], Str"."::Num 0::t -> cmp [] t
(* longer version numbers are before shorter ones *)
| _::_,[] -> 1 | [], _::_ -> -1
(* compare tails when heads are equal *)
| (x::xt), (y::yt) when x=y -> cmp xt yt
(* just compare numbers *)
| (Num x::_), (Num y::_) -> compare (x:int) y
(* extend with name ordering? *)
| (Str x::_), (Str y::_) -> compare (x:string) y
| (Num x::_), (Str y::_) -> -1 (* a number is always before a string *)
| (Str x::_), (Num y::_) -> 1 (* a string is always after a number *)
let to_ver = function
| Str.Delim s -> Str s
| Str.Text s -> Num (int_of_string s)
let parse_ver v =
try
List.map to_ver (Str.full_split (Str.regexp "[^0-9]+") v)
with Failure _ -> eprintf "Could not parse version: %s" v; []
let comp_to_string = function Str s -> s | Num n -> string_of_int n
let to_string v = String.concat "" (List.map comp_to_string v)
let (<?) a b = (cmp a (parse_ver b)) < 0
let (>?) a b = (cmp a (parse_ver b)) > 0
let (<=?) a b = (cmp a (parse_ver b)) <= 0
let (>=?) a b = (cmp a (parse_ver b)) >= 0
let (==?) a b = (cmp a (parse_ver b)) == 0
let ver_any _ = true
let ver_none _ = false
end;;
open Ver;;
if (parse_ver Sys.ocaml_version) <? "3.12.1" then begin
eprintf "OCaml version 3.12.1 or later is required";
exit 3;
end;;
(* Above this must be compatible with OCaml 3.09 *)
type clib = {
header: string;
lib: string;
fn: string;
}
type tool = {
tool: string;
}
type ocaml = {
findlibnames: string list;
version: ver -> bool;
}
type pkg_spec = CLib of clib | Tool of tool | OCaml of ocaml
type build = {
source : string;
findlibnames: string list;
configure: string list;
make: string list;
install: string list;
uninstall: string list;
}
type install = {
os_pkg_names: string list;
}
module Builds = Set.Make(struct
type t = string * build * string list
let compare = Pervasives.compare
end);;
module Installs = Set.Make(struct
type t = install
let compare = Pervasives.compare
end);;
let prefix = Filename.concat (Sys.getcwd ()) "_build";;
let prefix_bin = Filename.concat prefix "bin";;
let prefix_data = Filename.concat prefix "share";;
let prefix_var = Filename.concat prefix "var";;
let prefix_etc = Filename.concat prefix "etc";;
let destdir = Filename.concat prefix "lib/ocaml/site-lib";;
let ocamlpath = destdir;;
let ld_library_path = Filename.concat destdir "stublibs";;
(* libres3 features *)
let want_nethttpd = false;;
printf "Cleaning build directory\n";;
Sys.command "ocamlbuild -clean -quiet";;
Sys.command "cd libres3 && ocaml setup.ml -distclean -quiet";;
let append l1 l2 =
List.rev_append (List.rev l1) l2;;
let get_env_opt env =
try
Sys.getenv env
with Not_found ->
""
;;
module Packages : sig
type have = private No | MissingDev | Yes
type dep
type generate_build = dep list -> build
type action =
| Build of generate_build
| Install of install
type opt_flag = {
dep: dep;
enabled: string;
disabled: string;
}
val check_clib : name:string -> header:string -> lib:string list -> fn: string -> have
val check_tool : string -> commands:string list -> string -> (string -> bool) -> have * string
val check_findlib_package : (ver -> bool) -> string -> have
val check_ocaml :
name:string -> findlibnames:string list -> cmi:string*string*string -> version:(ver -> bool) -> have
val dependency :
string -> ?deps_opt:dep list -> ?deps:dep list ->
have -> action -> dep
(* (dep,flag) => if dep is required then add flag to configure flags *)
val flags : opt_flag list -> string list -> string list
val rules: dep list -> Builds.t * Installs.t
val print_summary : Builds.t -> Installs.t -> unit
val generate : string -> Builds.t -> unit
end = struct
type have = No | MissingDev | Yes
let run_command cmd =
Printf.eprintf "+ %s\n%!" cmd;
let rc = Sys.command cmd in
if rc <> 0 then
eprintf "Command '%s' exited with code '%d'\n%!" cmd rc;
rc = 0;;
let checking what check default =
printf "Checking for %s ... %!" what;
try
let result = check () in
begin match result with
| Yes -> printf "OK\n%!"
| MissingDev -> printf "No (-dev package missing)\n%!"
| No -> printf "No\n%!"
end;
result
with Not_found -> default
;;
let check_version verfn version =
printf "found %s ... %!" version;
if verfn (Ver.parse_ver version) then Yes else No
;;
let try_finally fn finally value =
let result =
begin try
fn value
with e ->
begin try finally value with _ -> () end;
raise e
end in
finally value;
result
;;
let remove name =
try
Sys.remove name
with Sys_error _ -> ();;
let with_tmpfile prefix suffix write_fn use_fn =
let name, ch = Filename.open_temp_file prefix suffix in
try_finally (fun name ->
try_finally write_fn close_out ch;
use_fn name;
) remove name
;;
let noop _ = ();;
let rec consume p =
try
ignore (input_line p);
consume p
with End_of_file -> ()
;;
let get_command_output cmd =
let pipe_out, pipe_in, pipe_err = Unix.open_process_full cmd (Unix.environment ()) in
let result =
try input_line pipe_out
with End_of_file -> "" in
consume pipe_out;
consume pipe_err;
if (Unix.close_process_full (pipe_out, pipe_in, pipe_err)) = (Unix.WEXITED 0) then
result
else
""
;;
let trim_start_re = Str.regexp "^ *"
let trim_end_re = Str.regexp " *$"
let trim str =
Str.replace_first trim_start_re "" (
Str.replace_first trim_end_re "" str)
;;
let append_env env value =
let v = trim (value) in
let old = trim (get_env_opt env) in
if v <> "" then
Unix.putenv env (
if old = "" || old = v then v
else (old ^ " " ^ v)
)
;;
let pkgconfig name =
let cppflags = get_command_output (sprintf "pkg-config %s --cflags-only-I" name)
and ldflags = get_command_output (sprintf "pkg-config %s --libs-only-L" name)
in
append_env "CPPFLAGS" cppflags;
append_env "LDFLAGS" ldflags;
cppflags, ldflags
;;
let check_clib ~name ~header ~lib ~fn =
checking (sprintf "C library '%s', lib%s, header '%s'" name
(String.concat "," lib) header) (fun () ->
let cppflags, ldflags = pkgconfig name in
printf "\n\tCPPFLAGS=%s LDFLAGS=%s\n%!" cppflags ldflags;
let test_name = sprintf "test_%s" name in
with_tmpfile test_name ".c" (fun tmp_out ->
fprintf tmp_out "#include <%s>\nint main(void)\n{ %s; return 0; }\n"
header fn
) (fun c_name ->
with_tmpfile test_name ".cma" noop (fun cma_name ->
let o_name = Filename.basename (Filename.chop_suffix c_name ".c") ^ ".o" in
let libs = String.concat " " (List.map (fun s -> "-l" ^ s) lib) in
let result = with_tmpfile test_name ".run" noop (fun run_name ->
run_command (
sprintf "ocamlc -verbose -a -o %s -ccopt \"%s\" %s -cclib \"%s %s\""
cma_name cppflags c_name ldflags libs
) &&
run_command (
sprintf "ocamlc -verbose -make-runtime -o %s %s" run_name cma_name
)
) in
remove o_name;
if result then Yes else No
)
)
) No
;;
let check_cmd verflag verfn cmd =
if cmd = "" then No
else checking cmd (fun () ->
match get_command_output (cmd ^ " " ^ verflag) with
| "" -> No
| out ->
printf "found %s ... %!" out;
if verfn out then Yes else No
) No;;
let check_tool name ~commands verflag verfn =
printf "Checking for %s ...\n%!" name;
match List.filter (fun c -> (check_cmd verflag verfn c) = Yes) commands with
| [] ->
No, ""
| first :: _ ->
Yes, first
;;
(* Can't use 'topfind' because Centos5 has incompatible ocaml and ocaml-findlib
* versions (3.09 and 3.11) when using EPEL5+Dag *)
let query_findlib fmt pkg =
(* TODO: check for .cmi! if not only runtime pkg is installed! *)
let cmd = "ocamlfind query -format " ^ fmt ^ " " ^ pkg in
let pipe = Unix.open_process_in cmd in
let result =
try input_line pipe
with End_of_file -> "" in
match Unix.close_process_in pipe with
| Unix.WEXITED 0 -> result
| _ ->
raise Not_found
;;
let get_version pkg =
query_findlib "%v" pkg;;
let check_findlib_package ver_fn pkg =
checking (sprintf "findlib package '%s'" pkg) (fun () ->
check_version ver_fn (get_version pkg)
) No
;;
let check_findlib_cm (pkg,cmi,cmxa) =
let has_cmi = checking cmi (fun () ->
let cmi = Filename.concat (query_findlib "%d" pkg) cmi in
if Sys.file_exists cmi then Yes else No
) No
and has_cmxa = checking cmxa (fun () ->
let cmxa = Filename.concat (query_findlib "%d" pkg) cmxa in
if Sys.file_exists cmxa then Yes else No
) No in
if has_cmi = Yes && has_cmxa = Yes then Yes else No
;;
let id x = x = Yes;;
let check_ocaml ~name ~findlibnames ~cmi ~version =
checking (sprintf "ocaml library '%s'" name) (fun () ->
printf "\n";
let have = List.rev_map (fun pkg ->
printf "\t";
(check_findlib_package version pkg),
(printf "\t";
check_findlib_cm cmi)
) findlibnames in
let have_pkgs, have_cmis = List.split have in
match (List.for_all id have_pkgs), (List.for_all id have_cmis) with
| true, true -> Yes
| true, false -> MissingDev
| false, _ -> No
) No
;;
type dep = {
name: string;
dep_findlibnames: string list;
have: bool;
deps: dep list;
deps_opt : dep list;
mutable required: bool;
action: action option;
}
and generate_build = dep list -> build
and action =
| Build of generate_build
| Install of install
type opt_flag = {
dep: dep;
enabled: string;
disabled: string;
}
let dependency name ?(deps_opt = []) ?(deps = []) have action =
let findlibnames, action_opt = match action with
| Build b ->
(* if the package is installed and none of its deps
* needs to be built then we don't have to build it.
* otherwise we do *)
if have = Yes && List.for_all (fun d -> d.action = None) deps then
[], None
else
(b []).findlibnames, Some action
| Install _ ->
[], if have = Yes then None else Some action in
{
name = name;
dep_findlibnames = findlibnames;
have = (have = Yes);
deps = deps;
deps_opt = deps_opt;
required = false;
action = action_opt
}
;;
let rec require dep =
if not dep.required then begin
dep.required <- true;
if dep.action <> None then
List.iter require dep.deps
end
;;
let is_required d = d.required;;
let get_deps deps =
List.fold_left (fun accum d ->
match d.action with
| Some (Build _) ->
List.rev_append d.dep_findlibnames accum
| _ ->
accum
) [] deps;;
let rec compute_rules deps =
List.fold_left (fun (builds,installs) d ->
match d.action with
| None -> builds, installs
| Some (Build get_build) ->
let deps = List.rev_append
(List.filter is_required d.deps_opt)
d.deps in
let dep_builds, dep_installs = compute_rules deps in
Builds.union builds (Builds.add (d.name, get_build deps, get_deps deps) dep_builds),
Installs.union installs dep_installs
| Some (Install i) ->
builds, Installs.add i installs
) (Builds.empty,Installs.empty) deps
;;
let rules deps =
List.iter require deps;
compute_rules deps;;
let print_install_deb i =
match i.os_pkg_names with
| deb :: _ -> printf " %s" deb
| _ -> ()
let print_install_rpm i =
match i.os_pkg_names with
| _ :: rpm :: _ -> printf " %s" rpm
| _ -> ()
let print_build (name,_,_) =
printf " %s" name;;
let print_summary builds installs =
printf "\n>>> Configure summary:\n";
if not (Installs.is_empty installs) then begin
printf "\n*** Please install the following packages:\n";
printf "\tapt-get install";
Installs.iter print_install_deb installs;
printf "\n\tyum install";
Installs.iter print_install_rpm installs;
printf "\n";
exit 1
end;
if not (Builds.is_empty builds) then begin
printf "The following packages will be built:";
Builds.iter print_build builds;
printf "\n"
end
;;
let flags opt_flags flags =
append flags (List.rev_map (fun flag ->
if is_required flag.dep then
flag.enabled
else
flag.disabled
) opt_flags
)
;;
module StringSet = Set.Make(String)
let sort_uniq l =
StringSet.elements (List.fold_left (fun accum s -> StringSet.add s accum)
StringSet.empty l)
let string_of_list lst =
let buf = Buffer.create 128 in
Buffer.add_char buf '[';
List.iter (fun e ->
Buffer.add_char buf '"';
Buffer.add_string buf e;
Buffer.add_char buf '"';
Buffer.add_char buf ';';
) (sort_uniq lst);
Buffer.add_char buf ']';
Buffer.contents buf;;
let print_cmd_cpr f dir =
fprintf f "\tlet cmd_cpr = Cmd (S [";
fprintf f "A \"cp\";A \"-R\";A \"-P\";P \"../%s\";A \"%s\"]) in\n"
dir (Filename.basename dir);;
let print_cmd ?(opt=false) f name lst =
fprintf f "\tlet cmd_%s = " name;
if lst = [] then
fprintf f "Nop"
else begin
fprintf f "Cmd (S [cmd_env; Sh \"&&\";\n\t\t";
List.iter (fun e ->
fprintf f "A \"%s\";" e
) lst;
if opt then
fprintf f "Sh \"2>/dev/null ||\";A \"true\"";
fprintf f "])";
end;
fprintf f " in\n";;
let print_cmd_env f dir =
fprintf f "\tlet cmd_env = S [A \"cd\"; Px \"%s\"] in\n" dir
;;
let name_re = Str.regexp "[-.]"
let gname s =
Str.global_replace name_re "_" s;;
let generate_build f (name,build,_) =
fprintf f "let build_%s _ _ =\n" (gname name);
let dir = build.source in
print_cmd_env f (Filename.basename dir);
print_cmd_cpr f dir;
print_cmd f "configure" build.configure;
print_cmd f "build" build.make;
print_cmd f "install" build.install;
print_cmd ~opt:true f "uninstall" build.uninstall;
fprintf f "\tSeq [cmd_cpr; cmd_configure; cmd_build; cmd_uninstall; cmd_install];;\n\n"
;;
(* TODO: dependencies should be on META.
* also handle uninstall; and install failures! *)
let depname name =
let name =
try String.sub name 0 (String.index name '.')
with Not_found -> name in
Filename.concat (Filename.concat "lib/ocaml/site-lib" name) "META";;
let generate_rule ?stamp f name prods deps =
let sdeps = List.fast_sort String.compare deps in
let udeps = List.fold_left (fun accum d ->
match accum with
| hd :: _ when hd = d ->
accum
| _ -> d :: accum) [] sdeps in
let rdeps = if udeps = prods then [] else udeps in
let name = gname name in
fprintf f "\trule %s \"build %s\" ~prods:%s ~deps:%s build_%s;\n"
(match stamp with Some s -> sprintf "~stamp:\"%s\"" s | None -> "")
name (string_of_list prods) (string_of_list rdeps) name;;
let generate_rule_meta f (name,b,deps) =
generate_rule f name
(List.rev_map depname b.findlibnames)
(List.rev_map depname deps)
;;
let not_starts_with ~start str =
let i = String.length start in
not (i <= String.length str && String.sub str 0 i = start)
let generate_main f main builds =
let args = List.tl (Array.to_list Sys.argv) in
let dir = Filename.concat ".." main in
fprintf f "let build_configure _ _ =\n";
print_cmd_env f dir;
let args = List.filter (not_starts_with ~start:"--includedir=") args in
print_cmd f "configure"
(append
["./configure";"--override";"ocamlbuildflags";"-j\\\\ 0";
"--override";"native_dynlink";"false";
"--disable-docs";
"--enable-tests"
]
args
);
fprintf f "\tcmd_configure;;\n";
fprintf f "let build_all _ _ =\n";
print_cmd_env f dir;
print_cmd f "build" ["ocaml";"setup.ml";"-build"];
fprintf f "\tSeq [ cmd_build ];;\n";
fprintf f "let build_allforce a b = build_all a b;;\n";
List.iter (fun target ->
fprintf f "let build_%s _ _ =\n" target;
print_cmd_env f dir;
print_cmd f target ["ocaml";"setup.ml";"-" ^ target];
fprintf f "\tSeq [cmd_%s];;\n" target
) ["test";"install";"reinstall";"uninstall";"clean"]
;;
let write_env name =
let file = "config." ^ (String.lowercase name) in
let f = open_out_gen [Open_trunc;Open_creat;Open_wronly] 0o600 file in
begin try
output_string f (Unix.getenv name);
with
Not_found-> ()
end;
close_out f
;;
let generate main builds =
write_env "CPPFLAGS";
write_env "LDFLAGS";
let f = open_out_gen [Open_trunc;Open_creat;Open_wronly] 0o600 "myocamlbuild.ml" in
fprintf f "open Ocamlbuild_plugin\n\n";
Builds.iter (generate_build f) builds;
fprintf f "\n";
generate_main f main builds;
fprintf f "\ndispatch begin function\n";
fprintf f "| After_rules ->\n";
Builds.iter (generate_rule_meta f) builds;
fprintf f "\n";
let deps = Builds.fold (fun (_,b,_) accum ->
List.rev_append (List.rev_map depname b.findlibnames) accum) builds [] in
generate_rule ~stamp:"configure.stamp" f "configure" [] deps;
generate_rule ~stamp:"build.stamp" f "all" [] ["configure.stamp"];
generate_rule f "allforce" ["all.target"] ["configure.stamp"];
generate_rule f "install" ["install.target"] ["build.stamp"];
generate_rule f "uninstall" ["uninstall.target"] [];
generate_rule f "test" ["test.target"] ["build.stamp"];
generate_rule f "clean" ["clean.target"] [];
fprintf f "| _ -> ()\n";
fprintf f "end;;\n";
close_out f;;
end;;
open Packages;;
module CommonRules : sig
val build_oasis : string -> findlibnames:string list -> flags:string list -> build
val build_pkgopkg : string -> findlibname:string -> flags:string list -> build
val build_pkgopkg2 : string -> findlibname:string -> flags:string list -> build
val build_confgnumake : ?flags: string list -> findlibnames:string list -> string -> build
val pkg_findlib: dep
val ocaml_dependency :
string -> ?cmi:string*string*string -> ?deps_opt:dep list -> ?deps:dep list ->
?findlibnames:string list -> ?version:(ver->bool) -> action -> dep
val clib_dependency :
string -> header:string -> lib:string list -> fn:string -> install -> dep
val gnu_make: string
val gnu_make_dep: dep
end = struct
(* GNU Make *)
let gnumake_re = Str.regexp_string "GNU Make"
let have_gnu_make, gnu_make = check_tool "GNU make" ~commands:[
(get_env_opt "MAKE"); "gmake";"make"
] "--version" (fun ver ->
Str.string_match gnumake_re ver 0
);;
let build_confgnumake ?(flags=[]) ~findlibnames source = {
source = source;
findlibnames = findlibnames;
configure = append ["sh";"configure";"--prefix";prefix;"--libdir";destdir] flags;
make = [gnu_make];
install = [gnu_make; "install"];
uninstall = [gnu_make; "uninstall"]
};;
let install_gnumake = Install { os_pkg_names = ["make";"gmake"] };;
let gnu_make_dep = dependency "GNU Make" have_gnu_make install_gnumake;;
let build_oasis source ~findlibnames ~flags = {
source = source;
findlibnames = findlibnames;
configure =
append
["ocaml";"setup.ml";"-configure";"--disable-docs";"--prefix";prefix;
"--override";"native_dynlink";"false";
"--override";"ocamlbuildflags";"-j 0"]
flags;
make = ["ocaml";"setup.ml";"-build"];
install = ["ocaml";"setup.ml";"-install"];
uninstall = ["ocaml";"setup.ml";"-uninstall"];
}
;;
let build_pkgopkg source ~findlibname ~flags = {
source = source;
findlibnames = [findlibname];
configure = ["./pkg/pkg-git"];
make = ["./pkg/build";"true"];
install = ["ocamlfind";"install";findlibname;"pkg/META";
"_build/src/" ^ findlibname ^ ".a";
"_build/src/" ^ findlibname ^ ".cmi";
"_build/src/" ^ findlibname ^ ".cma";
"_build/src/" ^ findlibname ^ ".cmx";
"_build/src/" ^ findlibname ^ ".cmxa"
];
uninstall = ["ocamlfind";"remove";findlibname]
}
;;
let build_pkgopkg2 source ~findlibname ~flags = {
source = source;
findlibnames = [findlibname];
configure = ["ocaml";"pkg/git.ml"];
make = ["ocaml";"pkg/build.ml";"native=true";"native-dynlink=false"];
install = ["ocamlfind";"install";findlibname;"pkg/META";
"_build/src/" ^ findlibname ^ ".a";
"_build/src/" ^ findlibname ^ ".cmi";
"_build/src/" ^ findlibname ^ ".cma";
"_build/src/" ^ findlibname ^ ".cmx";
"_build/src/" ^ findlibname ^ ".cmxa"
];
uninstall = ["ocamlfind";"remove";findlibname]
}
;;
let build_ocamlfind = Build (fun _ ->
{
source = "3rdparty/libs/findlib";
findlibnames = ["findlib"];
configure = ["sh";"configure";
"-bindir";prefix_bin;
"-mandir";Filename.concat prefix_data "man";
"-sitelib";destdir;
"-config";Filename.concat prefix_etc "findlib.conf";
"-no-topfind";
];
make = [gnu_make;"all";"opt"];
install = [gnu_make;"install"];
uninstall = [gnu_make;"uninstall"];
}
);;
let dep_ocamlfind =
(* oasis uses ocamlfind ocamldep -modules,
which is not supported on versions earlier than 1.2.0
some 3rdparty libs also use 'ocamlfind ocamlmklib' which was not available
prior to 1.2.8
*)
let have = check_findlib_package (fun v -> v >=? "1.5.3") "findlib" in
dependency "ocamlfind" have build_ocamlfind ~deps:[gnu_make_dep]
;;
let any _ = true
let ocaml_dependency
name ?(cmi=(name,name^".cmi",name^".cmxa")) ?deps_opt ?(deps=[]) ?(findlibnames = [name]) ?(version=any) action =
let have = check_ocaml ~name ~findlibnames ~cmi ~version in
(* if user has installed the correct runtime package,
* but not the dev package tell him to install the dev package,
* instead of building the package ourselves *)
let a =
match have with
| MissingDev ->
Install {
os_pkg_names = ["lib"^name^"-ocaml-dev";"ocaml-"^name^"-devel"]
}
| Yes | No ->
action in
dependency name ?deps_opt ~deps:(dep_ocamlfind :: deps) have a
;;
let pkg_findlib =
ocaml_dependency "findlib" build_ocamlfind ~version:(fun v -> v >=? "1.5.0")
let clib_dependency name ~header ~lib ~fn install =
dependency name (check_clib ~name ~header ~lib ~fn) (Install install);;
end;;
open CommonRules
(* ocamlbuild *)
let have_ocamlbuild, _ = check_tool "ocamlbuild" ~commands:["ocamlbuild"]
"-version" (fun _ -> true)
;;
let install_ocamlbuild = Install { os_pkg_names = ["ocaml"] };;
let dep_ocamlbuild = dependency "ocamlbuild" have_ocamlbuild install_ocamlbuild;;
(* Camlp4 *)
let install_camlp4of = Install { os_pkg_names = ["camlp4-extra";"ocaml-camlp4-devel"] };;
let have_camlp4of, _ = check_tool "camlp4of" ~commands:["camlp4of.opt";"camlp4of"]
"-version" (fun ver -> ver = Sys.ocaml_version);;
let camlp4of_dep = dependency "camlp4of" have_camlp4of install_camlp4of
let install_camlp4rf = Install { os_pkg_names = ["camlp4-extra";"ocaml-camlp4-devel"] };;
let have_camlp4rf, _ = check_tool "camlp4rf" ~commands:["camlp4rf.opt";"camlp4rf"]
"-version" (fun ver -> ver = Sys.ocaml_version);;
let camlp4rf_dep = dependency "camlp4rf" have_camlp4rf install_camlp4rf
let install_camlp4 = Install { os_pkg_names = ["camlp4";"ocaml-camlp4-devel"] };;
let have_camlp4, _ = check_tool "camlp4" ~commands:["camlp4.opt";"camlp4"]
"-version" (fun ver -> ver = Sys.ocaml_version);;
let camlp4_dep = dependency "camlp4" have_camlp4 install_camlp4
(* Pcre *)
let install_pcre = { os_pkg_names = ["libpcre3-dev"] };;
let pkg_pcre = ocaml_dependency "pcre" (Build (fun _ ->
build_oasis "3rdparty/libs/pcre-ocaml" ~findlibnames:["pcre"] ~flags:[]))
~deps:[
clib_dependency "libpcre" ~header:"pcre.h" ~lib:["pcre"] ~fn:"pcre_version()"
install_pcre;
pkg_findlib
] ~version:(fun ver -> ver >=? "6.0.1");;
(* OpenSSL *)
let install_ssl = { os_pkg_names = ["libssl-dev"] };;
let pkg_ssl =
ocaml_dependency "ssl"
(Build (fun _ ->
build_confgnumake "3rdparty/libs/ocaml-ssl" ~findlibnames:["ssl"]
))
~deps:[clib_dependency "libssl"
~header:"openssl/ssl.h" ~lib:["ssl";"crypto"] ~fn:"(void)SSL_library_init ()" install_ssl;
gnu_make_dep; pkg_findlib
]
~version:(fun v -> v >=? "0.4.4")
;;
(* libev *)
let install_libev = { os_pkg_names = ["libev-dev";"libev-devel"] };;
let pkg_libev =
clib_dependency "libev"
~header:"ev.h" ~lib:["ev"] ~fn:"(void)ev_default_loop(0)" install_libev
;;
(* OCamlnet *)
let pkg_ocamlnet =
ocaml_dependency "ocamlnet" ~findlibnames:[
"netstring";"netstring-pcre";"netsys";"netcgi2";"netclient";"equeue-ssl"
] ~version:(fun ver -> ver >? "3.7.3") ~cmi:("netstring","netstring_str.cmi","netstring.cmxa")
(Build (fun _ -> {
source = "3rdparty/libs/ocamlnet";
findlibnames = ["netstring";"netstring-pcre";"netsys";"netcgi2";"netclient"];
configure =
flags [
{dep = pkg_pcre; enabled = "-enable-pcre"; disabled = "-disable-pcre"};
{dep = pkg_ssl; enabled = "-enable-ssl"; disabled = "-disable-ssl"};
] ["sh"; "configure";"-bindir";prefix_bin;"-datadir";prefix_data;
"-disable-gtk";"-disable-gtk2";"-disable-tcl";"-disable-zip";
"-disable-crypto";"-disable-apache";
if want_nethttpd then "-with-nethttpd" else "-without-nethttpd";
"-without-rpc-auth-dh"
];
(* apparently this requires GNU make too, or at least it doesn't build with
* pmake *)
make = [gnu_make;"all";"opt"];
install = [gnu_make;"install"];
uninstall = [gnu_make;"uninstall"];
})) ~deps:[pkg_findlib] ~deps_opt:[gnu_make_dep; pkg_pcre; pkg_ssl ];;
(* xmlm *)
let pkg_xmlm = ocaml_dependency "xmlm" (Build (fun _ ->
build_pkgopkg "3rdparty/libs/xmlm" ~findlibname:"xmlm" ~flags:[]))
~deps:[dep_ocamlbuild; pkg_findlib];;
(* uutf *)
let pkg_uutf = ocaml_dependency "uutf" (Build (fun _ ->
build_pkgopkg "3rdparty/libs/uutf" ~findlibname:"uutf" ~flags:[]))
~deps:[dep_ocamlbuild; pkg_findlib];;
(* jsonm *)
let pkg_jsonm = ocaml_dependency "jsonm" (Build (fun _ ->
build_oasis "3rdparty/libs/jsonm" ~findlibnames:["jsonm"] ~flags:[]))
~deps:[dep_ocamlbuild; pkg_uutf];;
(* jsonm *)
let pkg_ipaddr = ocaml_dependency "ipaddr" (Build (fun _ ->
build_oasis "3rdparty/libs/ipaddr" ~findlibnames:["ipaddr"] ~flags:[]))
~deps:[dep_ocamlbuild; pkg_findlib]
~version:(fun v -> v >=? "2.2.0") ;;
(* cryptokit *)
let pkg_cryptokit = ocaml_dependency "cryptokit" (Build (fun _ ->
build_oasis "3rdparty/libs/cryptokit" ~flags:[] ~findlibnames:["cryptokit"]
)) ~deps:[dep_ocamlbuild; pkg_findlib] ~version:(fun ver -> ver >=? "1.3");;
(* oUnit *)
let pkg_ounit = ocaml_dependency "oUnit" (Build (fun _ ->
build_oasis "3rdparty/libs/ounit" ~flags:[] ~findlibnames:["oUnit"]
)) ~deps:[dep_ocamlbuild; pkg_findlib];;
(* React *)
let pkg_react = ocaml_dependency "react" (Build (fun _ ->
build_pkgopkg2 "3rdparty/libs/react" ~flags:[] ~findlibname:"react"
)) ~deps:[dep_ocamlbuild; pkg_findlib] ~version:(fun v -> v >=? "1.1.0");;
(* Lwt *)
let pkg_lwt = ocaml_dependency "lwt" ~findlibnames:["lwt";"lwt.unix";"lwt.ssl"]
(Build (fun _ ->
let flags = flags [{
dep = pkg_ssl;
enabled = "--enable-ssl";
disabled = "--disable-ssl";
};
{
dep = pkg_libev;
enabled = "--enable-libev";
disabled = "--disable-libev";
}
] ["--enable-libev";"--enable-react"] in
build_oasis "3rdparty/libs/lwt" ~flags ~findlibnames:["lwt"]
))
~version:(fun v -> (v >=? "2.4.3"))
~deps:[pkg_react; camlp4_dep; dep_ocamlbuild]
~deps_opt:[pkg_ssl;pkg_libev]
;;
(* Tyxml *)
let pkg_tyxml = ocaml_dependency "tyxml" ~cmi:("tyxml","html5.cmi","tyxml.cmxa") (Build (fun _ ->
build_oasis "3rdparty/libs/tyxml" ~findlibnames:["tyxml"] ~flags:[]))
~version:(fun v -> v >=? "2.0.1")
~deps:[pkg_findlib; pkg_uutf; camlp4of_dep; camlp4rf_dep; camlp4_dep]
;;
(* Ocsigenserver *)
let pkg_ocsigenserver = ocaml_dependency "ocsigenserver"
~cmi:("ocsigenserver","ocsigen_server.cmi","ocsigenserver.cmxa") (Build (fun _ ->
build_confgnumake "3rdparty/libs/ocsigenserver" ~flags:[
"--without-dbm";"--enable-debug";
"--disable-natdynlink";
"--commandpipe";Filename.concat prefix_var "lib/ocsigenserver/commandpipe";
"--ocsigen-user";string_of_int (Unix.getuid ());
"--ocsigen-group";string_of_int (Unix.getgid ());
"--sysconfdir";Filename.concat prefix_etc "ocsigenserver";
"--logdir";Filename.concat prefix_var "log/ocsigenserver";
"--staticpagesdir";Filename.concat prefix_var "www/ocsigenserver";
"--datadir";Filename.concat prefix_var "lib/ocsigenserver"
] ~findlibnames:["ocsigenserver"]
)) ~version:(fun v -> v >=? "2.5.0") (* always build *)
~deps:[
gnu_make_dep; pkg_findlib; pkg_pcre; pkg_ocamlnet; pkg_react; pkg_ssl; pkg_lwt; pkg_cryptokit; pkg_tyxml; pkg_ipaddr
]
let pkg_re = ocaml_dependency "re" (Build (fun _ ->
build_oasis "3rdparty/libs/ocaml-re" ~findlibnames:["re";"re.posix"] ~flags:[]))
~deps:[dep_ocamlbuild; pkg_findlib]
let pkg_optcomp = ocaml_dependency "optcomp" ~cmi:("optcomp","pa_optcomp.cmi","optcomp.cmxa") (Build (fun _ ->
build_oasis "3rdparty/libs/optcomp" ~findlibnames:["optcomp"] ~flags:[]))
~deps:[dep_ocamlbuild; camlp4_dep; pkg_findlib]
let pkg_ocplib_endian = ocaml_dependency "ocplib-endian" ~cmi:("ocplib-endian","endianString.cmi","ocplib_endian.cmxa") (Build (fun _ ->
build_oasis "3rdparty/libs/ocplib-endian" ~findlibnames:["ocplib-endian"] ~flags:[]))
~deps:[dep_ocamlbuild; pkg_findlib; pkg_optcomp; camlp4_dep]
let pkg_cstruct = ocaml_dependency "cstruct" (Build (fun _ ->
build_oasis "3rdparty/libs/ocaml-cstruct" ~findlibnames:["cstruct";"cstruct.lwt"] ~flags:["--enable-lwt"]))
~deps:[dep_ocamlbuild; pkg_ocplib_endian; pkg_ounit; camlp4_dep]
~deps_opt:[pkg_lwt]
~version:(fun v -> v >=? "1.0.1")
let pkg_base64 = ocaml_dependency "base64" (Build (fun _ ->
build_oasis "3rdparty/libs/base64" ~findlibnames:["base64"] ~flags:[]))
~cmi:("base64","b64.cmi","base64.cmxa")
~deps:[pkg_findlib]
let pkg_dns = ocaml_dependency "dns" (Build (fun _ ->
build_oasis "3rdparty/libs/ocaml-dns" ~findlibnames:["dns";"dns.lwt"] ~flags:["--enable-lwt"]))
~deps:[dep_ocamlbuild; pkg_lwt; pkg_cstruct; pkg_re; pkg_ipaddr; pkg_base64 ]
~version:(fun v -> v >=? "0.10.0")
(* Main dependencies of libres3 *)
let deps_default = [ pkg_ocamlnet; pkg_jsonm; pkg_xmlm; pkg_cryptokit; pkg_ounit; pkg_ssl; pkg_libev ];;
let deps = pkg_dns :: pkg_re :: pkg_ocsigenserver :: deps_default
let builds, installs = rules deps;;
print_summary builds installs;;
generate "libres3" builds;;
List.iter (fun dir ->
try Unix.mkdir dir 0o700
with Unix.Unix_error(Unix.EEXIST,_,_) -> ())
[
prefix;
prefix_bin;
prefix_data;
prefix_var;
prefix_etc;
Filename.concat prefix "3rdparty";
Filename.concat prefix "3rdparty/libs";
Filename.concat prefix "lib";
Filename.concat prefix "lib/ocaml";
destdir;
ld_library_path
];;
printf "\n>>> Ready\nNow run 'make' and 'make install'\n";;