Thu, 10 Feb 2011 13:03:22 +0100
7017824: Add support for creating 64-bit Visual Studio projects
Summary: Updated create.bat and ProjectCreator
Reviewed-by: brutisso, stefank, ohair
1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 import java.io.File;
26 import java.util.Enumeration;
27 import java.util.Hashtable;
28 import java.util.Iterator;
29 import java.util.Vector;
31 class BuildConfig {
32 Hashtable vars;
33 Vector basicNames, basicPaths;
34 String[] context;
36 static CompilerInterface ci;
37 static CompilerInterface getCI() {
38 if (ci == null) {
39 String comp = (String)getField(null, "CompilerVersion");
40 try {
41 ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance();
42 } catch (Exception cnfe) {
43 System.err.println("Cannot find support for compiler " + comp);
44 throw new RuntimeException(cnfe.toString());
45 }
46 }
47 return ci;
48 }
50 protected void initNames(String flavour, String build, String outDll) {
51 if (vars == null) vars = new Hashtable();
53 String flavourBuild = flavour + "_" + build;
54 String platformName = getFieldString(null, "PlatformName");
55 System.out.println();
56 System.out.println(flavourBuild);
58 put("Name", getCI().makeCfgName(flavourBuild, platformName));
59 put("Flavour", flavour);
60 put("Build", build);
61 put("PlatformName", platformName);
63 // ones mentioned above were needed to expand format
64 String buildBase = expandFormat(getFieldString(null, "BuildBase"));
65 String sourceBase = getFieldString(null, "SourceBase");
66 String outDir = buildBase;
68 put("Id", flavourBuild);
69 put("OutputDir", outDir);
70 put("SourceBase", sourceBase);
71 put("BuildBase", buildBase);
72 put("OutputDll", outDir + Util.sep + outDll);
74 context = new String [] {flavourBuild, flavour, build, null};
75 }
77 protected void init(Vector includes, Vector defines) {
78 initDefaultDefines(defines);
79 initDefaultCompilerFlags(includes);
80 initDefaultLinkerFlags();
81 handleDB();
82 }
85 protected void initDefaultCompilerFlags(Vector includes) {
86 Vector compilerFlags = new Vector();
88 compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"),
89 includes,
90 get("OutputDir")));
92 put("CompilerFlags", compilerFlags);
93 }
95 protected void initDefaultLinkerFlags() {
96 Vector linkerFlags = new Vector();
98 linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName")));
100 put("LinkerFlags", linkerFlags);
101 }
103 DirectoryTree getSourceTree(String sourceBase, String startAt) {
104 DirectoryTree tree = new DirectoryTree();
106 tree.addSubdirToIgnore("Codemgr_wsdata");
107 tree.addSubdirToIgnore("deleted_files");
108 tree.addSubdirToIgnore("SCCS");
109 tree.setVerbose(true);
110 if (startAt != null) {
111 tree.readDirectory(sourceBase + File.separator + startAt);
112 } else {
113 tree.readDirectory(sourceBase);
114 }
116 return tree;
117 }
120 Vector getPreferredPaths() {
121 Vector preferredPaths = new Vector();
123 // In the case of multiple files with the same name in
124 // different subdirectories, prefer these versions
125 preferredPaths.add("windows");
126 preferredPaths.add("x86");
127 preferredPaths.add("closed");
129 // Also prefer "opto" over "adlc" for adlcVMDeps.hpp
130 preferredPaths.add("opto");
132 return preferredPaths;
133 }
136 void handleDB() {
137 WinGammaPlatform platform = (WinGammaPlatform)getField(null, "PlatformObject");
139 putSpecificField("AllFilesHash", computeAllFiles(platform));
140 }
143 private boolean matchesIgnoredPath(String prefixedName) {
144 Vector rv = new Vector();
145 collectRelevantVectors(rv, "IgnorePath");
146 for (Iterator i = rv.iterator(); i.hasNext(); ) {
147 String pathPart = (String) i.next();
148 if (prefixedName.contains(Util.normalize(pathPart))) {
149 return true;
150 }
151 }
152 return false;
153 }
155 void addAll(Iterator i, Hashtable hash,
156 WinGammaPlatform platform, DirectoryTree tree,
157 Vector preferredPaths, Vector filesNotFound, Vector filesDuplicate) {
158 for (; i.hasNext(); ) {
159 String fileName = (String) i.next();
160 if (lookupHashFieldInContext("IgnoreFile", fileName) == null) {
161 String prefixedName = platform.envVarPrefixedFileName(fileName,
162 0, /* ignored */
163 tree,
164 preferredPaths,
165 filesNotFound,
166 filesDuplicate);
167 if (prefixedName != null) {
168 prefixedName = Util.normalize(prefixedName);
169 if (!matchesIgnoredPath(prefixedName)) {
170 addTo(hash, prefixedName, fileName);
171 }
172 }
173 }
174 }
175 }
177 void addTo(Hashtable ht, String key, String value) {
178 ht.put(expandFormat(key), expandFormat(value));
179 }
181 Hashtable computeAllFiles(WinGammaPlatform platform) {
182 Hashtable rv = new Hashtable();
183 DirectoryTree tree = getSourceTree(get("SourceBase"), getFieldString(null, "StartAt"));
184 Vector preferredPaths = getPreferredPaths();
186 // Hold errors until end
187 Vector filesNotFound = new Vector();
188 Vector filesDuplicate = new Vector();
190 Vector includedFiles = new Vector();
192 // find all files
193 Vector dirs = getSourceIncludes();
194 for (Iterator i = dirs.iterator(); i.hasNext(); ) {
195 String dir = (String)i.next();
196 DirectoryTree subtree = getSourceTree(dir, null);
197 for (Iterator fi = subtree.getFileIterator(); fi.hasNext(); ) {
198 String name = ((File)fi.next()).getName();
199 includedFiles.add(name);
200 }
201 }
202 addAll(includedFiles.iterator(), rv,
203 platform, tree,
204 preferredPaths, filesNotFound, filesDuplicate);
206 Vector addFiles = new Vector();
207 collectRelevantVectors(addFiles, "AdditionalFile");
208 addAll(addFiles.iterator(), rv,
209 platform, tree,
210 preferredPaths, filesNotFound, filesDuplicate);
212 collectRelevantHashes(rv, "AdditionalGeneratedFile");
214 if ((filesNotFound.size() != 0) ||
215 (filesDuplicate.size() != 0)) {
216 System.err.println("Error: some files were not found or " +
217 "appeared in multiple subdirectories of " +
218 "directory " + get("SourceBase") + " and could not " +
219 "be resolved with os_family and arch.");
220 if (filesNotFound.size() != 0) {
221 System.err.println("Files not found:");
222 for (Iterator iter = filesNotFound.iterator();
223 iter.hasNext(); ) {
224 System.err.println(" " + (String) iter.next());
225 }
226 }
227 if (filesDuplicate.size() != 0) {
228 System.err.println("Duplicate files:");
229 for (Iterator iter = filesDuplicate.iterator();
230 iter.hasNext(); ) {
231 System.err.println(" " + (String) iter.next());
232 }
233 }
234 throw new RuntimeException();
235 }
237 return rv;
238 }
240 void initDefaultDefines(Vector defines) {
241 Vector sysDefines = new Vector();
242 sysDefines.add("WIN32");
243 sysDefines.add("_WINDOWS");
244 sysDefines.add("HOTSPOT_BUILD_USER=\\\""+System.getProperty("user.name")+"\\\"");
245 sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
246 sysDefines.add("_JNI_IMPLEMENTATION_");
247 if (vars.get("PlatformName").equals("Win32")) {
248 sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
249 } else {
250 sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\"");
251 }
253 sysDefines.addAll(defines);
255 put("Define", sysDefines);
256 }
258 String get(String key) {
259 return (String)vars.get(key);
260 }
262 Vector getV(String key) {
263 return (Vector)vars.get(key);
264 }
266 Object getO(String key) {
267 return vars.get(key);
268 }
270 Hashtable getH(String key) {
271 return (Hashtable)vars.get(key);
272 }
274 Object getFieldInContext(String field) {
275 for (int i=0; i<context.length; i++) {
276 Object rv = getField(context[i], field);
277 if (rv != null) {
278 return rv;
279 }
280 }
281 return null;
282 }
284 Object lookupHashFieldInContext(String field, String key) {
285 for (int i=0; i<context.length; i++) {
286 Hashtable ht = (Hashtable)getField(context[i], field);
287 if (ht != null) {
288 Object rv = ht.get(key);
289 if (rv != null) {
290 return rv;
291 }
292 }
293 }
294 return null;
295 }
297 void put(String key, String value) {
298 vars.put(key, value);
299 }
301 void put(String key, Vector vvalue) {
302 vars.put(key, vvalue);
303 }
305 void add(String key, Vector vvalue) {
306 getV(key).addAll(vvalue);
307 }
309 String flavour() {
310 return get("Flavour");
311 }
313 String build() {
314 return get("Build");
315 }
317 Object getSpecificField(String field) {
318 return getField(get("Id"), field);
319 }
321 void putSpecificField(String field, Object value) {
322 putField(get("Id"), field, value);
323 }
325 void collectRelevantVectors(Vector rv, String field) {
326 for (int i = 0; i < context.length; i++) {
327 Vector v = getFieldVector(context[i], field);
328 if (v != null) {
329 for (Iterator j=v.iterator(); j.hasNext(); ) {
330 String val = (String)j.next();
331 rv.add(expandFormat(val));
332 }
333 }
334 }
335 }
337 void collectRelevantHashes(Hashtable rv, String field) {
338 for (int i = 0; i < context.length; i++) {
339 Hashtable v = (Hashtable)getField(context[i], field);
340 if (v != null) {
341 for (Enumeration e=v.keys(); e.hasMoreElements(); ) {
342 String key = (String)e.nextElement();
343 String val = (String)v.get(key);
344 addTo(rv, key, val);
345 }
346 }
347 }
348 }
351 Vector getDefines() {
352 Vector rv = new Vector();
353 collectRelevantVectors(rv, "Define");
354 return rv;
355 }
357 Vector getIncludes() {
358 Vector rv = new Vector();
360 collectRelevantVectors(rv, "AbsoluteInclude");
362 rv.addAll(getSourceIncludes());
364 return rv;
365 }
367 private Vector getSourceIncludes() {
368 Vector rv = new Vector();
369 Vector ri = new Vector();
370 String sourceBase = getFieldString(null, "SourceBase");
371 collectRelevantVectors(ri, "RelativeInclude");
372 for (Iterator i = ri.iterator(); i.hasNext(); ) {
373 String f = (String)i.next();
374 rv.add(sourceBase + Util.sep + f);
375 }
376 return rv;
377 }
379 static Hashtable cfgData = new Hashtable();
380 static Hashtable globalData = new Hashtable();
382 static boolean appliesToTieredBuild(String cfg) {
383 return (cfg != null &&
384 (cfg.startsWith("compiler1") ||
385 cfg.startsWith("compiler2")));
386 }
388 // Filters out the IgnoreFile and IgnorePaths since they are
389 // handled specially for tiered builds.
390 static boolean appliesToTieredBuild(String cfg, String key) {
391 return (appliesToTieredBuild(cfg))&& (key != null && !key.startsWith("Ignore"));
392 }
394 static String getTieredBuildCfg(String cfg) {
395 assert appliesToTieredBuild(cfg) : "illegal configuration " + cfg;
396 return "tiered" + cfg.substring(9);
397 }
399 static Object getField(String cfg, String field) {
400 if (cfg == null) {
401 return globalData.get(field);
402 }
404 Hashtable ht = (Hashtable)cfgData.get(cfg);
405 return ht == null ? null : ht.get(field);
406 }
408 static String getFieldString(String cfg, String field) {
409 return (String)getField(cfg, field);
410 }
412 static Vector getFieldVector(String cfg, String field) {
413 return (Vector)getField(cfg, field);
414 }
416 static void putField(String cfg, String field, Object value) {
417 putFieldImpl(cfg, field, value);
418 if (appliesToTieredBuild(cfg, field)) {
419 putFieldImpl(getTieredBuildCfg(cfg), field, value);
420 }
421 }
423 private static void putFieldImpl(String cfg, String field, Object value) {
424 if (cfg == null) {
425 globalData.put(field, value);
426 return;
427 }
429 Hashtable ht = (Hashtable)cfgData.get(cfg);
430 if (ht == null) {
431 ht = new Hashtable();
432 cfgData.put(cfg, ht);
433 }
435 ht.put(field, value);
436 }
438 static Object getFieldHash(String cfg, String field, String name) {
439 Hashtable ht = (Hashtable)getField(cfg, field);
441 return ht == null ? null : ht.get(name);
442 }
444 static void putFieldHash(String cfg, String field, String name, Object val) {
445 putFieldHashImpl(cfg, field, name, val);
446 if (appliesToTieredBuild(cfg, field)) {
447 putFieldHashImpl(getTieredBuildCfg(cfg), field, name, val);
448 }
449 }
451 private static void putFieldHashImpl(String cfg, String field, String name, Object val) {
452 Hashtable ht = (Hashtable)getField(cfg, field);
454 if (ht == null) {
455 ht = new Hashtable();
456 putFieldImpl(cfg, field, ht);
457 }
459 ht.put(name, val);
460 }
462 static void addFieldVector(String cfg, String field, String element) {
463 addFieldVectorImpl(cfg, field, element);
464 if (appliesToTieredBuild(cfg, field)) {
465 addFieldVectorImpl(getTieredBuildCfg(cfg), field, element);
466 }
467 }
469 private static void addFieldVectorImpl(String cfg, String field, String element) {
470 Vector v = (Vector)getField(cfg, field);
472 if (v == null) {
473 v = new Vector();
474 putFieldImpl(cfg, field, v);
475 }
477 v.add(element);
478 }
480 String expandFormat(String format) {
481 if (format == null) {
482 return null;
483 }
485 if (format.indexOf('%') == -1) {
486 return format;
487 }
489 StringBuffer sb = new StringBuffer();
490 int len = format.length();
491 for (int i=0; i<len; i++) {
492 char ch = format.charAt(i);
493 if (ch == '%') {
494 char ch1 = format.charAt(i+1);
495 switch (ch1) {
496 case '%':
497 sb.append(ch1);
498 break;
499 case 'b':
500 sb.append(build());
501 break;
502 case 'f':
503 sb.append(flavour());
504 break;
505 default:
506 sb.append(ch);
507 sb.append(ch1);
508 }
509 i++;
510 } else {
511 sb.append(ch);
512 }
513 }
515 return sb.toString();
516 }
517 }
519 abstract class GenericDebugConfig extends BuildConfig {
520 abstract String getOptFlag();
522 protected void init(Vector includes, Vector defines) {
523 defines.add("_DEBUG");
524 defines.add("ASSERT");
526 super.init(includes, defines);
528 getV("CompilerFlags").addAll(getCI().getDebugCompilerFlags(getOptFlag()));
529 getV("LinkerFlags").addAll(getCI().getDebugLinkerFlags());
530 }
531 }
533 abstract class GenericDebugNonKernelConfig extends GenericDebugConfig {
534 protected void init(Vector includes, Vector defines) {
535 super.init(includes, defines);
536 getCI().getAdditionalNonKernelLinkerFlags(getV("LinkerFlags"));
537 }
538 }
540 class C1DebugConfig extends GenericDebugNonKernelConfig {
541 String getOptFlag() {
542 return getCI().getNoOptFlag();
543 }
545 C1DebugConfig() {
546 initNames("compiler1", "debug", "jvm.dll");
547 init(getIncludes(), getDefines());
548 }
549 }
551 class C1FastDebugConfig extends GenericDebugNonKernelConfig {
552 String getOptFlag() {
553 return getCI().getOptFlag();
554 }
556 C1FastDebugConfig() {
557 initNames("compiler1", "fastdebug", "jvm.dll");
558 init(getIncludes(), getDefines());
559 }
560 }
562 class C2DebugConfig extends GenericDebugNonKernelConfig {
563 String getOptFlag() {
564 return getCI().getNoOptFlag();
565 }
567 C2DebugConfig() {
568 initNames("compiler2", "debug", "jvm.dll");
569 init(getIncludes(), getDefines());
570 }
571 }
573 class C2FastDebugConfig extends GenericDebugNonKernelConfig {
574 String getOptFlag() {
575 return getCI().getOptFlag();
576 }
578 C2FastDebugConfig() {
579 initNames("compiler2", "fastdebug", "jvm.dll");
580 init(getIncludes(), getDefines());
581 }
582 }
584 class TieredDebugConfig extends GenericDebugNonKernelConfig {
585 String getOptFlag() {
586 return getCI().getNoOptFlag();
587 }
589 TieredDebugConfig() {
590 initNames("tiered", "debug", "jvm.dll");
591 init(getIncludes(), getDefines());
592 }
593 }
595 class TieredFastDebugConfig extends GenericDebugNonKernelConfig {
596 String getOptFlag() {
597 return getCI().getOptFlag();
598 }
600 TieredFastDebugConfig() {
601 initNames("tiered", "fastdebug", "jvm.dll");
602 init(getIncludes(), getDefines());
603 }
604 }
607 abstract class ProductConfig extends BuildConfig {
608 protected void init(Vector includes, Vector defines) {
609 defines.add("NDEBUG");
610 defines.add("PRODUCT");
612 super.init(includes, defines);
614 getV("CompilerFlags").addAll(getCI().getProductCompilerFlags());
615 getV("LinkerFlags").addAll(getCI().getProductLinkerFlags());
616 }
617 }
619 class C1ProductConfig extends ProductConfig {
620 C1ProductConfig() {
621 initNames("compiler1", "product", "jvm.dll");
622 init(getIncludes(), getDefines());
623 }
624 }
626 class C2ProductConfig extends ProductConfig {
627 C2ProductConfig() {
628 initNames("compiler2", "product", "jvm.dll");
629 init(getIncludes(), getDefines());
630 }
631 }
633 class TieredProductConfig extends ProductConfig {
634 TieredProductConfig() {
635 initNames("tiered", "product", "jvm.dll");
636 init(getIncludes(), getDefines());
637 }
638 }
641 class CoreDebugConfig extends GenericDebugNonKernelConfig {
642 String getOptFlag() {
643 return getCI().getNoOptFlag();
644 }
646 CoreDebugConfig() {
647 initNames("core", "debug", "jvm.dll");
648 init(getIncludes(), getDefines());
649 }
650 }
653 class CoreFastDebugConfig extends GenericDebugNonKernelConfig {
654 String getOptFlag() {
655 return getCI().getOptFlag();
656 }
658 CoreFastDebugConfig() {
659 initNames("core", "fastdebug", "jvm.dll");
660 init(getIncludes(), getDefines());
661 }
662 }
665 class CoreProductConfig extends ProductConfig {
666 CoreProductConfig() {
667 initNames("core", "product", "jvm.dll");
668 init(getIncludes(), getDefines());
669 }
670 }
672 class KernelDebugConfig extends GenericDebugConfig {
673 String getOptFlag() {
674 return getCI().getNoOptFlag();
675 }
677 KernelDebugConfig() {
678 initNames("kernel", "debug", "jvm.dll");
679 init(getIncludes(), getDefines());
680 }
681 }
684 class KernelFastDebugConfig extends GenericDebugConfig {
685 String getOptFlag() {
686 return getCI().getOptFlag();
687 }
689 KernelFastDebugConfig() {
690 initNames("kernel", "fastdebug", "jvm.dll");
691 init(getIncludes(), getDefines());
692 }
693 }
696 class KernelProductConfig extends ProductConfig {
697 KernelProductConfig() {
698 initNames("kernel", "product", "jvm.dll");
699 init(getIncludes(), getDefines());
700 }
701 }
702 abstract class CompilerInterface {
703 abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir);
704 abstract Vector getBaseLinkerFlags(String outDir, String outDll, String platformName);
705 abstract Vector getDebugCompilerFlags(String opt);
706 abstract Vector getDebugLinkerFlags();
707 abstract void getAdditionalNonKernelLinkerFlags(Vector rv);
708 abstract Vector getProductCompilerFlags();
709 abstract Vector getProductLinkerFlags();
710 abstract String getOptFlag();
711 abstract String getNoOptFlag();
712 abstract String makeCfgName(String flavourBuild, String platformName);
714 void addAttr(Vector receiver, String attr, String value) {
715 receiver.add(attr); receiver.add(value);
716 }
717 void extAttr(Vector receiver, String attr, String value) {
718 int attr_pos=receiver.indexOf(attr) ;
719 if ( attr_pos == -1) {
720 // If attr IS NOT present in the Vector - add it
721 receiver.add(attr); receiver.add(value);
722 } else {
723 // If attr IS present in the Vector - append value to it
724 receiver.set(attr_pos+1,receiver.get(attr_pos+1)+value);
725 }
726 }
727 }