1structure genscriptdep :> sig val main : unit -> unit end =
2struct
3
4structure FileSys = OS.FileSys
5structure Path = OS.Path
6structure Process = OS.Process
7
8infix ++
9fun p1 ++ p2 = Path.concat(p1,p2)
10
11
12fun warn s = (TextIO.output(TextIO.stdErr, s ^ "\n");
13              TextIO.flushOut TextIO.stdErr)
14
15fun get_includes () =
16  if FileSys.access ("Holmakefile", [FileSys.A_READ]) then
17    let
18      open Holmake_types
19      val (env, _, _) = ReadHMF.read "Holmakefile" (base_environment())
20      fun envlist id =
21        map dequote (tokenize (perform_substitution env [VREF id]))
22    in
23      envlist "PRE_INCLUDES" @ envlist "INCLUDES"
24    end
25    handle e => (warn "[bogus Holmakefile in current directory - ignoring it]";
26                 [])
27  else []
28
29fun usage_str nm =
30  "Usage:\n  " ^ nm ^ " [-h|-?|filename]\n"
31
32fun usage ok =
33  let
34    val strm = if ok then TextIO.stdOut else TextIO.stdErr
35  in
36    TextIO.output(strm, usage_str (CommandLine.name()));
37    Process.exit (if ok then Process.success else Process.failure)
38  end
39
40fun addPath I file =
41  if OS.Path.isAbsolute file then
42    file
43  else let
44      val p = List.find (fn p =>
45                            FileSys.access (p ++ (file ^ ".ui"), []))
46                        (FileSys.getDir() :: I)
47    in
48      case p of
49           NONE => FileSys.getDir() ++ file
50         | SOME p => p ++ file
51    end;
52
53fun main() =
54  let
55    open Holmake_tools
56    val _ = holpathdb.extend_db {vname = "HOLDIR", path = Systeml.HOLDIR}
57    val I = get_includes() @ [OS.Path.concat(Systeml.HOLDIR, "sigobj")]
58  in
59    case CommandLine.arguments() of
60        ["-h"] => usage true
61      | ["-?"] => usage true
62      | [fname] =>
63        let
64          val {deps = deps0,...} =
65              Holdep.main{assumes = [], includes = I,
66                          diag = (fn s => ()), fname = fname}
67          val deps = map toFile deps0
68          fun mapthis (Unhandled _) = NONE
69            | mapthis (DAT _) = NONE
70            | mapthis f = SOME (fromFileNoSuf f)
71          val depMods = List.map (addPath I) (List.mapPartial mapthis deps)
72          fun usePathVars p = holpathdb.reverse_lookup {path = p}
73          val depMods = List.map usePathVars depMods
74        in
75          List.app (fn s => print (s ^ "\n")) depMods
76        end
77      | _ => usage false
78  end
79
80end (* structure *)
81