+/* Set up dependency-file output. */
+static void
+init_dependency_output ()
+{
+ char *spec, *s, *output_file;
+
+ /* Either of two environment variables can specify output of deps.
+ Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
+ where OUTPUT_FILE is the file to write deps info to
+ and DEPS_TARGET is the target to mention in the deps. */
+
+ if (print_deps == 0)
+ {
+ spec = getenv ("DEPENDENCIES_OUTPUT");
+ if (spec)
+ print_deps = 1;
+ else
+ {
+ spec = getenv ("SUNPRO_DEPENDENCIES");
+ if (spec)
+ print_deps = 2;
+ else
+ return;
+ }
+
+ /* Find the space before the DEPS_TARGET, if there is one. */
+ s = strchr (spec, ' ');
+ if (s)
+ {
+ /* Let the caller perform MAKE quoting. */
+ deps_add_target (deps, s + 1, 0);
+ output_file = (char *) xmalloc (s - spec + 1);
+ memcpy (output_file, spec, s - spec);
+ output_file[s - spec] = 0;
+ }
+ else
+ output_file = spec;
+
+ /* Command line overrides environment variables. */
+ if (deps_file == 0)
+ deps_file = output_file;
+ deps_append = 1;
+ }
+
+ /* If dependencies go to standard output, or -MG is used, we should
+ suppress output. The user may be requesting other stuff to
+ stdout, with -dM, -v etc. We let them shoot themselves in the
+ foot. */
+ if (deps_file == 0 || deps_missing_files)
+ inhibit_output = 1;
+}
+
+/* Use mkdeps.c to output dependency information. */
+static void
+output_deps ()
+{
+ /* Stream on which to print the dependency information. */
+ FILE *deps_stream = 0;
+ const char *deps_mode = deps_append ? "a" : "w";
+
+ if (deps_file == 0)
+ deps_stream = stdout;
+ else
+ {
+ deps_stream = fopen (deps_file, deps_mode);
+ if (deps_stream == 0)
+ {
+ error_from_errno (deps_file);
+ return;
+ }
+ }
+
+ deps_write (deps, deps_stream, 72);
+
+ if (print_deps_phony_targets)
+ deps_phony_targets (deps, deps_stream);
+
+ /* Don't close stdout. */
+ if (deps_file)
+ {
+ if (ferror (deps_stream) || fclose (deps_stream) != 0)
+ fatal ("I/O error on output");
+ }
+}
+