src/share/tools/ProjectCreator/WinGammaPlatformVC7.java

Thu, 08 Aug 2013 09:21:30 -0700

author
dcubed
date
Thu, 08 Aug 2013 09:21:30 -0700
changeset 5500
31f3b1e1c5e5
parent 4153
b9a9ed0f8eeb
child 5507
bd0e82136b03
permissions
-rw-r--r--

8016601: Unable to build hsx24 on Windows using project creator and Visual Studio
Summary: ProjectCreator tool is modified to support two new options: '-relativeAltSrcInclude' and '-altRelativeInclude' which prevents IDE linker errors. Also fixed some cmd line build linker warnings. Misc cleanups.
Reviewed-by: rdurbin, coleenp

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

mercurial