Update Changes
[apc.git] / build.ml
blob07eee1091d9a1b4f894d45e6fb8ac10622a38220
1 open List;;
2 open Typs;;
3 open Utils;;
4 open State;;
5 open Helpers;;
7 let jobs, targets, dodeplist, dotarlist = getopt ();;
9 let srcdir =
10 match getval "src" with
11 | None -> failwith "no source dir"
12 | Some s -> s
15 let _ =
16 cmopp ~flags:"-g -I +lablGL -thread" ~dirname:srcdir "apc";
17 ocaml
18 "ocamlc.opt"
19 "-ccopt '-Wall -o ml_apc.o'"
20 "ml_apc.o"
21 (StrSet.singleton "ml_apc.o")
22 [Filename.concat srcdir "ml_apc.c"]
23 StrSet.empty
25 let prog base =
26 gcc "gcc" true
27 "-Wall -Werror -g -c" ""
28 (base ^ ".o")
29 [Filename.concat srcdir (base ^ ".c")]
31 gcc "gcc" false
32 "" ""
33 base
34 [base ^ ".o"]
37 prog "hog";
38 prog "idlestat";
39 ocaml
40 "ocamlc.opt"
41 "-custom -thread -g -I +lablGL lablgl.cma lablglut.cma unix.cma threads.cma"
42 "apc"
43 (StrSet.singleton "apc")
44 ["ml_apc.o"; "apc.cmo"]
45 StrSet.empty
47 let _ =
48 let moddir = Filename.concat srcdir "mod" in
49 let modconts = Sys.readdir moddir in
50 let deps = Array.fold_left (fun deps s ->
51 if String.length s > 0 && s.[0] != '.'
52 then
53 let src = Filename.concat moddir s in
54 add_target s (StrSet.singleton src) (StrSet.singleton s) (StrSet.singleton src);
55 let build =
56 let commands _ =
57 [Run ("cp " ^ Filename.quote src ^ " " ^ Filename.quote s)]
58 and cookie _ = "cp"
59 and presentation _ =
60 "COPY"
62 { get_commands = commands
63 ; get_cookie = cookie
64 ; get_presentation = presentation
67 State.put_build_info s build;
68 StrSet.add s deps
69 else
70 deps
71 ) StrSet.empty modconts
73 let build =
74 let commands _ = [Run ("make")]
75 and cookie _ = "make"
76 and presentation _ = "KBUILD" in
77 { get_commands = commands
78 ; get_cookie = cookie
79 ; get_presentation = presentation
82 add_phony "mod" deps "";
83 State.put_build_info "mod" build;
88 let () =
89 let start = Unix.gettimeofday () in
90 (* Scan.all targets; *)
91 if dodeplist
92 then
93 List.iter State.print_deps targets
94 else
95 begin
96 let build path =
97 let built = Unix.handle_unix_error Build.path path in
98 if not !Config.silent
99 then
100 if built
101 then print_endline (path ^ " has been built")
102 else print_endline ("nothing to be done for " ^ path)
105 if jobs = 1
106 then
107 iter build targets
108 else
109 let rec loop i tids = if i = jobs then tids else
110 let tid = Thread.create (fun () -> iter build targets) () in
111 loop (succ i) (tid :: tids)
113 let tids = loop 0 [] in
114 iter Thread.join tids
117 Cache.save !State.Config.cache;
118 let stop = Unix.gettimeofday () in
119 Format.eprintf "build took %f seconds@." (stop -. start);