jcf-depend.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Functions for handling dependency tracking when reading .class files.
  2. Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>.
  15. Java and all Java-based marks are trademarks or registered trademarks
  16. of Sun Microsystems, Inc. in the United States and other countries.
  17. The Free Software Foundation is independent of Sun Microsystems, Inc. */
  18. /* Written by Tom Tromey <tromey@cygnus.com>, October 1998. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "mkdeps.h"
  23. #include "jcf.h"
  24. /* The dependency structure used for this invocation. */
  25. struct deps *dependencies;
  26. /* The output file, or NULL if we aren't doing dependency tracking. */
  27. static FILE *dep_out = NULL;
  28. /* Nonzero if system files should be added. */
  29. static int system_files;
  30. /* Nonzero if we are dumping out dummy dependencies. */
  31. static int print_dummies;
  32. /* Call this to reset the dependency module. This is required if
  33. multiple dependency files are being generated from a single tool
  34. invocation. FIXME: we should change our API or just completely use
  35. the one in mkdeps.h. */
  36. void
  37. jcf_dependency_reset (void)
  38. {
  39. if (dep_out != NULL)
  40. {
  41. if (dep_out != stdout)
  42. fclose (dep_out);
  43. dep_out = NULL;
  44. }
  45. if (dependencies != NULL)
  46. {
  47. deps_free (dependencies);
  48. dependencies = NULL;
  49. }
  50. }
  51. void
  52. jcf_dependency_set_target (const char *name)
  53. {
  54. /* We just handle this the same as an `add_target'. */
  55. if (dependencies != NULL && name != NULL)
  56. deps_add_target (dependencies, name, 1);
  57. }
  58. void
  59. jcf_dependency_add_target (const char *name)
  60. {
  61. if (dependencies != NULL)
  62. deps_add_target (dependencies, name, 1);
  63. }
  64. void
  65. jcf_dependency_set_dep_file (const char *name)
  66. {
  67. gcc_assert (dep_out != stdout);
  68. if (dep_out)
  69. fclose (dep_out);
  70. if (! strcmp (name, "-"))
  71. dep_out = stdout;
  72. else
  73. dep_out = fopen (name, "w");
  74. }
  75. void
  76. jcf_dependency_add_file (const char *filename ATTRIBUTE_UNUSED, int system_p)
  77. {
  78. if (! dependencies)
  79. return;
  80. /* Just omit system files. */
  81. if (system_p && ! system_files)
  82. return;
  83. /* FIXME: Don't emit any dependencies. In many cases we'll just see
  84. temporary files emitted by ecj... */
  85. /* deps_add_dep (dependencies, filename); */
  86. }
  87. void
  88. jcf_dependency_init (int system_p)
  89. {
  90. gcc_assert (! dependencies);
  91. system_files = system_p;
  92. dependencies = deps_init ();
  93. }
  94. void
  95. jcf_dependency_print_dummies (void)
  96. {
  97. print_dummies = 1;
  98. }
  99. void
  100. jcf_dependency_write (void)
  101. {
  102. if (! dep_out)
  103. return;
  104. gcc_assert (dependencies);
  105. deps_write (dependencies, dep_out, 72);
  106. if (print_dummies)
  107. deps_phony_targets (dependencies, dep_out);
  108. fflush (dep_out);
  109. }