annotate src/share/tools/MakeDeps/MakeDeps.java @ 1408:0ba67bb5392c

added c1x build directory, added MSVC Win64 project support
author lstadler
date Wed, 12 May 2010 15:01:05 +0200
parents a61af66fc99e
children 2d26b0046e0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1408
0ba67bb5392c added c1x build directory, added MSVC Win64 project support
lstadler
parents: 0
diff changeset
1 import java.util.Map;
0ba67bb5392c added c1x build directory, added MSVC Win64 project support
lstadler
parents: 0
diff changeset
2 import java.util.Map.Entry;
0ba67bb5392c added c1x build directory, added MSVC Win64 project support
lstadler
parents: 0
diff changeset
3
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
7 *
a61af66fc99e Initial load
duke
parents:
diff changeset
8 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
11 *
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
17 *
a61af66fc99e Initial load
duke
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
21 *
a61af66fc99e Initial load
duke
parents:
diff changeset
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
23 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
24 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
25 *
a61af66fc99e Initial load
duke
parents:
diff changeset
26 */
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // This program reads an include file database.
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // The database should cover each self .c and .h file,
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // but not files in /usr/include
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // The database consists of pairs of nonblank words, where the first word is
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // the filename that needs to include the file named by the second word.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // For each .c file, this program generates a fooIncludes.h file that
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // the .c file may include to include all the needed files in the right order.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // It also generates a foo.dep file to include in the makefile.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Finally it detects cycles, and can work with two files, an old and a new one.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // To incrementally write out only needed files after a small change.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Based on a suggestion by Roland Conybeare, algorithm suggested by Craig
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Chambers, written by David Ungar, 3/1/89.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Added PREFIX, {DEP/INC}_DIR, smaller dep output 10/92 -Urs
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Add something for precompiled headers
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // To handle different platforms, I am introducing a platform file.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // The platform file contains lines like:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // os = svr4
a61af66fc99e Initial load
duke
parents:
diff changeset
48 //
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Then, when processing the includeDB file, a token such as <os>
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // gets replaced by svr4. -- dmu 3/25/97
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Modified to centralize Dependencies to speed up make -- dmu 5/97
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public class MakeDeps {
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public static void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 System.out.println("usage:");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 System.out.println("\tmakeDeps platform-name platform-file database-file [MakeDeps args] [platform args]");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 System.out.println("\tmakeDeps diffs platform-name old-platform-file old-database-file new-platform-file new-database-file [MakeDeps args] [platform args]");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 System.out.println("where platform-name is the name of a platform MakeDeps supports");
a61af66fc99e Initial load
duke
parents:
diff changeset
61 System.out.println("(currently \"WinGammaPlatform\" or \"UnixPlatform\")");
a61af66fc99e Initial load
duke
parents:
diff changeset
62 System.out.println("MakeDeps options:");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 System.out.println(" -firstFile [filename]: Specify the first file in link order (i.e.,");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 System.out.println(" to have a well-known function at the start of the output file)");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 System.out.println(" -lastFile [filename]: Specify the last file in link order (i.e.,");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 System.out.println(" to have a well-known function at the end of the output file)");
a61af66fc99e Initial load
duke
parents:
diff changeset
67 System.err.println("WinGammaPlatform platform-specific options:");
a61af66fc99e Initial load
duke
parents:
diff changeset
68 System.err.println(" -sourceBase <path to directory (workspace) " +
a61af66fc99e Initial load
duke
parents:
diff changeset
69 "containing source files; no trailing slash>");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 System.err.println(" -dspFileName <full pathname to which .dsp file " +
a61af66fc99e Initial load
duke
parents:
diff changeset
71 "will be written; all parent directories must " +
a61af66fc99e Initial load
duke
parents:
diff changeset
72 "already exist>");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 System.err.println(" -envVar <environment variable to be inserted " +
a61af66fc99e Initial load
duke
parents:
diff changeset
74 "into .dsp file, substituting for path given in " +
a61af66fc99e Initial load
duke
parents:
diff changeset
75 "-sourceBase. Example: HotSpotWorkSpace>");
a61af66fc99e Initial load
duke
parents:
diff changeset
76 System.err.println(" -dllLoc <path to directory in which to put " +
a61af66fc99e Initial load
duke
parents:
diff changeset
77 "jvm.dll and jvm_g.dll; no trailing slash>");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 System.err.println(" If any of the above are specified, "+
a61af66fc99e Initial load
duke
parents:
diff changeset
79 "they must all be.");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 System.err.println(" Additional, optional arguments, which can be " +
a61af66fc99e Initial load
duke
parents:
diff changeset
81 "specified multiple times:");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 System.err.println(" -absoluteInclude <string containing absolute " +
a61af66fc99e Initial load
duke
parents:
diff changeset
83 "path to include directory>");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 System.err.println(" -relativeInclude <string containing include " +
a61af66fc99e Initial load
duke
parents:
diff changeset
85 "directory relative to -envVar>");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 System.err.println(" -define <preprocessor flag to be #defined " +
a61af66fc99e Initial load
duke
parents:
diff changeset
87 "(note: doesn't yet support " +
a61af66fc99e Initial load
duke
parents:
diff changeset
88 "#define (flag) (value))>");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 System.err.println(" -perFileLine <file> <line>");
a61af66fc99e Initial load
duke
parents:
diff changeset
90 System.err.println(" -conditionalPerFileLine <file> <line for " +
a61af66fc99e Initial load
duke
parents:
diff changeset
91 "release build> <line for debug build>");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 System.err.println(" (NOTE: To work around a bug in nmake, where " +
a61af66fc99e Initial load
duke
parents:
diff changeset
93 "you can't have a '#' character in a quoted " +
a61af66fc99e Initial load
duke
parents:
diff changeset
94 "string, all of the lines outputted have \"#\"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
95 "prepended)");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 System.err.println(" -startAt <subdir of sourceBase>");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 System.err.println(" -ignoreFile <file which won't be able to be " +
a61af66fc99e Initial load
duke
parents:
diff changeset
98 "found in the sourceBase because it's generated " +
a61af66fc99e Initial load
duke
parents:
diff changeset
99 "later>");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 System.err.println(" -additionalFile <file not in database but " +
a61af66fc99e Initial load
duke
parents:
diff changeset
101 "which should show up in .dsp file, like " +
a61af66fc99e Initial load
duke
parents:
diff changeset
102 "includeDB_core>");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 System.err.println(" -additionalGeneratedFile <environment variable of " +
a61af66fc99e Initial load
duke
parents:
diff changeset
104 "generated file's location> <relative path to " +
a61af66fc99e Initial load
duke
parents:
diff changeset
105 "directory containing file; no trailing slash> " +
a61af66fc99e Initial load
duke
parents:
diff changeset
106 "<name of file generated later in the build process>");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 System.err.println(" -prelink <build> <desc> <cmds>:");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 System.err.println(" Generate a set of prelink commands for the given BUILD");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 System.err.println(" (\"Debug\" or \"Release\"). The prelink description and commands");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 System.err.println(" are both quoted strings.");
a61af66fc99e Initial load
duke
parents:
diff changeset
111 System.err.println(" Default includes: \".\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
112 System.err.println(" Default defines: WIN32, _WINDOWS, \"HOTSPOT_BUILD_USER=$(USERNAME)\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (args.length < 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 int argc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 boolean diffMode = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (args[argc].equals("diffs")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 diffMode = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 ++argc;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 String platformName = args[argc++];
a61af66fc99e Initial load
duke
parents:
diff changeset
130 Class platformClass = Class.forName(platformName);
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 String plat1 = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 String db1 = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 String plat2 = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 String db2 = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 String firstFile = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 String lastFile = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 int numOptionalArgs =
a61af66fc99e Initial load
duke
parents:
diff changeset
141 (diffMode ? (args.length - 6) : (args.length - 3));
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (numOptionalArgs < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 plat1 = args[argc++];
a61af66fc99e Initial load
duke
parents:
diff changeset
148 db1 = args[argc++];
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (diffMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 plat2 = args[argc++];
a61af66fc99e Initial load
duke
parents:
diff changeset
152 db2 = args[argc++];
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // argc now points at start of optional arguments, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 boolean gotOne = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 while (gotOne && (argc < args.length - 1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 gotOne = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 String arg = args[argc];
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (arg.equals("-firstFile")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 firstFile = args[argc + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
164 argc += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 gotOne = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } else if (arg.equals("-lastFile")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 lastFile = args[argc + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
168 argc += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 gotOne = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 Platform platform = (Platform) platformClass.newInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 platform.setupFileTemplates();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 long t = platform.defaultGrandIncludeThreshold();
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 String[] platformArgs = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 int numPlatformArgs = args.length - argc;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (numPlatformArgs > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 platformArgs = new String[numPlatformArgs];
a61af66fc99e Initial load
duke
parents:
diff changeset
187 int offset = argc;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 while (argc < args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 platformArgs[argc - offset] = args[argc];
a61af66fc99e Initial load
duke
parents:
diff changeset
190 ++argc;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // If you want to change the threshold, change the default
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // "grand include" threshold in Platform.java, or override
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // it in the platform-specific file like UnixPlatform.java
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 Database previous = new Database(platform, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 Database current = new Database(platform, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 previous.canBeMissing();
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (firstFile != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 previous.setFirstFile(firstFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 current.setFirstFile(firstFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (lastFile != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 previous.setLastFile(lastFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 current.setLastFile(lastFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (diffMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 System.out.println("Old database:");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 previous.get(plat1, db1);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 previous.compute();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 System.out.println("New database:");
a61af66fc99e Initial load
duke
parents:
diff changeset
217 current.get(plat2, db2);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 current.compute();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 System.out.println("Deltas:");
a61af66fc99e Initial load
duke
parents:
diff changeset
220 current.putDiffs(previous);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 System.out.println("New database:");
a61af66fc99e Initial load
duke
parents:
diff changeset
223 current.get(plat1, db1);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 current.compute();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 current.put();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (platformArgs != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // Allow the platform to write platform-specific files
a61af66fc99e Initial load
duke
parents:
diff changeset
230 platform.writePlatformSpecificFiles(previous, current,
a61af66fc99e Initial load
duke
parents:
diff changeset
231 platformArgs);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }