X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=examples%2Fcompile-c%2Fcompile.ml;fp=examples%2Fcompile-c%2Fcompile.ml;h=6cd2e88938cce3bba43da8dcf094537acf046c9d;hb=b71fd4c0029678140d2496ac52f7b79f1ad96fe1;hp=0000000000000000000000000000000000000000;hpb=153276d53f879786956bd7c2a4d3b97ef13c9adc;p=goaljobs.git diff --git a/examples/compile-c/compile.ml b/examples/compile-c/compile.ml new file mode 100644 index 0000000..6cd2e88 --- /dev/null +++ b/examples/compile-c/compile.ml @@ -0,0 +1,30 @@ +open Goaljobs (* will be implicit *) + +let rec goal all () = + require (built "program" ["main.c"; "utils.c"]) + +(* Goal: build the final program from source files. *) +and built program sources = + target (more_recent [program] sources); + List.iter (fun s -> require (compiled s)) sources; + + let objects = List.map (change_file_extension "o") sources in + sh "cc %s -o %s" (String.concat " " objects) program + +(* Goal: Make sure a C file is compiled (to an object file). *) +and compiled c_file = + let o_file = change_file_extension "o" c_file in + target (more_recent [o_file] [c_file]); + require (file_exists c_file); + sh "cc -c %s -o %s" c_file o_file + +(* XXX IMPLICIT *) +let () = + try goal_all () + with + | Goal_result (Goal_failed msg) -> + prerr_endline ("error: " ^ msg); + exit 1 + | exn -> + prerr_endline (Printexc.to_string exn); + exit 1