public static void substituteTemplateVariablesToMakefile(String templatefile, String outputfile, KeyValueList variables) {
    { InputFileStream in = null;

      try {
        in = Stella.openInputFile(templatefile, Stella.NIL);
        { OutputFileStream out = null;

          try {
            out = Stella.openOutputFile(outputfile, Stella.NIL);
            {
              out.nativeStream.println("# This file has been generated automatically.  Modify at your own risk!");
              out.nativeStream.println();
            }
;
            InputStream.substituteTemplateVariablesToStream(in, out, variables);

          } finally {
            if (out != null) {
              out.free();
            }
          }
        }

      } finally {
        if (in != null) {
          in.free();
        }
      }
    }
  }