1 /* 2 * Copyright (c) 2005, 2009, 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 rv.add(new SpecificNameFilter("Include DBs", new String[] {"^includeDB_.+"})); 270 271 // this one is to catch files not caught by other filters 272 //rv.add(new TypeFilter("Header Files", new String[] {"h", "hpp", "hxx", "hm", "inl", "fi", "fd"})); 273 rv.add(new TerminatorFilter("Source Files")); 274 275 return rv; 276 } 277 278 void writeFiles(Vector allConfigs) { 279 280 Hashtable allFiles = computeAttributedFiles(allConfigs); 281 282 Vector allConfigNames = new Vector(); 283 for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { 284 allConfigNames.add(((BuildConfig)i.next()).get("Name")); 285 } 286 287 TreeSet sortedFiles = sortFiles(allFiles); 288 289 startTag("Files", null); 290 291 for (Iterator i = makeFilters(sortedFiles).iterator(); i.hasNext(); ) { 292 doWriteFiles(sortedFiles, allConfigNames, (NameFilter)i.next()); 293 } 294 295 296 startTag("Filter", 297 new String[] { 298 "Name", "Resource Files", 299 "Filter", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" 300 } 301 ); 302 endTag("Filter"); 303 304 endTag("Files"); 305 } 306 307 void doWriteFiles(TreeSet allFiles, Vector allConfigNames, NameFilter filter) { 308 startTag("Filter", 309 new String[] { 310 "Name", filter.name(), 311 "Filter", filter.filterString() 312 } 313 ); 314 315 if (filter instanceof ContainerFilter) { 316 317 Iterator i = ((ContainerFilter)filter).babies(); 318 while (i.hasNext()) { 319 doWriteFiles(allFiles, allConfigNames, (NameFilter)i.next()); 320 } 321 322 } else { 323 324 Iterator i = allFiles.iterator(); 325 while (i.hasNext()) { 326 FileInfo fi = (FileInfo)i.next(); 327 328 if (!filter.match(fi)) { 329 continue; 330 } 331 332 startTag("File", 333 new String[] { 334 "RelativePath", fi.full.replace('/', '\\') 335 } 336 ); 337 338 FileAttribute a = fi.attr; 339 if (a.pchRoot) { 340 writeCustomToolConfig(allConfigNames, 341 new String[] { 342 "Name", "VCCLCompilerTool", 343 "UsePrecompiledHeader", "1" 344 }); 345 } 346 347 if (a.noPch) { 348 writeCustomToolConfig(allConfigNames, 349 new String[] { 350 "Name", "VCCLCompilerTool", 351 "UsePrecompiledHeader", "0" 352 }); 353 } 354 355 if (a.configs != null) { 356 for (Iterator j=allConfigNames.iterator(); j.hasNext();) { 357 String cfg = (String)j.next(); 358 if (!a.configs.contains(cfg)) { 359 startTag("FileConfiguration", 360 new String[] { 361 "Name", cfg, 362 "ExcludedFromBuild", "TRUE" 363 }); 364 tag("Tool", new String[] {"Name", "VCCLCompilerTool"}); 365 endTag("FileConfiguration"); 366 367 } 368 } 369 } 370 371 endTag("File"); 372 373 // we not gonna look at this file anymore 374 i.remove(); 375 } 376 } 377 378 endTag("Filter"); 379 } 380 381 382 void writeConfiguration(BuildConfig cfg) { 383 startTag("Configuration", 384 new String[] { 385 "Name", cfg.get("Name"), 386 "OutputDirectory", cfg.get("OutputDir"), 387 "IntermediateDirectory", cfg.get("OutputDir"), 388 "ConfigurationType", "2", 389 "UseOfMFC", "0", 390 "ATLMinimizesCRunTimeLibraryUsage", "FALSE" 391 } 392 ); 393 394 395 396 tagV("Tool", cfg.getV("CompilerFlags")); 397 398 tag("Tool", 399 new String[] { 400 "Name", "VCCustomBuildTool" 401 } 402 ); 403 404 tagV("Tool", cfg.getV("LinkerFlags")); 405 406 tag("Tool", 407 new String[] { 408 "Name", "VCPostBuildEventTool" 409 } 410 ); 411 412 tag("Tool", 413 new String[] { 414 "Name", "VCPreBuildEventTool" 415 } 416 ); 417 418 tag("Tool", 419 new String[] { 420 "Name", "VCPreLinkEventTool", 421 "Description", BuildConfig.getFieldString(null, "PrelinkDescription"), 422 //Caution: String.replace(String,String) is available from JDK5 onwards only 423 "CommandLine", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace 424 ("\t", "
")) 425 } 426 ); 427 428 tag("Tool", 429 new String[] { 430 "Name", "VCResourceCompilerTool", 431 // XXX??? 432 "PreprocessorDefinitions", "NDEBUG", 433 "Culture", "1033" 434 } 435 ); 436 tag("Tool", 437 new String[] { 438 "Name", "VCWebServiceProxyGeneratorTool" 439 } 440 ); 441 442 tag ("Tool", 443 new String[] { 444 "Name", "VCXMLDataGeneratorTool" 445 } 446 ); 447 448 tag("Tool", 449 new String[] { 450 "Name", "VCWebDeploymentTool" 451 } 452 ); 453 tag("Tool", 454 new String[] { 455 "Name", "VCManagedWrapperGeneratorTool" 456 } 457 ); 458 tag("Tool", 459 new String[] { 460 "Name", "VCAuxiliaryManagedWrapperGeneratorTool" 461 } 462 ); 463 464 tag("Tool", 465 new String[] { 466 "Name", "VCMIDLTool", 467 "PreprocessorDefinitions", "NDEBUG", 468 "MkTypLibCompatible", "TRUE", 469 "SuppressStartupBanner", "TRUE", 470 "TargetEnvironment", "1", 471 "TypeLibraryName", cfg.get("OutputDir") + Util.sep + "vm.tlb", 472 "HeaderFileName", "" 473 } 474 ); 475 476 endTag("Configuration"); 477 } 478 479 int indent; 480 481 private void startTagPrim(String name, 482 String[] attrs, 483 boolean close) { 484 doIndent(); 485 printWriter.print("<"+name); 486 indent++; 487 488 if (attrs != null) { 489 printWriter.println(); 490 for (int i=0; i<attrs.length; i+=2) { 491 doIndent(); 492 printWriter.println(" " + attrs[i]+"=\""+attrs[i+1]+"\""); 493 } 494 } 495 496 if (close) { 497 indent--; 498 //doIndent(); 499 printWriter.println("/>"); 500 } else { 501 //doIndent(); 502 printWriter.println(">"); 503 } 504 } 505 506 void startTag(String name, String[] attrs) { 507 startTagPrim(name, attrs, false); 508 } 509 510 void startTagV(String name, Vector attrs) { 511 String s[] = new String [attrs.size()]; 512 for (int i=0; i<attrs.size(); i++) { 513 s[i] = (String)attrs.elementAt(i); 514 } 515 startTagPrim(name, s, false); 516 } 517 518 void endTag(String name) { 519 indent--; 520 doIndent(); 521 printWriter.println("</"+name+">"); 522 } 523 524 void tag(String name, String[] attrs) { 525 startTagPrim(name, attrs, true); 526 } 527 528 void tagV(String name, Vector attrs) { 529 String s[] = new String [attrs.size()]; 530 for (int i=0; i<attrs.size(); i++) { 531 s[i] = (String)attrs.elementAt(i); 532 } 533 startTagPrim(name, s, true); 534 } 535 536 537 void doIndent() { 538 for (int i=0; i<indent; i++) { 539 printWriter.print(" "); 540 } 541 } 542 543 protected String getProjectExt() { 544 return ".vcproj"; 545 } 546 } 547 548 class CompilerInterfaceVC7 extends CompilerInterface { 549 void getBaseCompilerFlags_common(Vector defines, Vector includes, String outDir,Vector rv) { 550 551 // advanced M$ IDE (2003) can only recognize name if it's first or 552 // second attribute in the tag - go guess 553 addAttr(rv, "Name", "VCCLCompilerTool"); 554 addAttr(rv, "AdditionalIncludeDirectories", Util.join(",", includes)); 555 addAttr(rv, "PreprocessorDefinitions", 556 Util.join(";", defines).replace("\"",""")); 557 addAttr(rv, "PrecompiledHeaderThrough", 558 "incls"+Util.sep+"_precompiled.incl"); 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 }