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 */ 24 25 import java.io.FileWriter; 26 import java.io.IOException; 27 import java.io.PrintWriter; 28 import java.nio.file.FileSystems; 29 import java.util.Vector; 30 31 public class WinGammaPlatformVC7 extends WinGammaPlatform { 32 33 String projectVersion() {return "7.10";}; 34 35 public void writeProjectFile(String projectFileName, String projectName, 36 Vector<BuildConfig> allConfigs) throws IOException { 37 System.out.println(); 38 System.out.println(" Writing .vcproj file: "+projectFileName); 39 // If we got this far without an error, we're safe to actually 40 // write the .vcproj file 41 printWriter = new PrintWriter(new FileWriter(projectFileName)); 42 43 printWriter 44 .println("<?xml version=\"1.0\" encoding=\"windows-1251\"?>"); 45 startTag("VisualStudioProject", new String[] { "ProjectType", 46 "Visual C++", "Version", projectVersion(), "Name", projectName, 47 "ProjectGUID", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}", 48 "SccProjectName", "", "SccLocalPath", "" }); 49 startTag("Platforms"); 50 tag("Platform", 51 new String[] { "Name", 52 (String) BuildConfig.getField(null, "PlatformName") }); 53 endTag(); 54 55 startTag("Configurations"); 56 57 for (BuildConfig cfg : allConfigs) { 58 writeConfiguration(cfg); 59 } 60 61 endTag(); 62 63 tag("References"); 64 65 writeFiles(allConfigs); 66 67 tag("Globals"); 68 69 endTag(); 70 printWriter.close(); 71 72 System.out.println(" Done."); 73 } 74 75 void writeCustomToolConfig(Vector<BuildConfig> configs, String[] customToolAttrs) { 76 for (BuildConfig cfg : configs) { 77 startTag("FileConfiguration", 78 new String[] { "Name", (String) cfg.get("Name") }); 79 tag("Tool", customToolAttrs); 80 81 endTag(); 82 } 83 } 84 85 void writeFiles(Vector<BuildConfig> allConfigs) { 86 87 // This code assummes there are no config specific includes. 88 startTag("Files"); 89 String sourceBase = BuildConfig.getFieldString(null, "SourceBase"); 90 91 // Use first config for all global absolute includes. 92 BuildConfig baseConfig = allConfigs.firstElement(); 93 Vector<String> rv = new Vector<String>(); 94 95 // Then use first config for all relative includes 96 Vector<String> ri = new Vector<String>(); 97 baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude"); 98 for (String f : ri) { 99 rv.add(sourceBase + Util.sep + f); 100 } 101 102 baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude"); 103 104 handleIncludes(rv, allConfigs); 105 106 startTag("Filter", new String[] { "Name", "Resource Files", "Filter", 107 "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" }); 108 endTag(); 109 110 endTag(); 111 } 112 113 // Will visit file tree for each include 114 private void handleIncludes(Vector<String> includes, Vector<BuildConfig> allConfigs) { 115 for (String path : includes) { 116 FileTreeCreatorVC7 ftc = new FileTreeCreatorVC7(FileSystems.getDefault().getPath(path) , allConfigs, this); 117 try { 118 ftc.writeFileTree(); 119 } catch (IOException e) { 120 e.printStackTrace(); 121 } 122 } 123 } 124 125 void writeConfiguration(BuildConfig cfg) { 126 startTag("Configuration", new String[] { "Name", cfg.get("Name"), 127 "OutputDirectory", cfg.get("OutputDir"), 128 "IntermediateDirectory", cfg.get("OutputDir"), 129 "ConfigurationType", "2", "UseOfMFC", "0", 130 "ATLMinimizesCRunTimeLibraryUsage", "FALSE" }); 131 132 tagV("Tool", cfg.getV("CompilerFlags")); 133 134 tag("Tool", new String[] { "Name", "VCCustomBuildTool" }); 135 136 tagV("Tool", cfg.getV("LinkerFlags")); 137 138 tag("Tool", 139 new String[] { 140 "Name", 141 "VCPostBuildEventTool", 142 "Description", 143 BuildConfig 144 .getFieldString(null, "PostbuildDescription"), 145 // Caution: String.replace(String,String) is available 146 // from JDK5 onwards only 147 "CommandLine", 148 cfg.expandFormat(BuildConfig.getFieldString(null, 149 "PostbuildCommand").replace("\t", 150 "
")) }); 151 152 tag("Tool", new String[] { "Name", "VCPreBuildEventTool" }); 153 154 tag("Tool", 155 new String[] { 156 "Name", 157 "VCPreLinkEventTool", 158 "Description", 159 BuildConfig.getFieldString(null, "PrelinkDescription"), 160 // Caution: String.replace(String,String) is available 161 // from JDK5 onwards only 162 "CommandLine", 163 cfg.expandFormat(BuildConfig.getFieldString(null, 164 "PrelinkCommand").replace("\t", "
")) }); 165 166 tag("Tool", new String[] { "Name", "VCResourceCompilerTool", 167 "PreprocessorDefinitions", "NDEBUG", "Culture", "1033" }); 168 169 tag("Tool", new String[] { "Name", "VCMIDLTool", 170 "PreprocessorDefinitions", "NDEBUG", "MkTypLibCompatible", 171 "TRUE", "SuppressStartupBanner", "TRUE", "TargetEnvironment", 172 "1", "TypeLibraryName", 173 cfg.get("OutputDir") + Util.sep + "vm.tlb", "HeaderFileName", 174 "" }); 175 176 endTag(); 177 } 178 179 180 181 protected String getProjectExt() { 182 return ".vcproj"; 183 } 184 } 185 186 class CompilerInterfaceVC7 extends CompilerInterface { 187 void getBaseCompilerFlags_common(Vector defines, Vector includes, String outDir,Vector rv) { 188 189 // advanced M$ IDE (2003) can only recognize name if it's first or 190 // second attribute in the tag - go guess 191 addAttr(rv, "Name", "VCCLCompilerTool"); 192 addAttr(rv, "AdditionalIncludeDirectories", Util.join(",", includes)); 193 addAttr(rv, "PreprocessorDefinitions", 194 Util.join(";", defines).replace("\"",""")); 195 addAttr(rv, "PrecompiledHeaderThrough", "precompiled.hpp"); 196 addAttr(rv, "PrecompiledHeaderFile", outDir+Util.sep+"vm.pch"); 197 addAttr(rv, "AssemblerListingLocation", outDir); 198 addAttr(rv, "ObjectFile", outDir+Util.sep); 199 addAttr(rv, "ProgramDataBaseFileName", outDir+Util.sep+"jvm.pdb"); 200 // Set /nologo optin 201 addAttr(rv, "SuppressStartupBanner", "TRUE"); 202 // Surpass the default /Tc or /Tp. 0 is compileAsDefault 203 addAttr(rv, "CompileAs", "0"); 204 // Set /W3 option. 3 is warningLevel_3 205 addAttr(rv, "WarningLevel", "3"); 206 // Set /WX option, 207 addAttr(rv, "WarnAsError", "TRUE"); 208 // Set /GS option 209 addAttr(rv, "BufferSecurityCheck", "FALSE"); 210 // Set /Zi option. 3 is debugEnabled 211 addAttr(rv, "DebugInformationFormat", "3"); 212 } 213 Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir) { 214 Vector rv = new Vector(); 215 216 getBaseCompilerFlags_common(defines,includes, outDir, rv); 217 // Set /Yu option. 3 is pchUseUsingSpecific 218 // Note: Starting VC8 pchUseUsingSpecific is 2 !!! 219 addAttr(rv, "UsePrecompiledHeader", "3"); 220 // Set /EHsc- option 221 addAttr(rv, "ExceptionHandling", "FALSE"); 222 223 return rv; 224 } 225 226 Vector getBaseLinkerFlags(String outDir, String outDll, String platformName) { 227 Vector rv = new Vector(); 228 229 addAttr(rv, "Name", "VCLinkerTool"); 230 addAttr(rv, "AdditionalOptions", 231 "/export:JNI_GetDefaultJavaVMInitArgs " + 232 "/export:JNI_CreateJavaVM " + 233 "/export:JVM_FindClassFromBootLoader "+ 234 "/export:JNI_GetCreatedJavaVMs "+ 235 "/export:jio_snprintf /export:jio_printf "+ 236 "/export:jio_fprintf /export:jio_vfprintf "+ 237 "/export:jio_vsnprintf "+ 238 "/export:JVM_GetVersionInfo "+ 239 "/export:JVM_GetThreadStateNames "+ 240 "/export:JVM_GetThreadStateValues "+ 241 "/export:JVM_InitAgentProperties "); 242 addAttr(rv, "AdditionalDependencies", "Wsock32.lib winmm.lib"); 243 addAttr(rv, "OutputFile", outDll); 244 // Set /INCREMENTAL option. 1 is linkIncrementalNo 245 addAttr(rv, "LinkIncremental", "1"); 246 addAttr(rv, "SuppressStartupBanner", "TRUE"); 247 addAttr(rv, "ModuleDefinitionFile", outDir+Util.sep+"vm.def"); 248 addAttr(rv, "ProgramDatabaseFile", outDir+Util.sep+"jvm.pdb"); 249 // Set /SUBSYSTEM option. 2 is subSystemWindows 250 addAttr(rv, "SubSystem", "2"); 251 addAttr(rv, "BaseAddress", "0x8000000"); 252 addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib"); 253 if(platformName.equals("Win32")) { 254 // Set /MACHINE option. 1 is X86 255 addAttr(rv, "TargetMachine", "1"); 256 } else { 257 // Set /MACHINE option. 17 is X64 258 addAttr(rv, "TargetMachine", "17"); 259 } 260 261 return rv; 262 } 263 264 void getDebugCompilerFlags_common(String opt,Vector rv) { 265 266 // Set /On option 267 addAttr(rv, "Optimization", opt); 268 // Set /FR option. 1 is brAllInfo 269 addAttr(rv, "BrowseInformation", "1"); 270 addAttr(rv, "BrowseInformationFile", "$(IntDir)" + Util.sep); 271 // Set /MD option. 2 is rtMultiThreadedDLL 272 addAttr(rv, "RuntimeLibrary", "2"); 273 // Set /Oy- option 274 addAttr(rv, "OmitFramePointers", "FALSE"); 275 276 } 277 278 Vector getDebugCompilerFlags(String opt) { 279 Vector rv = new Vector(); 280 281 getDebugCompilerFlags_common(opt,rv); 282 283 return rv; 284 } 285 286 Vector getDebugLinkerFlags() { 287 Vector rv = new Vector(); 288 289 addAttr(rv, "GenerateDebugInformation", "TRUE"); // == /DEBUG option 290 291 return rv; 292 } 293 294 void getAdditionalNonKernelLinkerFlags(Vector rv) { 295 extAttr(rv, "AdditionalOptions", 296 "/export:AsyncGetCallTrace "); 297 } 298 299 void getProductCompilerFlags_common(Vector rv) { 300 // Set /O2 option. 2 is optimizeMaxSpeed 301 addAttr(rv, "Optimization", "2"); 302 // Set /Oy- option 303 addAttr(rv, "OmitFramePointers", "FALSE"); 304 // Set /Ob option. 1 is expandOnlyInline 305 addAttr(rv, "InlineFunctionExpansion", "1"); 306 // Set /GF option. 307 addAttr(rv, "StringPooling", "TRUE"); 308 // Set /MD option. 2 is rtMultiThreadedDLL 309 addAttr(rv, "RuntimeLibrary", "2"); 310 // Set /Gy option 311 addAttr(rv, "EnableFunctionLevelLinking", "TRUE"); 312 } 313 314 Vector getProductCompilerFlags() { 315 Vector rv = new Vector(); 316 317 getProductCompilerFlags_common(rv); 318 319 return rv; 320 } 321 322 Vector getProductLinkerFlags() { 323 Vector rv = new Vector(); 324 325 // Set /OPT:REF option. 2 is optReferences 326 addAttr(rv, "OptimizeReferences", "2"); 327 // Set /OPT:optFolding option. 2 is optFolding 328 addAttr(rv, "EnableCOMDATFolding", "2"); 329 330 return rv; 331 } 332 333 String getOptFlag() { 334 return "2"; 335 } 336 337 String getNoOptFlag() { 338 return "0"; 339 } 340 341 String makeCfgName(String flavourBuild, String platform) { 342 return flavourBuild + "|" + platform; 343 } 344 }