Fix signed/unsigned mixup (John Stuffer)
[llpp/slowscroll.git] / build.ml
blob2f5967bb33a79242f58b0c106ca3c2f6fe1fb461
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 StrSet.empty
38 let ocaml1 prog flags1 flags2 mainoutput outputs inputs deps f =
39 let flags = flags1 ^ " -o " ^ Filename.quote mainoutput in
40 let build =
41 let commands _ =
42 let s = String.concat " " (map Filename.quote (f ())) in
43 [Run (prog ^ " " ^ flags ^ " " ^ s ^ flags2)]
45 let cookie _ = prog ^ flags in
46 let presentation _ = "OCAMLC " ^ mainoutput in
47 { get_commands = commands
48 ; get_cookie = cookie
49 ; get_presentation = presentation
52 let inputs = fold_right StrSet.add inputs StrSet.empty in
53 let deps = StrSet.union inputs deps in
54 StrSet.iter (fun output ->
55 put_build_info output build;
56 let deps = StrSet.remove output deps in
57 add_target output inputs outputs deps
58 ) outputs;
61 let ocaml' prog flags1 flags2 mainoutput outputs inputs deps =
62 ocaml1 prog flags1 flags2 mainoutput outputs inputs deps (fun () -> inputs)
65 let bso name objs =
66 let so = name ^ ".so" in
67 let mupdf_libs =
68 " -L" ^ mupdflibpath ^ " " ^ libs
70 let o = List.map (fun s -> s ^ ".o") objs in
71 ocaml'
73 ("-shared -lpthread -o " ^ so ^ mupdf_libs)
74 (mupdf_libs)
76 (StrSet.singleton so)
78 (StrSet.singleton (Filename.concat mupdflibpath "libmupdf.a"))
83 let () =
84 boc "-g" "link";
85 let so = bso "link" ["link"] in
86 let prog name cmos =
87 ocaml
88 "ocamlc.opt"
89 ("-g -I +lablGL lablgl.cma lablglut.cma str.cma unix.cma -dllpath "
90 ^ Sys.getcwd ())
91 name
92 (StrSet.singleton name)
93 (State.dep_sort cmos)
94 StrSet.empty
96 let main =
97 cmopp ~flags:"-g -w y -I +lablGL -thread" ~dirname:srcdir "main";
98 "main.cmo"
100 prog "llpp" [so; main];
103 let () =
104 let objs =
105 c cc "-c -Wall -Werror -Wextra -g" srcdir "test";
106 ["test.o"]
108 let objsgl =
109 c cc "-c -Wall -Werror -Wextra -g" srcdir "testgl";
110 ["testgl.o"]
112 let prog name objs =
115 ~doscan:false
116 ~flags1:""
117 ~flags2:"-lX11 -lXext"
118 ~output:name
119 objs
121 let proggl name objs =
124 ~doscan:false
125 ~flags1:""
126 ~flags2:"-lX11 -lXext -lGL"
127 ~output:name
128 objs
130 prog "test" objs;
131 proggl "testgl" objsgl;
134 let () =
135 run start jobs targets dodeplist dotarlist;