Mention unzip
[llpp.git] / build.ml
blobce8da26b5fc43839a59a8be4ac8cf5302cca1026
1 let start = Unix.gettimeofday ();;
3 open List;;
4 open Typs;;
5 open Utils;;
6 open State;;
7 open Helpers;;
9 let jobs, targets, dodeplist, dotarlist = getopt ();;
11 let get key msg =
12 match getval key with | None -> failwith msg | Some s -> s
15 let getdef key def =
16 match getval key with | None -> def | Some s -> s
19 let srcdir = get "src" "no source dir";;
20 let cc = getdef "cc" "cc";;
21 let ccopt = getdef "ccopt" "";;
22 let mupdflibpath = get "mupdflibpath" "no mupdf libpath";;
23 let libs = getdef "libs" "";;
25 let boc flags src =
26 let o = src ^ ".o" in
27 let c = src ^ ".c" in
28 ocaml
29 "ocamlc.opt"
30 ("-cc '" ^ cc ^ "' -ccopt '" ^ flags ^ " " ^ ccopt ^ " -o " ^ o ^ "'")
32 (StrSet.singleton o)
33 [Filename.concat srcdir c]
34 (* Since we are using ocaml instead of gcc to compile this
35 the dep scanning passs is not done, hence this cludge *)
36 (StrSet.singleton (Filename.concat srcdir "glfont.c"))
40 let ocaml1 prog flags1 flags2 mainoutput outputs inputs deps f =
41 let flags = flags1 ^ " -o " ^ Filename.quote mainoutput in
42 let build =
43 let commands _ =
44 let s = String.concat " " (map Filename.quote (f ())) in
45 [Run (prog ^ " " ^ flags ^ " " ^ s ^ flags2)]
47 let cookie _ = prog ^ flags in
48 let presentation _ = "OCAMLC " ^ mainoutput in
49 { get_commands = commands
50 ; get_cookie = cookie
51 ; get_presentation = presentation
54 let inputs = fold_right StrSet.add inputs StrSet.empty in
55 let deps = StrSet.union inputs deps in
56 StrSet.iter (fun output ->
57 put_build_info output build;
58 let deps = StrSet.remove output deps in
59 add_target output inputs outputs deps
60 ) outputs;
63 let ocaml' prog flags1 flags2 mainoutput outputs inputs deps =
64 ocaml1 prog flags1 flags2 mainoutput outputs inputs deps (fun () -> inputs)
67 let bso name objs =
68 let so = name ^ ".so" in
69 let mupdf_libs =
70 " -L" ^ mupdflibpath ^ " " ^ libs
72 let o = List.map (fun s -> s ^ ".o") objs in
73 ocaml'
75 ("-shared -lpthread -o " ^ so ^ mupdf_libs)
76 (mupdf_libs)
78 (StrSet.singleton so)
80 (StrSet.add
81 (Filename.concat mupdflibpath "libfitz.a")
82 (StrSet.singleton (Filename.concat mupdflibpath "libmupdf.a")))
87 let () =
88 boc "-g" "link";
89 let _ =
90 let mkhelp = Filename.concat srcdir "mkhelp.sh" in
91 let keystoml = Filename.concat srcdir "keystoml.ml" in
92 let keys = Filename.concat srcdir "KEYS" in
93 let cmd = "sh " ^ mkhelp ^ " " ^ keystoml ^ " " ^ keys ^ "> help.ml" in
94 let build =
95 { get_commands = (fun _ -> [Run cmd])
96 ; get_cookie = (fun _ ->
97 let cwd = Sys.getcwd () in
98 Sys.chdir srcdir;
99 let s = get_cmd_output "git describe --tags --dirty || echo" in
100 Sys.chdir cwd;
102 ; get_presentation = (fun _ -> "KEYSTOML KEYS")
105 put_build_info "help.ml" build;
106 let sing s = StrSet.singleton s in
107 add_target
108 "help.ml"
109 (sing "KEYS")
110 (sing "help.ml")
111 (StrSet.add keys (StrSet.add mkhelp (sing keystoml)))
113 let so = bso "link" ["link"] in
114 let prog name cmos =
115 ocaml
116 "ocamlc.opt"
117 ("-g -I +lablGL lablgl.cma lablglut.cma str.cma unix.cma -dllpath "
118 ^ Sys.getcwd ())
119 name
120 (StrSet.singleton name)
121 (State.dep_sort cmos)
122 StrSet.empty
124 let mkcmo name =
125 let dirname = if name = "help" then Sys.getcwd () else srcdir in
126 cmopp ~flags:"-g -w Ale -I +lablGL -thread" ~dirname name;
127 (name ^ ".cmo")
129 let cmos = so :: List.map mkcmo ["help"; "parser"; "main"] in
130 prog "llpp" cmos;
133 let () =
134 run start jobs ["help.ml"] false dotarlist;
135 run start jobs targets dodeplist dotarlist;