OSDN Git Service

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