% Copyright (C) 1993, Digital Equipment Corporation
% All rights reserved.
% See the file COPYRIGHT for a full description.
%
% Last modified on Fri Jan 21 15:57:01 PST 1994 by kalsow

if defined("_all")
  local md_nw = path_of ("MD.nw")
  local ret = 0

  % extract the machine description
  if stale(".md", md_nw)
    write ("executing notangle\n")
    ret = exec(["notangle", "-RBURS specification", md_nw ], [ "", ".md.tmp" ])
    if not equal(ret, 0)
      error("notangle failed in m3makefile with code: ", ret) end
    ret = exec(["sed", "-e", "s/:  */:	/g", "-e", "s/    */	/g" ],
         [ ".md.tmp", ".md" ])
    if not equal(ret, 0)
      error("sed failed in m3makefile with code: ", ret) end
  end
  cp_if (".md", "md")

  % build the input to iburg
  if stale("md.brg", ["md", "pp"])
    write ("executing pp\n")
    ret = exec(["pp"], [ "md", "md.brg"])
    if not equal(ret, 0) error("pp failed in m3makefile with code: ", ret) end
  end

  % build burm.c
  if stale("burm.c", "md.brg")
    write ("execuging iburg\n")
    ret = exec([ "iburg", "-I", "-T" ], [ "md.brg", "burm.c" ])
    if not equal(ret, 0)
      error("iburg failed in m3makefile with code: ", ret) end
  end

  % extract the reducer cases
  foreach i in {"1", "2"}
    if stale("reduce" & i, "md")
      write ("executing pp\n")
      ret = exec([ "pp", "-" & i ], [ "md", "reduce" & i ])
      if not equal(ret, 0)
        error("pp failed in m3makefile with code: ", ret) end
    end
  end

  % build MD.m3
  if stale(".MD.m3", [md_nw, "reduce1", "reduce2"])
    write ("executing notangle\n")
    ret = exec([ "notangle", "-L<*LINE %L \"%F\" *>%N", "-Rimplementation",
	  md_nw, "reduce1", "reduce2" ], [ ".MD.m3" ])
    if not equal(ret, 0)
      error("notangle failed in m3makefile with code: ", ret) end
  end
  cp_if (".MD.m3", "MD.m3")

end % if defined ("_all")

foreach i in [".md", ".md.tmp", "md", "md.brg", "reduce1", "reduce2", 
              ".MD.m3", "MD.m3" ]
  deriveds(i, no_extensions)
end

noweb_interface ("MD","interface","MD")
derived_implementation("MD")
derived_c("burm")

