Initial .gitignore
[imt.git] / driver.ml
blob5b07ec5b28d51ca2befb50c65b089e9d79f80f05
1 let help () =
2 print_string "usage: ";
3 print_string (Filename.basename Sys.executable_name);
4 print_endline " command [ command-argument ] [ arguments ... ]";
5 print_endline "command is one of: ";
6 List.iter (fun s -> print_string " "; print_endline s)
7 ["cl";
8 " run `cl [arguments]' sanitizing output (converting paths etc)";
9 "";
11 "dep target";
12 " run `cl /E [arguments]'";
13 " search output for headers";
14 " print `target: <list-of-headers>' to standard output";
15 "";
17 "dep7 target";
18 " run `cl /showIncludes /Zs [arguments]'";
19 " same as dep";
20 "";
22 "dep7-test";
23 " test if cl is new enough and has /showIncludes option";
24 "";
26 "cldep7 target depfile";
27 " run `cl /showIncludes [arguments]'";
28 " same as cl+dep7 but put the dependency information into file <depfile>";
29 " (sans /Zs)";
30 "";
32 "link";
33 " run `link [arguments]'";
34 "";
36 "help";
37 " show this help screen";
40 let exp_cmd, run_cmd =
41 if Wine.native
42 then
43 "C:\\> set ", "C:\\> "
44 else
45 "$ export ", "$ "
47 List.iter print_endline
48 ["If environment variable IMT_[CL|LINK] is set it will be used as the ";
49 "path to respective utility, otherwise [cl.exe|link.exe] will be used";
50 "";
51 "If environment variable IMT_VIA is set it will be used as the path ";
52 "to the application to run instead of [cl.exe|link.exe]";
53 "IMT_VIA_PASS_NAME environment variable can be used to specify the name";
54 "of the corresponding utility down the chain";
55 "IMT_VIA_PASS_ARGS can be used to pass parameters of the utility";
56 "";
57 "Headers produced by [cl]dep[7] commands will be tested against IMT_REJ";
58 "environment variable (: separated list of OCaml style regular expressions)";
59 "if the path to header matches it will be excluded from the printout";
60 "(paths are tested after windows to unix translation (nop on Win platforms))";
61 "";
62 "Example:";
63 exp_cmd ^ "IMT_REJ=/mnt/windows/msc/include:/mnt/psdk/include";
64 exp_cmd ^ "IMT_CL=/mnt/windows/msc/bin/cl.exe";
65 run_cmd ^ "imt cldep7 moo.obj moo.dep -c moo.c";
66 "";
67 exp_cmd ^ "IMT_VIA=ocamlc";
68 exp_cmd ^ "IMT_VIA_PASS_NAME=-cc";
69 exp_cmd ^ "IMT_VIA_PASS_ARGS=-ccopt";
70 run_cmd ^ "imt cl -c moo.ml";
71 "will result in execution of `ocamlc -cc \"cl\" -ccopt \"-nologo\" moo.ml'";
74 print_endline "Have a nice day";
75 exit 0
77 let show_usage () =
78 print_endline "Incredible Mega Thing by extremely cool hacker, Version 1.01";
79 print_newline ();
80 print_string "usage: ";
81 print_string (Filename.basename Sys.executable_name);
82 print_endline " command [ command-argument ] [ arguments ... ]";
83 print_endline "command is one of: ";
84 List.iter (fun s -> print_string " "; print_endline s)
85 ["cl: invoke cl";
86 "dep target: invoke cl /E, parse output, print dependencies to stdout";
87 "dep7 target: invoke cl /showIncludes /Zs, same as dep";
88 "dep7-test: test if /showIncludes is available, exit with non-zero if not";
89 "cldep7 target depfile: cl+dep7 combined, put dependencies into depfile";
90 "link: invoke link";
91 "help: show extended help"
93 print_endline "Have a nice day";
94 exit 100
96 let main argv =
97 if Array.length argv < 2
98 then
99 show_usage ()
100 else
101 begin
102 Drive.init ();
103 let code =
104 match argv.(1) with
105 | "cl" ->
106 Cl.invoke argv 2
108 | "dep7" ->
109 if Array.length argv < 3
110 then
111 show_usage ()
112 else
113 let target = argv.(2) in
114 Dep7.invoke target argv 3
116 | "dep" ->
117 if Array.length argv < 3
118 then
119 show_usage ()
120 else
121 let target = argv.(2) in
122 Dep.invoke target argv 3
124 | "link" ->
125 Link.invoke argv 2
127 | "dep7-test" ->
128 Dep7.test ()
130 | "cldep7" ->
131 if Array.length argv < 4
132 then
133 show_usage ()
134 else
135 let target = argv.(2)
136 and depfile = argv.(3) in
137 Dep7.invoke2 target depfile argv 4
139 | "help" ->
140 help ()
142 | cmd ->
143 prerr_string "invalid command: ";
144 prerr_string (String.escaped cmd);
145 prerr_newline ();
146 show_usage ()
148 exit code
151 let _ =
152 main Sys.argv