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