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