1 /* 2 * Copyright (c) 2005, 2010, 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 */ 24 25 import java.io.*; 26 import java.util.*; 27 28 public class WinGammaPlatformVC7 extends WinGammaPlatform { 29 30 String projectVersion() {return "7.10";}; 31 32 public void writeProjectFile(String projectFileName, String projectName, 33 Vector allConfigs) throws IOException { 34 System.out.println(); 35 System.out.println(" Writing .vcproj file..."); 36 // If we got this far without an error, we're safe to actually 37 // write the .vcproj file 38 printWriter = new PrintWriter(new FileWriter(projectFileName)); 39 40 printWriter.println("<?xml version=\"1.0\" encoding=\"windows-1251\"?>"); 41 startTag( 42 "VisualStudioProject", 43 new String[] { 44 "ProjectType", "Visual C++", 45 "Version", projectVersion(), 46 "Name", projectName, 47 "ProjectGUID", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}", 48 "SccProjectName", "", 49 "SccLocalPath", "" 50 } 51 ); 52 53 startTag("Platforms", null); 54 tag("Platform", new String[] {"Name", Util.os}); 55 endTag("Platforms"); 56 57 startTag("Configurations", null); 58 59 for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { 60 writeConfiguration((BuildConfig)i.next()); 61 } 62 63 endTag("Configurations"); 64 65 tag("References", null); 66 67 writeFiles(allConfigs); 68 69 tag("Globals", null); 70 71 endTag("VisualStudioProject"); 72 printWriter.close(); 73 74 System.out.println(" Done."); 75 } 76 77 78 abstract class NameFilter { 79 protected String fname; 80 81 abstract boolean match(FileInfo fi); 82 83 String filterString() { return ""; } 84 String name() { return this.fname;} 85 } 86 87 class DirectoryFilter extends NameFilter { 88 String dir; 89 int baseLen, dirLen; 90 91 DirectoryFilter(String dir, String sbase) { 92 this.dir = dir; 93 this.baseLen = sbase.length(); 94 this.dirLen = dir.length(); 95 this.fname = dir; 96 } 97 98 DirectoryFilter(String fname, String dir, String sbase) { 99 this.dir = dir; 100 this.baseLen = sbase.length(); 101 this.dirLen = dir.length(); 102 this.fname = fname; 103 } 104 105 106 boolean match(FileInfo fi) { 107 return fi.full.regionMatches(true, baseLen, dir, 0, dirLen); 108 } 109 } 110 111 class TypeFilter extends NameFilter { 112 String[] exts; 113 114 TypeFilter(String fname, String[] exts) { 115 this.fname = fname; 116 this.exts = exts; 117 } 118 119 boolean match(FileInfo fi) { 120 for (int i=0; i<exts.length; i++) { 121 if (fi.full.endsWith(exts[i])) { 122 return true; 123 } 124 } 125 return false; 126 } 127 128 String filterString() { 129 return Util.join(";", exts); 130 } 131 } 132 133 class TerminatorFilter extends NameFilter { 134 TerminatorFilter(String fname) { 135 this.fname = fname; 136 137 } 138 boolean match(FileInfo fi) { 139 return true; 140 } 141 142 } 143 144 class SpecificNameFilter extends NameFilter { 145 String pats[]; 146 147 SpecificNameFilter(String fname, String[] pats) { 148 this.fname = fname; 149 this.pats = pats; 150 } 151 152 boolean match(FileInfo fi) { 153 for (int i=0; i<pats.length; i++) { 154 if (fi.attr.shortName.matches(pats[i])) { 155 return true; 156 } 157 } 158 return false; 159 } 160 161 } 162 163 class ContainerFilter extends NameFilter { 164 Vector children; 165 166 ContainerFilter(String fname) { 167 this.fname = fname; 168 children = new Vector(); 169 170 } 171 boolean match(FileInfo fi) { 172 return false; 173 } 174 175 Iterator babies() { return children.iterator(); } 176 177 void add(NameFilter f) { 178 children.add(f); 179 } 180 } 181 182 183 void writeCustomToolConfig(Vector configs, String[] customToolAttrs) { 184 for (Iterator i = configs.iterator(); i.hasNext(); ) { 185 startTag("FileConfiguration", 186 new String[] { 187 "Name", (String)i.next() 188 } 189 ); 190 tag("Tool", customToolAttrs); 191 192 endTag("FileConfiguration"); 193 } 194 } 195 196 // here we define filters, which define layout of what can be seen in 'Solution View' of MSVC 197 // Basically there are two types of entities - container filters and real filters 198 // - container filter just provides a container to group together real filters 199 // - real filter can select elements from the set according to some rule, put it into XML 200 // and remove from the list 201 Vector makeFilters(TreeSet files) { 202 Vector rv = new Vector(); 203 String sbase = Util.normalize(BuildConfig.getFieldString(null, "SourceBase")+"/src/"); 204 205 ContainerFilter rt = new ContainerFilter("Runtime"); 206 rt.add(new DirectoryFilter("share/vm/prims", sbase)); 207 rt.add(new DirectoryFilter("share/vm/runtime", sbase)); 208 rt.add(new DirectoryFilter("share/vm/oops", sbase)); 209 rv.add(rt); 210 211 ContainerFilter gc = new ContainerFilter("GC"); 212 gc.add(new DirectoryFilter("share/vm/memory", sbase)); 213 gc.add(new DirectoryFilter("share/vm/gc_interface", sbase)); 214 215 ContainerFilter gc_impl = new ContainerFilter("Implementations"); 216 gc_impl.add(new DirectoryFilter("CMS", 217 "share/vm/gc_implementation/concurrentMarkSweep", 218 sbase)); 219 gc_impl.add(new DirectoryFilter("Parallel Scavenge", 220 "share/vm/gc_implementation/parallelScavenge", 221 sbase)); 222 gc_impl.add(new DirectoryFilter("Shared", 223 "share/vm/gc_implementation/shared", 224 sbase)); 225 // for all leftovers 226 gc_impl.add(new DirectoryFilter("Misc", 227 "share/vm/gc_implementation", 228 sbase)); 229 230 gc.add(gc_impl); 231 rv.add(gc); 232 233 rv.add(new DirectoryFilter("C1", "share/vm/c1", sbase)); 234 235 ContainerFilter c2 = new ContainerFilter("C2"); 236 //c2.add(new DirectoryFilter("share/vm/adlc", sbase)); 237 c2.add(new DirectoryFilter("share/vm/opto", sbase)); 238 c2.add(new SpecificNameFilter("Generated", new String[] {"^ad_.+", "^dfa_.+", "^adGlobals.+"})); 239 rv.add(c2); 240 241 ContainerFilter comp = new ContainerFilter("Compiler Common"); 242 comp.add(new DirectoryFilter("share/vm/asm", sbase)); 243 comp.add(new DirectoryFilter("share/vm/ci", sbase)); 244 comp.add(new DirectoryFilter("share/vm/code", sbase)); 245 comp.add(new DirectoryFilter("share/vm/compiler", sbase)); 246 rv.add(comp); 247 248 rv.add(new DirectoryFilter("Interpreter", 249 "share/vm/interpreter", 250 sbase)); 251 252 ContainerFilter misc = new ContainerFilter("Misc"); 253 //misc.add(new DirectoryFilter("share/vm/launch", sbase)); 254 misc.add(new DirectoryFilter("share/vm/libadt", sbase)); 255 misc.add(new DirectoryFilter("share/vm/services", sbase)); 256 misc.add(new DirectoryFilter("share/vm/utilities", sbase)); 257 rv.add(misc); 258 259 rv.add(new DirectoryFilter("os_cpu", sbase)); 260 261 rv.add(new DirectoryFilter("cpu", sbase)); 262 263 rv.add(new DirectoryFilter("os", sbase)); 264 265 rv.add(new SpecificNameFilter("JVMTI Generated", new String[] {"^jvmti.+"})); 266 267 rv.add(new SpecificNameFilter("C++ Interpreter Generated", new String[] {"^bytecodeInterpreterWithChecks.+"})); 268 269 // this one is to catch files not caught by other filters 270 //rv.add(new TypeFilter("Header Files", new String[] {"h", "hpp", "hxx", "hm", "inl", "fi", "fd"})); 271 rv.add(new TerminatorFilter("Source Files")); 272 273 return rv; 274 } 275 276 void writeFiles(Vector allConfigs) { 277 278 Hashtable allFiles = computeAttributedFiles(allConfigs); 279 280 Vector allConfigNames = new Vector(); 281 for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { 282 allConfigNames.add(((BuildConfig)i.next()).get("Name")); 283 } 284 285 TreeSet sortedFiles = sortFiles(allFiles); 286 287 startTag("Files", null); 288 289 for (Iterator i = makeFilters(sortedFiles).iterator(); i.hasNext(); ) { 290 doWriteFiles(sortedFiles, allConfigNames, (NameFilter)i.next()); 291 } 292 293 294 startTag("Filter", 295 new String[] { 296 "Name", "Resource Files", 297 "Filter", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" 298 } 299 ); 300 endTag("Filter"); 301 302 endTag("Files"); 303 } 304 305 void doWriteFiles(TreeSet allFiles, Vector allConfigNames, NameFilter filter) { 306 startTag("Filter", 307 new String[] { 308 "Name", filter.name(), 309 "Filter", filter.filterString() 310 } 311 ); 312 313 if (filter instanceof ContainerFilter) { 314 315 Iterator i = ((ContainerFilter)filter).babies(); 316 while (i.hasNext()) { 317 doWriteFiles(allFiles, allConfigNames, (NameFilter)i.next()); 318 } 319 320 } else { 321 322 Iterator i = allFiles.iterator(); 323 while (i.hasNext()) { 324 FileInfo fi = (FileInfo)i.next(); 325 326 if (!filter.match(fi)) { 327 continue; 328 } 329 330 startTag("File", 331 new String[] { 332 "RelativePath", fi.full.replace('/', '\\') 333 } 334 ); 335 336 FileAttribute a = fi.attr; 337 if (a.pchRoot) { 338 writeCustomToolConfig(allConfigNames, 339 new String[] { 340 "Name", "VCCLCompilerTool", 341 "UsePrecompiledHeader", "1" 342 }); 343 } 344 345 if (a.noPch) { 346 writeCustomToolConfig(allConfigNames, 347 new String[] { 348 "Name", "VCCLCompilerTool", 349 "UsePrecompiledHeader", "0" 350 }); 351 } 352 353 if (a.configs != null) { 354 for (Iterator j=allConfigNames.iterator(); j.hasNext();) { 355 String cfg = (String)j.next(); 356 if (!a.configs.contains(cfg)) { 357 startTag("FileConfiguration", 358 new String[] { 359 "Name", cfg, 360 "ExcludedFromBuild", "TRUE" 361 }); 362 tag("Tool", new String[] {"Name", "VCCLCompilerTool"}); 363 endTag("FileConfiguration"); 364 365 } 366 } 367 } 368 369 endTag("File"); 370 371 // we not gonna look at this file anymore 372 i.remove(); 373 } 374 } 375 376 endTag("Filter"); 377 } 378 379 380 void writeConfiguration(BuildConfig cfg) { 381 startTag("Configuration", 382 new String[] { 383 "Name", cfg.get("Name"), 384 "OutputDirectory", cfg.get("OutputDir"), 385 "IntermediateDirectory", cfg.get("OutputDir"), 386 "ConfigurationType", "2", 387 "UseOfMFC", "0", 388 "ATLMinimizesCRunTimeLibraryUsage", "FALSE" 389 } 390 ); 391 392 393 394 tagV("Tool", cfg.getV("CompilerFlags")); 395 396 tag("Tool", 397 new String[] { 398 "Name", "VCCustomBuildTool" 399 } 400 ); 401 402 tagV("Tool", cfg.getV("LinkerFlags")); 403 404 tag("Tool", 405 new String[] { 406 "Name", "VCPostBuildEventTool" 407 } 408 ); 409 410 tag("Tool", 411 new String[] { 412 "Name", "VCPreBuildEventTool" 413 } 414 ); 415 416 tag("Tool", 417 new String[] { 418 "Name", "VCPreLinkEventTool", 419 "Description", BuildConfig.getFieldString(null, "PrelinkDescription"), 420 //Caution: String.replace(String,String) is available from JDK5 onwards only 421 "CommandLine", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace 422 ("\t", "
")) 423 } 424 ); 425 426 tag("Tool", 427 new String[] { 428 "Name", "VCResourceCompilerTool", 429 // XXX??? 430 "PreprocessorDefinitions", "NDEBUG", 431 "Culture", "1033" 432 } 433 ); 434 tag("Tool", 435 new String[] { 436 "Name", "VCWebServiceProxyGeneratorTool" 437 } 438 ); 439 440 tag ("Tool", 441 new String[] { 442 "Name", "VCXMLDataGeneratorTool" 443 } 444 ); 445 446 tag("Tool", 447 new String[] { 448 "Name", "VCWebDeploymentTool" 449 } 450 ); 451 tag("Tool", 452 new String[] { 453 "Name", "VCManagedWrapperGeneratorTool" 454 } 455 ); 456 tag("Tool", 457 new String[] { 458 "Name", "VCAuxiliaryManagedWrapperGeneratorTool" 459 } 460 ); 461 462 tag("Tool", 463 new String[] { 464 "Name", "VCMIDLTool", 465 "PreprocessorDefinitions", "NDEBUG", 466 "MkTypLibCompatible", "TRUE", 467 "SuppressStartupBanner", "TRUE", 468 "TargetEnvironment", "1", 469 "TypeLibraryName", cfg.get("OutputDir") + Util.sep + "vm.tlb", 470 "HeaderFileName", "" 471 } 472 ); 473 474 endTag("Configuration"); 475 } 476 477 int indent; 478 479 private void startTagPrim(String name, 480 String[] attrs, 481 boolean close) { 482 doIndent(); 483 printWriter.print("<"+name); 484 indent++; 485 486 if (attrs != null) { 487 printWriter.println(); 488 for (int i=0; i<attrs.length; i+=2) { 489 doIndent(); 490 printWriter.print(" " + attrs[i]+"=\""+attrs[i+1]+"\""); 491 if (i < attrs.length - 2) { 492 printWriter.println(); 493 } 494 } 495 } 496 497 if (close) { 498 indent--; 499 //doIndent(); 500 printWriter.println("/>"); 501 } else { 502 //doIndent(); 503 printWriter.println(">"); 504 } 505 } 506 507 void startTag(String name, String[] attrs) { 508 startTagPrim(name, attrs, false); 509 } 510 511 void startTagV(String name, Vector attrs) { 512 String s[] = new String [attrs.size()]; 513 for (int i=0; i<attrs.size(); i++) { 514 s[i] = (String)attrs.elementAt(i); 515 } 516 startTagPrim(name, s, false); 517 } 518 519 void endTag(String name) { 520 indent--; 521 doIndent(); 522 printWriter.println("</"+name+">"); 523 } 524 525 void tag(String name, String[] attrs) { 526 startTagPrim(name, attrs, true); 527 } 528 529 void tagV(String name, Vector attrs) { 530 String s[] = new String [attrs.size()]; 531 for (int i=0; i<attrs.size(); i++) { 532 s[i] = (String)attrs.elementAt(i); 533 } 534 startTagPrim(name, s, true); 535 } 536 537 538 void doIndent() { 539 for (int i=0; i<indent; i++) { 540 printWriter.print(" "); 541 } 542 } 543 544 protected String getProjectExt() { 545 return ".vcproj"; 546 } 547 } 548 549 class CompilerInterfaceVC7 extends CompilerInterface { 550 void getBaseCompilerFlags_common(Vector defines, Vector includes, String outDir,Vector rv) { 551 552 // advanced M$ IDE (2003) can only recognize name if it's first or 553 // second attribute in the tag - go guess 554 addAttr(rv, "Name", "VCCLCompilerTool"); 555 addAttr(rv, "AdditionalIncludeDirectories", Util.join(",", includes)); 556 addAttr(rv, "PreprocessorDefinitions", 557 Util.join(";", defines).replace("\"",""")); 558 addAttr(rv, "PrecompiledHeaderThrough", "precompiled.hpp"); 559 addAttr(rv, "PrecompiledHeaderFile", outDir+Util.sep+"vm.pch"); 560 addAttr(rv, "AssemblerListingLocation", outDir); 561 addAttr(rv, "ObjectFile", outDir+Util.sep); 562 addAttr(rv, "ProgramDataBaseFileName", outDir+Util.sep+"vm.pdb"); 563 // Set /nologo optin 564 addAttr(rv, "SuppressStartupBanner", "TRUE"); 565 // Surpass the default /Tc or /Tp. 0 is compileAsDefault 566 addAttr(rv, "CompileAs", "0"); 567 // Set /W3 option. 3 is warningLevel_3 568 addAttr(rv, "WarningLevel", "3"); 569 // Set /WX option, 570 addAttr(rv, "WarnAsError", "TRUE"); 571 // Set /GS option 572 addAttr(rv, "BufferSecurityCheck", "FALSE"); 573 // Set /Zi option. 3 is debugEnabled 574 addAttr(rv, "DebugInformationFormat", "3"); 575 } 576 Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir) { 577 Vector rv = new Vector(); 578 579 getBaseCompilerFlags_common(defines,includes, outDir, rv); 580 // Set /Yu option. 3 is pchUseUsingSpecific 581 // Note: Starting VC8 pchUseUsingSpecific is 2 !!! 582 addAttr(rv, "UsePrecompiledHeader", "3"); 583 // Set /EHsc- option 584 addAttr(rv, "ExceptionHandling", "FALSE"); 585 586 return rv; 587 } 588 589 Vector getBaseLinkerFlags(String outDir, String outDll) { 590 Vector rv = new Vector(); 591 592 addAttr(rv, "Name", "VCLinkerTool"); 593 addAttr(rv, "AdditionalOptions", 594 "/export:JNI_GetDefaultJavaVMInitArgs " + 595 "/export:JNI_CreateJavaVM " + 596 "/export:JNI_GetCreatedJavaVMs "+ 597 "/export:jio_snprintf /export:jio_printf "+ 598 "/export:jio_fprintf /export:jio_vfprintf "+ 599 "/export:jio_vsnprintf "); 600 addAttr(rv, "AdditionalDependencies", "Wsock32.lib winmm.lib"); 601 addAttr(rv, "OutputFile", outDll); 602 // Set /INCREMENTAL option. 1 is linkIncrementalNo 603 addAttr(rv, "LinkIncremental", "1"); 604 addAttr(rv, "SuppressStartupBanner", "TRUE"); 605 addAttr(rv, "ModuleDefinitionFile", outDir+Util.sep+"vm.def"); 606 addAttr(rv, "ProgramDatabaseFile", outDir+Util.sep+"vm.pdb"); 607 // Set /SUBSYSTEM option. 2 is subSystemWindows 608 addAttr(rv, "SubSystem", "2"); 609 addAttr(rv, "BaseAddress", "0x8000000"); 610 addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib"); 611 // Set /MACHINE option. 1 is machineX86 612 addAttr(rv, "TargetMachine", "1"); 613 614 return rv; 615 } 616 617 void getDebugCompilerFlags_common(String opt,Vector rv) { 618 619 // Set /On option 620 addAttr(rv, "Optimization", opt); 621 // Set /FR option. 1 is brAllInfo 622 addAttr(rv, "BrowseInformation", "1"); 623 addAttr(rv, "BrowseInformationFile", "$(IntDir)" + Util.sep); 624 // Set /MD option. 2 is rtMultiThreadedDLL 625 addAttr(rv, "RuntimeLibrary", "2"); 626 // Set /Oy- option 627 addAttr(rv, "OmitFramePointers", "FALSE"); 628 629 } 630 631 Vector getDebugCompilerFlags(String opt) { 632 Vector rv = new Vector(); 633 634 getDebugCompilerFlags_common(opt,rv); 635 636 return rv; 637 } 638 639 Vector getDebugLinkerFlags() { 640 Vector rv = new Vector(); 641 642 addAttr(rv, "GenerateDebugInformation", "TRUE"); // == /DEBUG option 643 644 return rv; 645 } 646 647 void getProductCompilerFlags_common(Vector rv) { 648 // Set /O2 option. 2 is optimizeMaxSpeed 649 addAttr(rv, "Optimization", "2"); 650 // Set /Oy- option 651 addAttr(rv, "OmitFramePointers", "FALSE"); 652 } 653 654 Vector getProductCompilerFlags() { 655 Vector rv = new Vector(); 656 657 getProductCompilerFlags_common(rv); 658 // Set /Ob option. 1 is expandOnlyInline 659 addAttr(rv, "InlineFunctionExpansion", "1"); 660 // Set /GF option. 661 addAttr(rv, "StringPooling", "TRUE"); 662 // Set /MD option. 2 is rtMultiThreadedDLL 663 addAttr(rv, "RuntimeLibrary", "2"); 664 // Set /Gy option 665 addAttr(rv, "EnableFunctionLevelLinking", "TRUE"); 666 667 return rv; 668 } 669 670 Vector getProductLinkerFlags() { 671 Vector rv = new Vector(); 672 673 // Set /OPT:REF option. 2 is optReferences 674 addAttr(rv, "OptimizeReferences", "2"); 675 // Set /OPT:optFolding option. 2 is optFolding 676 addAttr(rv, "EnableCOMDATFolding", "2"); 677 678 return rv; 679 } 680 681 String getOptFlag() { 682 return "2"; 683 } 684 685 String getNoOptFlag() { 686 return "0"; 687 } 688 689 String makeCfgName(String flavourBuild) { 690 return flavourBuild + "|" + Util.os; 691 } 692 }