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