Sync with upstream
[llpp.git] / build.ml
blob57802a7b0cf38de2f4306656064a8dac105be84d
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 let d =
29 (* Since we are using ocaml instead of gcc to compile this
30 the dep scanning passs is not done, hence this cludge *)
31 List.fold_left
32 (fun s p -> StrSet.add (Filename.concat srcdir p) s)
33 StrSet.empty
34 ["glfont.c"; "keysym2ucs.c"]
36 ocaml
37 "ocamlc.opt"
38 ("-cc '" ^ cc ^ "' -ccopt '" ^ flags ^ " " ^ ccopt ^ " -o " ^ o ^ "'")
40 (StrSet.singleton o)
41 [Filename.concat srcdir c]
46 let ocaml1 prog flags1 flags2 mainoutput outputs inputs deps f =
47 let flags = flags1 ^ " -o " ^ Filename.quote mainoutput in
48 let build =
49 let commands _ =
50 let s = String.concat " " (map Filename.quote (f ())) in
51 [Run (prog ^ " " ^ flags ^ " " ^ s ^ flags2)]
53 let cookie _ = prog ^ flags in
54 let presentation _ = "OCAMLC " ^ mainoutput in
55 { get_commands = commands
56 ; get_cookie = cookie
57 ; get_presentation = presentation
60 let inputs = fold_right StrSet.add inputs StrSet.empty in
61 let deps = StrSet.union inputs deps in
62 StrSet.iter (fun output ->
63 put_build_info output build;
64 let deps = StrSet.remove output deps in
65 add_target output inputs outputs deps
66 ) outputs;
69 let ocaml' prog flags1 flags2 mainoutput outputs inputs deps =
70 ocaml1 prog flags1 flags2 mainoutput outputs inputs deps (fun () -> inputs)
73 let bso name objs =
74 let so = name ^ ".so" in
75 let mupdf_libs =
76 " -L" ^ mupdflibpath ^ " " ^ libs
78 let o = List.map (fun s -> s ^ ".o") objs in
79 let libs = ["fitz"] in
80 let set =
81 List.fold_left (fun set s ->
82 let l = "lib" ^ s ^ ".a" in
83 let l = Filename.concat mupdflibpath l in
84 StrSet.add l set)
85 StrSet.empty libs
87 ocaml'
89 ("-shared -lpthread -o " ^ so ^ mupdf_libs)
90 (mupdf_libs)
92 (StrSet.singleton so)
94 set
99 let () =
100 boc "-g" "link";
101 let _ =
102 let mkhelp = Filename.concat srcdir "mkhelp.sh" in
103 let keystoml = Filename.concat srcdir "keystoml.ml" in
104 let keys = Filename.concat srcdir "KEYS" in
105 let cmd = "sh " ^ mkhelp ^ " " ^ keystoml ^ " " ^ keys ^ "> help.ml" in
106 let build =
107 { get_commands = (fun _ -> [Run cmd])
108 ; get_cookie = (fun _ ->
109 let cwd = Sys.getcwd () in
110 Sys.chdir srcdir;
111 let s = get_cmd_output "git describe --tags --dirty || echo" in
112 Sys.chdir cwd;
114 ; get_presentation = (fun _ -> "KEYSTOML KEYS")
117 put_build_info "help.ml" build;
118 let sing s = StrSet.singleton s in
119 add_target
120 "help.ml"
121 (sing "KEYS")
122 (sing "help.ml")
123 (StrSet.add keys (StrSet.add mkhelp (sing keystoml)))
125 let so = bso "link" ["link"] in
126 let prog name cmos =
127 ocaml
128 "ocamlc.opt"
129 ("-g -I +lablGL lablgl.cma str.cma unix.cma -dllpath "
130 ^ Sys.getcwd ())
131 name
132 (StrSet.singleton name)
133 (State.dep_sort cmos)
134 StrSet.empty
136 let mkcmo name =
137 let dirname = if name = "help" then Sys.getcwd () else srcdir in
138 cmopp ~flags:"-g -w A-7-6-4 -I +lablGL -thread" ~dirname name;
139 (name ^ ".cmo")
141 let cmos = so :: List.map mkcmo ["help"; "parser"; "wsi"; "main"] in
142 prog "llpp" cmos;
145 let () =
146 run start jobs ["help.ml"] false dotarlist;
147 run start jobs targets dodeplist dotarlist;