TBS based build system
[apc.git] / build.ml
blob7e1e58133f6dbbbe1a9a8c5fdb715a70a2edab01
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 cmo "-g -I +lablGL -thread" [srcdir] srcdir "apc";
17 ocaml
18 "-ccopt '-Wall -o ml_apc.o'"
19 "ml_apc.o"
20 (StrSet.singleton "ml_apc.o")
21 [Filename.concat srcdir "ml_apc.c"]
22 StrSet.empty
24 ocaml
25 "-custom -thread -g -I +lablGL lablgl.cma lablglut.cma unix.cma threads.cma"
26 "apc"
27 (StrSet.singleton "apc")
28 ["ml_apc.o"; "apc.cmo"]
29 StrSet.empty
31 let _ =
32 let moddir = Filename.concat srcdir "mod" in
33 let modconts = Sys.readdir moddir in
34 let deps = Array.fold_left (fun deps s ->
35 if String.length s > 0 && s.[0] != '.'
36 then
37 let src = Filename.concat moddir s in
38 add_target s (StrSet.singleton src) (StrSet.singleton s) (StrSet.singleton src);
39 let build _ =
40 let c = [Run ("cp " ^ Filename.quote src ^ " " ^ Filename.quote s)] in
41 c, c, "COPY"
43 State.put_build_info s build;
44 StrSet.add s deps
45 else
46 deps
47 ) StrSet.empty modconts
49 let build _ =
50 let c = [Run ("make")] in
51 c, c, "KBUILD"
53 add_phony "mod" deps [];
54 State.put_build_info "mod" build;
59 let () =
60 let start = Unix.gettimeofday () in
61 Scan.all targets;
62 if dodeplist
63 then
64 List.iter State.print_deps targets
65 else
66 begin
67 let build path =
68 let built = Unix.handle_unix_error Build.path path in
69 if not !Config.silent
70 then
71 if built
72 then print_endline (path ^ " has been built")
73 else print_endline ("nothing to be done for " ^ path)
76 if jobs = 1
77 then
78 iter build targets
79 else
80 let rec loop i tids = if i = jobs then tids else
81 let tid = Thread.create (fun () -> iter build targets) () in
82 loop (succ i) (tid :: tids)
84 let tids = loop 0 [] in
85 iter Thread.join tids
86 end
88 Cache.save !State.Config.cache;
89 let stop = Unix.gettimeofday () in
90 Format.eprintf "build took %f seconds@." (stop -. start);